tests: Better suite creation

While the previous method of in-lining a stack allocated array of
tests into the suite struct declaration was nice, we had to update
size manually.

This macro will allow us to just append new tests to the suite without
having to care for that.  It generates a uniquely named variable for
the test array, then uses that test array in the suite declaration.
Nice and easy.
This commit is contained in:
2026-02-05 06:44:35 +00:00
parent 61efa91403
commit 762dabd3e5
6 changed files with 22 additions and 55 deletions

View File

@@ -61,8 +61,13 @@ typedef struct
const u64 size;
} test_suite_t;
#define MAKE_TEST_SUITE(NAME) \
{.name = #NAME, .tests = NAME, .size = ARRSIZE(NAME)}
#define MAKE_TEST_SUITE(NAME, DESC, ...) \
const test_fn NAME##_TESTS[] = {__VA_ARGS__}; \
const test_suite_t NAME = { \
.name = DESC, \
.tests = NAME##_TESTS, \
.size = ARRSIZE(NAME##_TESTS), \
}
#endif

View File

@@ -186,19 +186,11 @@ void sys_test(void)
TEST_PASSED();
}
const test_suite_t LISP_API_SUITE = {
.name = "Lisp API Tests",
.tests =
(test_fn[]){
MAKE_TEST_FN(smi_test),
MAKE_TEST_FN(smi_oob_test),
MAKE_TEST_FN(sym_fresh_test),
MAKE_TEST_FN(sym_unique_test),
MAKE_TEST_FN(cons_test),
MAKE_TEST_FN(sys_test),
},
.size = 6,
};
MAKE_TEST_SUITE(LISP_API_SUITE, "LISP API Tests",
MAKE_TEST_FN(smi_test), MAKE_TEST_FN(smi_oob_test),
MAKE_TEST_FN(sym_fresh_test), MAKE_TEST_FN(sym_unique_test),
MAKE_TEST_FN(cons_test), MAKE_TEST_FN(sys_test), );
/* Copyright (C) 2026 Aryadev Chavali

View File

@@ -87,21 +87,9 @@ void stream_test_line_col(void)
TODO("Not implemented");
}
const test_suite_t STREAM_SUITE = {
.name = "Stream Tests",
.tests =
(test_fn[]){
MAKE_TEST_FN(stream_test_string),
// MAKE_TEST_FN(stream_test_file),
// MAKE_TEST_FN(stream_test_peek_next),
// MAKE_TEST_FN(stream_test_seek),
// MAKE_TEST_FN(stream_test_substr),
// MAKE_TEST_FN(stream_test_till),
// MAKE_TEST_FN(stream_test_while),
// MAKE_TEST_FN(stream_test_line_col),
},
.size = 1,
};
MAKE_TEST_SUITE(STREAM_SUITE, "Stream Tests",
MAKE_TEST_FN(stream_test_string), );
/* Copyright (C) 2026 Aryadev Chavali

View File

@@ -28,14 +28,7 @@ void sv_copy_test(void)
}
}
const test_suite_t SV_SUITE = {
.name = "String View Tests",
.tests =
(test_fn[]){
MAKE_TEST_FN(sv_copy_test),
},
.size = 1,
};
MAKE_TEST_SUITE(SV_SUITE, "String View Tests", MAKE_TEST_FN(sv_copy_test), );
/* Copyright (C) 2026 Aryadev Chavali

View File

@@ -22,14 +22,9 @@ void symtable_test(void)
TEST_PASSED();
}
const test_suite_t SYMTABLE_SUITE = {
.name = "Symbol Table Tests",
.tests =
(test_fn[]){
MAKE_TEST_FN(symtable_test),
},
.size = 1,
};
MAKE_TEST_SUITE(SYMTABLE_SUITE, "Symbol Table Tests",
MAKE_TEST_FN(symtable_test), );
/* Copyright (C) 2026 Aryadev Chavali

View File

@@ -69,15 +69,9 @@ void vec_test_substr(void)
TEST_PASSED();
}
const test_suite_t VEC_SUITE = {
.name = "Vector Tests",
.tests =
(test_fn[]){
MAKE_TEST_FN(vec_test_concat),
MAKE_TEST_FN(vec_test_substr),
},
.size = 2,
};
MAKE_TEST_SUITE(VEC_SUITE, "Vector Tests",
MAKE_TEST_FN(vec_test_concat), MAKE_TEST_FN(vec_test_substr), );
/* Copyright (C) 2026 Aryadev Chavali