From ee0a2e7e1965200ec5968ec310bee429db819dde Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 3 Sep 2023 22:20:31 +0200 Subject: Remove const --- source/tests/_static.c | 2 +- source/tests/array_ref.test.c | 6 +-- source/tests/cpp.cpp | 13 ------ source/tests/duration.test.c | 19 ++++++++ source/tests/input_stream.test.c | 4 +- source/tests/lower_bound.test.c | 78 ++++++++++++++++----------------- source/tests/main.test.c | 3 +- source/tests/move_back.test.c | 8 ++-- source/tests/signals.cpp | 29 ------------ source/tests/test_cpp.cpp | 13 ++++++ source/tests/test_duration.test.c | 19 -------- source/tests/test_signals.cpp | 29 ++++++++++++ source/tests/test_too_many_assertions.c | 13 ++++++ source/tests/test_too_many_tests.c | 14 ++++++ source/tests/too_many_assertions.c | 13 ------ source/tests/too_many_tests.c | 14 ------ 16 files changed, 139 insertions(+), 138 deletions(-) delete mode 100644 source/tests/cpp.cpp create mode 100644 source/tests/duration.test.c delete mode 100644 source/tests/signals.cpp create mode 100644 source/tests/test_cpp.cpp delete mode 100644 source/tests/test_duration.test.c create mode 100644 source/tests/test_signals.cpp create mode 100644 source/tests/test_too_many_assertions.c create mode 100644 source/tests/test_too_many_tests.c delete mode 100644 source/tests/too_many_assertions.c delete mode 100644 source/tests/too_many_tests.c (limited to 'source/tests') diff --git a/source/tests/_static.c b/source/tests/_static.c index 4b7543d..54587d3 100644 --- a/source/tests/_static.c +++ b/source/tests/_static.c @@ -43,7 +43,7 @@ #include "string_ref.test.c" #undef KIT_TEST_FILE -#include "test_duration.test.c" +#include "duration.test.c" #undef KIT_TEST_FILE #include "thread.test.c" diff --git a/source/tests/array_ref.test.c b/source/tests/array_ref.test.c index da20aa0..cb19850 100644 --- a/source/tests/array_ref.test.c +++ b/source/tests/array_ref.test.c @@ -3,7 +3,7 @@ #define KIT_TEST_FILE array_ref #include "../kit_test/test.h" -TEST("array ref const wrap") { +TEST("array ref wrap") { int foo[] = { 1, 2, 3 }; AR_WRAP(ref, int, foo); @@ -15,7 +15,7 @@ TEST("array ref const wrap") { TEST("array ref wrap") { int foo[] = { 1, 2, 3 }; - AR_MUT_WRAP(ref, int, foo); + AR_WRAP(ref, int, foo); REQUIRE(ref.size == 3); REQUIRE(ref.values[0] == 1); @@ -36,7 +36,7 @@ TEST("array ref equal") { REQUIRE(AR_EQUAL(foo_ref, bar_ref)); } -static int compare(int const *left, int const *right) { +static int compare(int *left, int *right) { return *left - *right; } diff --git a/source/tests/cpp.cpp b/source/tests/cpp.cpp deleted file mode 100644 index 8b762e4..0000000 --- a/source/tests/cpp.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "../kit_test/test.h" - -TEST("foo") { - REQUIRE(20 + 22 == 42); -} - -TEST("bar") { - REQUIRE(true); -} - -int main(int argc, char **argv) { - return run_tests(argc, argv); -} diff --git a/source/tests/duration.test.c b/source/tests/duration.test.c new file mode 100644 index 0000000..56919e4 --- /dev/null +++ b/source/tests/duration.test.c @@ -0,0 +1,19 @@ +#define KIT_TEST_FILE duration +#include "../kit_test/test.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) +__declspec(dllimport) void __stdcall Sleep(unsigned long timeout); +static void kit_sleep(int ms) { + Sleep(ms); +} +#else +# include +# include +static void kit_sleep(int ms) { + usleep(ms * 1000); +} +#endif + +TEST("test duration") { + kit_sleep(100); +} diff --git a/source/tests/input_stream.test.c b/source/tests/input_stream.test.c index 61c2254..46ee0dd 100644 --- a/source/tests/input_stream.test.c +++ b/source/tests/input_stream.test.c @@ -12,8 +12,8 @@ TEST("input stream wrap string") { is_handle_t in = IS_WRAP_STRING(foo_ref); - char buf[4]; - out_str_t buf_ref = { .size = sizeof(buf), .values = buf }; + char buf[4]; + str_t buf_ref = { .size = sizeof(buf), .values = buf }; REQUIRE(IS_READ(in, buf_ref) == buf_ref.size); REQUIRE(AR_EQUAL(foo_ref, bar_ref)); diff --git a/source/tests/lower_bound.test.c b/source/tests/lower_bound.test.c index 3b62325..56ec816 100644 --- a/source/tests/lower_bound.test.c +++ b/source/tests/lower_bound.test.c @@ -8,7 +8,7 @@ static int kit_less_int(int left, int right) { return left < right; } -static int kit_less_int_ref(int const *left, int const *right) { +static int kit_less_int_ref(int *left, int *right) { return *left < *right; } @@ -21,8 +21,8 @@ TEST("lower bound empty") { } TEST("lower bound single left") { - int const v[1] = { 42 }; - AR(int) ref = { .size = 1, .values = v }; + int v[1] = { 42 }; + AR(int) ref = { .size = 1, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 42, kit_less_int); @@ -30,8 +30,8 @@ TEST("lower bound single left") { } TEST("lower bound single right") { - int const v[1] = { 42 }; - AR(int) ref = { .size = 1, .values = v }; + int v[1] = { 42 }; + AR(int) ref = { .size = 1, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 43, kit_less_int); @@ -39,8 +39,8 @@ TEST("lower bound single right") { } TEST("lower bound first of four") { - int const v[4] = { 1, 2, 3, 4 }; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 1, kit_less_int); @@ -48,8 +48,8 @@ TEST("lower bound first of four") { } TEST("lower bound second of four") { - int const v[4] = { 1, 2, 3, 4 }; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 2, kit_less_int); @@ -57,8 +57,8 @@ TEST("lower bound second of four") { } TEST("lower bound third of four") { - int const v[4] = { 1, 2, 3, 4 }; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 3, kit_less_int); @@ -66,8 +66,8 @@ TEST("lower bound third of four") { } TEST("lower bound forth of four") { - int const v[4] = { 1, 2, 3, 4 }; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 4, kit_less_int); @@ -75,8 +75,8 @@ TEST("lower bound forth of four") { } TEST("lower bound fifth of four") { - int const v[4] = { 1, 2, 3, 4 }; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 5, kit_less_int); @@ -84,8 +84,8 @@ TEST("lower bound fifth of four") { } TEST("lower bound first of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 1, kit_less_int); @@ -93,8 +93,8 @@ TEST("lower bound first of five") { } TEST("lower bound second of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 2, kit_less_int); @@ -102,8 +102,8 @@ TEST("lower bound second of five") { } TEST("lower bound third of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 3, kit_less_int); @@ -111,8 +111,8 @@ TEST("lower bound third of five") { } TEST("lower bound forth of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 4, kit_less_int); @@ -120,8 +120,8 @@ TEST("lower bound forth of five") { } TEST("lower bound fifth of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 5, kit_less_int); @@ -129,8 +129,8 @@ TEST("lower bound fifth of five") { } TEST("lower bound sixth of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND(index, ref, 6, kit_less_int); @@ -138,9 +138,9 @@ TEST("lower bound sixth of five") { } TEST("lower bound ref first of four") { - int const v[4] = { 1, 2, 3, 4 }; - int const value = 1; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + int value = 1; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref); @@ -148,9 +148,9 @@ TEST("lower bound ref first of four") { } TEST("lower bound ref second of four") { - int const v[4] = { 1, 2, 3, 4 }; - int const value = 2; - AR(int) ref = { .size = 4, .values = v }; + int v[4] = { 1, 2, 3, 4 }; + int value = 2; + AR(int) ref = { .size = 4, .values = v }; ptrdiff_t index; LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref); @@ -158,9 +158,9 @@ TEST("lower bound ref second of four") { } TEST("lower bound ref fifth of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - int const value = 5; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + int value = 5; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref); @@ -168,9 +168,9 @@ TEST("lower bound ref fifth of five") { } TEST("lower bound ref sixth of five") { - int const v[5] = { 1, 2, 3, 4, 5 }; - int const value = 6; - AR(int) ref = { .size = 5, .values = v }; + int v[5] = { 1, 2, 3, 4, 5 }; + int value = 6; + AR(int) ref = { .size = 5, .values = v }; ptrdiff_t index; LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref); diff --git a/source/tests/main.test.c b/source/tests/main.test.c index 2a41d4b..790c8c2 100644 --- a/source/tests/main.test.c +++ b/source/tests/main.test.c @@ -1,9 +1,10 @@ +#include "../kit/status.h" #include "../kit_test/bench.h" #include "../kit_test/test.h" int main(int argc, char **argv) { int status = run_tests(argc, argv); - if (status == 0) + if (status == KIT_OK) status = run_benchmarks(argc, argv); return status; } diff --git a/source/tests/move_back.test.c b/source/tests/move_back.test.c index f08d190..f3f6dc4 100644 --- a/source/tests/move_back.test.c +++ b/source/tests/move_back.test.c @@ -3,19 +3,19 @@ #define KIT_TEST_FILE move_back #include "../kit_test/test.h" -static int is_equal(int const x, int const y) { +static int is_equal(int x, int y) { return x == y; } -static int is_equal_ref(int const *const x, int const y) { +static int is_equal_ref(int *x, int y) { return *x == y; } -static int is_even(int const x, int const _) { +static int is_even(int x, int _) { return (x % 2) == 0; } -static int is_even_ref(int const *const x, int const _) { +static int is_even_ref(int *x, int _) { return (*x % 2) == 0; } diff --git a/source/tests/signals.cpp b/source/tests/signals.cpp deleted file mode 100644 index 0f6d77a..0000000 --- a/source/tests/signals.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "../kit_test/test.h" - -#include -#include - -/* FIXME - * MSVC tests fail in GitHub Actions. - */ - -TEST("c++ exception") { - throw std::exception(); -} - -TEST("abort") { - abort(); -} - -TEST("invalid access") { - *(volatile int *) nullptr = 42; -} - -int main(int argc, char **argv) { -#ifndef _MSC_VER - if (run_tests(argc, argv) != 1) - return 1; -#endif - - return 0; -} diff --git a/source/tests/test_cpp.cpp b/source/tests/test_cpp.cpp new file mode 100644 index 0000000..8b762e4 --- /dev/null +++ b/source/tests/test_cpp.cpp @@ -0,0 +1,13 @@ +#include "../kit_test/test.h" + +TEST("foo") { + REQUIRE(20 + 22 == 42); +} + +TEST("bar") { + REQUIRE(true); +} + +int main(int argc, char **argv) { + return run_tests(argc, argv); +} diff --git a/source/tests/test_duration.test.c b/source/tests/test_duration.test.c deleted file mode 100644 index 27384b4..0000000 --- a/source/tests/test_duration.test.c +++ /dev/null @@ -1,19 +0,0 @@ -#define KIT_TEST_FILE test_duration -#include "../kit_test/test.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -__declspec(dllimport) void __stdcall Sleep(unsigned long timeout); -static void kit_sleep(int ms) { - Sleep(ms); -} -#else -# include -# include -static void kit_sleep(int ms) { - usleep(ms * 1000); -} -#endif - -TEST("test duration") { - kit_sleep(100); -} diff --git a/source/tests/test_signals.cpp b/source/tests/test_signals.cpp new file mode 100644 index 0000000..0f6d77a --- /dev/null +++ b/source/tests/test_signals.cpp @@ -0,0 +1,29 @@ +#include "../kit_test/test.h" + +#include +#include + +/* FIXME + * MSVC tests fail in GitHub Actions. + */ + +TEST("c++ exception") { + throw std::exception(); +} + +TEST("abort") { + abort(); +} + +TEST("invalid access") { + *(volatile int *) nullptr = 42; +} + +int main(int argc, char **argv) { +#ifndef _MSC_VER + if (run_tests(argc, argv) != 1) + return 1; +#endif + + return 0; +} diff --git a/source/tests/test_too_many_assertions.c b/source/tests/test_too_many_assertions.c new file mode 100644 index 0000000..662207d --- /dev/null +++ b/source/tests/test_too_many_assertions.c @@ -0,0 +1,13 @@ +#include "../kit_test/test.h" + +TEST("foo") { + int i; + for (i = 0; i <= KIT_TEST_ASSERTIONS_LIMIT; i++) REQUIRE(1); +} + +int main(int argc, char **argv) { + if (run_tests(argc, argv) != 1) + return 1; + + return 0; +} diff --git a/source/tests/test_too_many_tests.c b/source/tests/test_too_many_tests.c new file mode 100644 index 0000000..d4842e4 --- /dev/null +++ b/source/tests/test_too_many_tests.c @@ -0,0 +1,14 @@ +#include "../kit_test/test.h" + +void bar(int index, kit_test_report_fn report) { } + +int main(int argc, char **argv) { + int i; + for (i = 0; i <= KIT_TESTS_SIZE_LIMIT; i++) + test_register("foo", __FILE__, bar); + + if (run_tests(argc, argv) != 1) + return 1; + + return 0; +} diff --git a/source/tests/too_many_assertions.c b/source/tests/too_many_assertions.c deleted file mode 100644 index 662207d..0000000 --- a/source/tests/too_many_assertions.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "../kit_test/test.h" - -TEST("foo") { - int i; - for (i = 0; i <= KIT_TEST_ASSERTIONS_LIMIT; i++) REQUIRE(1); -} - -int main(int argc, char **argv) { - if (run_tests(argc, argv) != 1) - return 1; - - return 0; -} diff --git a/source/tests/too_many_tests.c b/source/tests/too_many_tests.c deleted file mode 100644 index d4842e4..0000000 --- a/source/tests/too_many_tests.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "../kit_test/test.h" - -void bar(int index, kit_test_report_fn report) { } - -int main(int argc, char **argv) { - int i; - for (i = 0; i <= KIT_TESTS_SIZE_LIMIT; i++) - test_register("foo", __FILE__, bar); - - if (run_tests(argc, argv) != 1) - return 1; - - return 0; -} -- cgit v1.2.3