From 0a112c3f0964e4be0bab7148538656173768c3b7 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 8 Sep 2023 21:34:37 +0200 Subject: Refactor kit_test to header-only library --- source/tests/_static.c | 41 +++++++++++++++++---------------- source/tests/array_ref.test.c | 12 +--------- source/tests/async_function.test.c | 2 +- source/tests/atomic.test.c | 2 +- source/tests/bench.test.c | 3 +-- source/tests/bigint.test.c | 2 +- source/tests/condition_variable.test.c | 2 +- source/tests/duration.test.c | 2 +- source/tests/dynamic_array.test.c | 2 +- source/tests/file.test.c | 2 +- source/tests/input_buffer.test.c | 2 +- source/tests/input_stream.test.c | 2 +- source/tests/lower_bound.test.c | 2 +- source/tests/main.test.c | 7 +++--- source/tests/mersenne_twister_64.test.c | 2 +- source/tests/move_back.test.c | 2 +- source/tests/mutex.test.c | 2 +- source/tests/secure_random.test.c | 2 +- source/tests/sha256.test.c | 2 +- source/tests/string_ref.test.c | 2 +- source/tests/test_cpp.cpp | 3 ++- source/tests/test_signals.cpp | 3 ++- source/tests/test_too_many_assertions.c | 4 +++- source/tests/test_too_many_tests.c | 4 +++- source/tests/thread.test.c | 2 +- 25 files changed, 53 insertions(+), 58 deletions(-) (limited to 'source/tests') diff --git a/source/tests/_static.c b/source/tests/_static.c index 54587d3..9975a53 100644 --- a/source/tests/_static.c +++ b/source/tests/_static.c @@ -1,55 +1,56 @@ -#include "array_ref.test.c" -#undef KIT_TEST_FILE +#define KIT_TEST_IMPLEMENTATION +#include "main.test.c" -#include "async_function.test.c" #undef KIT_TEST_FILE +#include "array_ref.test.c" -#include "bigint.test.c" #undef KIT_TEST_FILE +#include "async_function.test.c" -#include "condition_variable.test.c" #undef KIT_TEST_FILE +#include "bigint.test.c" -#include "dynamic_array.test.c" #undef KIT_TEST_FILE +#include "condition_variable.test.c" -#include "file.test.c" #undef KIT_TEST_FILE +#include "dynamic_array.test.c" -#include "input_buffer.test.c" #undef KIT_TEST_FILE +#include "file.test.c" -#include "input_stream.test.c" #undef KIT_TEST_FILE +#include "input_buffer.test.c" -#include "lower_bound.test.c" #undef KIT_TEST_FILE +#include "input_stream.test.c" -#include "mersenne_twister_64.test.c" #undef KIT_TEST_FILE +#include "lower_bound.test.c" -#include "move_back.test.c" #undef KIT_TEST_FILE +#include "mersenne_twister_64.test.c" -#include "mutex.test.c" #undef KIT_TEST_FILE +#include "move_back.test.c" -#include "secure_random.test.c" #undef KIT_TEST_FILE +#include "mutex.test.c" -#include "sha256.test.c" #undef KIT_TEST_FILE +#include "secure_random.test.c" -#include "string_ref.test.c" #undef KIT_TEST_FILE +#include "sha256.test.c" -#include "duration.test.c" #undef KIT_TEST_FILE +#include "string_ref.test.c" -#include "thread.test.c" #undef KIT_TEST_FILE +#include "duration.test.c" -#include "bench.test.c" #undef KIT_TEST_FILE +#include "thread.test.c" -#include "main.test.c" +#undef KIT_TEST_FILE +#include "bench.test.c" diff --git a/source/tests/array_ref.test.c b/source/tests/array_ref.test.c index cb19850..06e098c 100644 --- a/source/tests/array_ref.test.c +++ b/source/tests/array_ref.test.c @@ -1,17 +1,7 @@ #include "../kit/array_ref.h" #define KIT_TEST_FILE array_ref -#include "../kit_test/test.h" - -TEST("array ref wrap") { - int foo[] = { 1, 2, 3 }; - AR_WRAP(ref, int, foo); - - REQUIRE(ref.size == 3); - REQUIRE(ref.values[0] == 1); - REQUIRE(ref.values[1] == 2); - REQUIRE(ref.values[2] == 3); -} +#include "../kit/kit_test.h" TEST("array ref wrap") { int foo[] = { 1, 2, 3 }; diff --git a/source/tests/async_function.test.c b/source/tests/async_function.test.c index 35ce0ce..2e62f64 100644 --- a/source/tests/async_function.test.c +++ b/source/tests/async_function.test.c @@ -1,7 +1,7 @@ #include "../kit/async_function.h" #define KIT_TEST_FILE async_function -#include "../kit_test/test.h" +#include "../kit/kit_test.h" AF_STATE(int, test_foo, ); static AF_DECL(test_foo); diff --git a/source/tests/atomic.test.c b/source/tests/atomic.test.c index c1831a3..8bf2c95 100644 --- a/source/tests/atomic.test.c +++ b/source/tests/atomic.test.c @@ -2,7 +2,7 @@ #include "../kit/thread.h" #define KIT_TEST_FILE atomic -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("atomic store and load") { ATOMIC(int) value; diff --git a/source/tests/bench.test.c b/source/tests/bench.test.c index 92e216d..a5536f4 100644 --- a/source/tests/bench.test.c +++ b/source/tests/bench.test.c @@ -1,12 +1,11 @@ #define KIT_TEST_FILE bench -#include "../kit_test/bench.h" +#include "../kit/kit_test.h" struct test_foo_ { double f; }; BENCHMARK("foo") { - /* Benchmark setup. */ diff --git a/source/tests/bigint.test.c b/source/tests/bigint.test.c index c8ac44f..ad0d076 100644 --- a/source/tests/bigint.test.c +++ b/source/tests/bigint.test.c @@ -2,7 +2,7 @@ #include "../kit/bigint.h" #define KIT_TEST_FILE bigint -#include "../kit_test/test.h" +#include "../kit/kit_test.h" #if __STDC_VERSION__ >= 199901L static_assert(sizeof(bigint_t) == 256, "KIT_BIGINT_SIZE check"); diff --git a/source/tests/condition_variable.test.c b/source/tests/condition_variable.test.c index dfbe4a6..59882bf 100644 --- a/source/tests/condition_variable.test.c +++ b/source/tests/condition_variable.test.c @@ -2,7 +2,7 @@ #include "../kit/thread.h" #define KIT_TEST_FILE condition_variable -#include "../kit_test/test.h" +#include "../kit/kit_test.h" typedef struct { mtx_t m; diff --git a/source/tests/duration.test.c b/source/tests/duration.test.c index 56919e4..9613583 100644 --- a/source/tests/duration.test.c +++ b/source/tests/duration.test.c @@ -1,5 +1,5 @@ #define KIT_TEST_FILE duration -#include "../kit_test/test.h" +#include "../kit/kit_test.h" #if defined(_WIN32) && !defined(__CYGWIN__) __declspec(dllimport) void __stdcall Sleep(unsigned long timeout); diff --git a/source/tests/dynamic_array.test.c b/source/tests/dynamic_array.test.c index 8701e6c..8aa7f42 100644 --- a/source/tests/dynamic_array.test.c +++ b/source/tests/dynamic_array.test.c @@ -1,7 +1,7 @@ #include "../kit/dynamic_array.h" #define KIT_TEST_FILE dynamic_array -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("dynamic array empty") { DA_CREATE(v, char, 0); diff --git a/source/tests/file.test.c b/source/tests/file.test.c index 859de86..94e8ed3 100644 --- a/source/tests/file.test.c +++ b/source/tests/file.test.c @@ -3,7 +3,7 @@ #include #define KIT_TEST_FILE file -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("file path cache") { string_t user = path_user(NULL); diff --git a/source/tests/input_buffer.test.c b/source/tests/input_buffer.test.c index 3cd84b6..bfbcaef 100644 --- a/source/tests/input_buffer.test.c +++ b/source/tests/input_buffer.test.c @@ -1,7 +1,7 @@ #include "../kit/input_buffer.h" #define KIT_TEST_FILE input_buffer -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("input buffer read once") { str_t text = { .size = 3, .values = "foo" }; diff --git a/source/tests/input_stream.test.c b/source/tests/input_stream.test.c index 467c227..4b609b9 100644 --- a/source/tests/input_stream.test.c +++ b/source/tests/input_stream.test.c @@ -2,7 +2,7 @@ #include "../kit/file.h" #define KIT_TEST_FILE input_stream -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("input stream wrap string") { char foo[] = "test"; diff --git a/source/tests/lower_bound.test.c b/source/tests/lower_bound.test.c index 56ec816..ea6e72d 100644 --- a/source/tests/lower_bound.test.c +++ b/source/tests/lower_bound.test.c @@ -2,7 +2,7 @@ #include "../kit/array_ref.h" #define KIT_TEST_FILE lower_bound -#include "../kit_test/test.h" +#include "../kit/kit_test.h" static int kit_less_int(int left, int right) { return left < right; diff --git a/source/tests/main.test.c b/source/tests/main.test.c index 790c8c2..d81a8cb 100644 --- a/source/tests/main.test.c +++ b/source/tests/main.test.c @@ -1,10 +1,9 @@ -#include "../kit/status.h" -#include "../kit_test/bench.h" -#include "../kit_test/test.h" +#define KIT_TEST_IMPLEMENTATION +#include "../kit/kit_test.h" int main(int argc, char **argv) { int status = run_tests(argc, argv); - if (status == KIT_OK) + if (status == 0) status = run_benchmarks(argc, argv); return status; } diff --git a/source/tests/mersenne_twister_64.test.c b/source/tests/mersenne_twister_64.test.c index f9b0278..a138a41 100644 --- a/source/tests/mersenne_twister_64.test.c +++ b/source/tests/mersenne_twister_64.test.c @@ -2,7 +2,7 @@ #include "../kit/secure_random.h" #define KIT_TEST_FILE mersenne_twister_64 -#include "../kit_test/test.h" +#include "../kit/kit_test.h" enum { MT64_TEST_SIZE = 1000 }; diff --git a/source/tests/move_back.test.c b/source/tests/move_back.test.c index f3f6dc4..18171b5 100644 --- a/source/tests/move_back.test.c +++ b/source/tests/move_back.test.c @@ -1,7 +1,7 @@ #include "../kit/move_back.h" #define KIT_TEST_FILE move_back -#include "../kit_test/test.h" +#include "../kit/kit_test.h" static int is_equal(int x, int y) { return x == y; diff --git a/source/tests/mutex.test.c b/source/tests/mutex.test.c index ce26991..c2e5d85 100644 --- a/source/tests/mutex.test.c +++ b/source/tests/mutex.test.c @@ -2,7 +2,7 @@ #include "../kit/thread.h" #define KIT_TEST_FILE mutex -#include "../kit_test/test.h" +#include "../kit/kit_test.h" enum { SLEEP = 400000000, TICK_COUNT = 200, THREAD_COUNT = 100 }; diff --git a/source/tests/secure_random.test.c b/source/tests/secure_random.test.c index 0f25b47..e54edee 100644 --- a/source/tests/secure_random.test.c +++ b/source/tests/secure_random.test.c @@ -2,7 +2,7 @@ #include #define KIT_TEST_FILE secure_random -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("secure random") { int v[20]; diff --git a/source/tests/sha256.test.c b/source/tests/sha256.test.c index 0f751df..215a73b 100644 --- a/source/tests/sha256.test.c +++ b/source/tests/sha256.test.c @@ -2,7 +2,7 @@ #include "../kit/array_ref.h" #define KIT_TEST_FILE sha256_64 -#include "../kit_test/test.h" +#include "../kit/kit_test.h" #include diff --git a/source/tests/string_ref.test.c b/source/tests/string_ref.test.c index 2891f16..a75abc5 100644 --- a/source/tests/string_ref.test.c +++ b/source/tests/string_ref.test.c @@ -1,7 +1,7 @@ #include "../kit/string_ref.h" #define KIT_TEST_FILE string_ref -#include "../kit_test/test.h" +#include "../kit/kit_test.h" TEST("static string wrap") { str_t ref = SZ("foo bar"); diff --git a/source/tests/test_cpp.cpp b/source/tests/test_cpp.cpp index 8b762e4..919ebb9 100644 --- a/source/tests/test_cpp.cpp +++ b/source/tests/test_cpp.cpp @@ -1,4 +1,5 @@ -#include "../kit_test/test.h" +#define KIT_TEST_IMPLEMENTATION +#include "../kit/kit_test.h" TEST("foo") { REQUIRE(20 + 22 == 42); diff --git a/source/tests/test_signals.cpp b/source/tests/test_signals.cpp index 1b4acc7..0ffd5eb 100644 --- a/source/tests/test_signals.cpp +++ b/source/tests/test_signals.cpp @@ -1,4 +1,5 @@ -#include "../kit_test/test.h" +#define KIT_TEST_IMPLEMENTATION +#include "../kit/kit_test.h" #include #include diff --git a/source/tests/test_too_many_assertions.c b/source/tests/test_too_many_assertions.c index 662207d..a1ce710 100644 --- a/source/tests/test_too_many_assertions.c +++ b/source/tests/test_too_many_assertions.c @@ -1,4 +1,6 @@ -#include "../kit_test/test.h" +#define KIT_TEST_IMPLEMENTATION +#define KIT_TEST_ASSERTIONS_LIMIT 10 +#include "../kit/kit_test.h" TEST("foo") { int i; diff --git a/source/tests/test_too_many_tests.c b/source/tests/test_too_many_tests.c index d4842e4..9691e2c 100644 --- a/source/tests/test_too_many_tests.c +++ b/source/tests/test_too_many_tests.c @@ -1,4 +1,6 @@ -#include "../kit_test/test.h" +#define KIT_TEST_IMPLEMENTATION +#define KIT_TESTS_SIZE_LIMIT 40 +#include "../kit/kit_test.h" void bar(int index, kit_test_report_fn report) { } diff --git a/source/tests/thread.test.c b/source/tests/thread.test.c index 50f7c04..b8069da 100644 --- a/source/tests/thread.test.c +++ b/source/tests/thread.test.c @@ -1,7 +1,7 @@ #include "../kit/thread.h" #define KIT_TEST_FILE thread -#include "../kit_test/test.h" +#include "../kit/kit_test.h" static int test_nothing(void *_) { return 0; -- cgit v1.2.3