Skip to content

Commit

Permalink
include/lone: split macros into init and literals
Browse files Browse the repository at this point in the history
I fix one thing and it breaks another. Can't have compound literals
in designated initializers, so delete it. Then it breaks other things
that were depending on the compound initializer's lvalue nature.

Let's just have both. An INIT macro that generates the designated
initializer and a normal macro that creates a compound literal.
Then macros can build upon each other with the INIT macros while
code uses the normal macros whenever possible.
  • Loading branch information
matheusmoreira committed Jul 4, 2024
1 parent 4a075d2 commit 28b87dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
43 changes: 29 additions & 14 deletions include/lone/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 7 additions & 4 deletions include/lone/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. │
Expand Down
34 changes: 17 additions & 17 deletions source/tests/lone/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down

0 comments on commit 28b87dd

Please sign in to comment.