diff --git a/include/lone/test.h b/include/lone/test.h index e8a6a4b2..ab9f8274 100644 --- a/include/lone/test.h +++ b/include/lone/test.h @@ -45,25 +45,40 @@ struct lone_test_case { void *context; }; -#define LONE_TEST_CASE_WITH_CONTEXT(name_c_string_literal, test_function, _context) \ - { \ - .name = LONE_BYTES_FROM_LITERAL((name_c_string_literal)), \ - .test = (test_function), \ - .context = (_context), \ - .result = LONE_TEST_RESULT_PENDING, \ +#define LONE_TEST_CASE_WITH_CONTEXT_INIT(name_c_string_literal, test_function, _context) \ + { \ + .name = LONE_BYTES_FROM_LITERAL_INIT((name_c_string_literal)), \ + .test = (test_function), \ + .context = (_context), \ + .result = LONE_TEST_RESULT_PENDING, \ } -#define LONE_TEST_CASE(name_c_string_literal, test_function) \ - LONE_TEST_CASE_WITH_CONTEXT((name_c_string_literal), (test_function), 0) +#define LONE_TEST_CASE_INIT(name_c_string_literal, test_function) \ + LONE_TEST_CASE_WITH_CONTEXT_INIT((name_c_string_literal), \ + (test_function), 0) -#define LONE_TEST_SUITE(cases) \ - { \ - .tests = (cases), \ - .events.context = 0, \ - .events.on.test.initiated = 0, \ - .events.on.test.terminated = 0, \ +#define LONE_TEST_CASE_WITH_CONTEXT(name_c_string_literal, test_function, _context) \ + ((struct lone_test_case) \ + LONE_TEST_CASE_WITH_CONTEXT_INIT((name_c_string_literal), \ + (test_function), (_context))) + + +#define LONE_TEST_CASE(name_c_string_literal, test_function) \ + ((struct lone_test_case) \ + LONE_TEST_CASE_INIT((name_c_string_literal), \ + (test_function))) + +#define LONE_TEST_SUITE_INITIALIZER(cases) \ + { \ + .tests = (cases), \ + .events.context = 0, \ + .events.on.test.initiated = 0, \ + .events.on.test.terminated = 0, \ } +#define LONE_TEST_SUITE(cases) \ + ((struct lone_test_suite) LONE_TEST_SUITE_INITIALIZER(cases)) + enum lone_test_result lone_test_suite_run(struct lone_test_suite *suite); #endif /* LONE_TEST_HEADER */ diff --git a/include/lone/types.h b/include/lone/types.h index 979feff0..a4a4baa0 100644 --- a/include/lone/types.h +++ b/include/lone/types.h @@ -63,12 +63,15 @@ struct lone_bytes { unsigned char *pointer; /* address of memory block */ }; -#define LONE_BYTES_FROM_LITERAL(c_string_literal) \ - { \ - .count = sizeof(c_string_literal) - 1, \ - .pointer = (unsigned char *) (c_string_literal), \ +#define LONE_BYTES_FROM_LITERAL_INIT(c_string_literal) \ + { \ + .count = sizeof((c_string_literal)) - 1, \ + .pointer = (unsigned char *) (c_string_literal), \ } +#define LONE_BYTES_FROM_LITERAL(c_string_literal) \ + ((struct lone_bytes) LONE_BYTES_FROM_LITERAL_INIT((c_string-literal))) + /* ╭────────────────────────────────────────────────────────────────────────╮ │ │ │ Lone primitive type operations. │ diff --git a/source/tests/lone/types.c b/source/tests/lone/types.c index 671f57c0..3bec5dbf 100644 --- a/source/tests/lone/types.c +++ b/source/tests/lone/types.c @@ -186,23 +186,23 @@ long lone(int argc, char **argv, char **envp, struct lone_auxiliary_vector *auxv { static struct lone_test_case cases[] = { - LONE_TEST_CASE("lone/types/u8/read", test_lone_types_lone_u8_read), - LONE_TEST_CASE("lone/types/s8/read", test_lone_types_lone_s8_read), - LONE_TEST_CASE("lone/types/u16/read", test_lone_types_lone_u16_read), - LONE_TEST_CASE("lone/types/s16/read", test_lone_types_lone_s16_read), - LONE_TEST_CASE("lone/types/u32/read", test_lone_types_lone_u32_read), - LONE_TEST_CASE("lone/types/s32/read", test_lone_types_lone_s32_read), - LONE_TEST_CASE("lone/types/u64/read", test_lone_types_lone_u64_read), - LONE_TEST_CASE("lone/types/s64/read", test_lone_types_lone_s64_read), - - LONE_TEST_CASE("lone/types/u8/write", test_lone_types_lone_u8_write), - LONE_TEST_CASE("lone/types/s8/write", test_lone_types_lone_s8_write), - LONE_TEST_CASE("lone/types/u16/write", test_lone_types_lone_u16_write), - LONE_TEST_CASE("lone/types/s16/write", test_lone_types_lone_s16_write), - LONE_TEST_CASE("lone/types/u32/write", test_lone_types_lone_u32_write), - LONE_TEST_CASE("lone/types/s32/write", test_lone_types_lone_s32_write), - LONE_TEST_CASE("lone/types/u64/write", test_lone_types_lone_u64_write), - LONE_TEST_CASE("lone/types/s64/write", test_lone_types_lone_s64_write), + LONE_TEST_CASE_INIT("lone/types/u8/read", test_lone_types_lone_u8_read), + LONE_TEST_CASE_INIT("lone/types/s8/read", test_lone_types_lone_s8_read), + LONE_TEST_CASE_INIT("lone/types/u16/read", test_lone_types_lone_u16_read), + LONE_TEST_CASE_INIT("lone/types/s16/read", test_lone_types_lone_s16_read), + LONE_TEST_CASE_INIT("lone/types/u32/read", test_lone_types_lone_u32_read), + LONE_TEST_CASE_INIT("lone/types/s32/read", test_lone_types_lone_s32_read), + LONE_TEST_CASE_INIT("lone/types/u64/read", test_lone_types_lone_u64_read), + LONE_TEST_CASE_INIT("lone/types/s64/read", test_lone_types_lone_s64_read), + + LONE_TEST_CASE_INIT("lone/types/u8/write", test_lone_types_lone_u8_write), + LONE_TEST_CASE_INIT("lone/types/s8/write", test_lone_types_lone_s8_write), + LONE_TEST_CASE_INIT("lone/types/u16/write", test_lone_types_lone_u16_write), + LONE_TEST_CASE_INIT("lone/types/s16/write", test_lone_types_lone_s16_write), + LONE_TEST_CASE_INIT("lone/types/u32/write", test_lone_types_lone_u32_write), + LONE_TEST_CASE_INIT("lone/types/s32/write", test_lone_types_lone_s32_write), + LONE_TEST_CASE_INIT("lone/types/u64/write", test_lone_types_lone_u64_write), + LONE_TEST_CASE_INIT("lone/types/s64/write", test_lone_types_lone_s64_write), {0}, };