diff --git a/samples/tests/CMakeLists.txt b/samples/tests/CMakeLists.txt index 463d4da..388c5ae 100644 --- a/samples/tests/CMakeLists.txt +++ b/samples/tests/CMakeLists.txt @@ -3,11 +3,13 @@ set(SAMPLES exit.c long-messages.c other-crashes.c + theories_regression.c failmessages.cc exit.cc long-messages.cc other-crashes.cc + theories_regression.cc ) add_samples("${CMAKE_CURRENT_LIST_DIR}" "${SAMPLES}") diff --git a/samples/tests/outputs/theories_regression.c.bin.err.expected b/samples/tests/outputs/theories_regression.c.bin.err.expected new file mode 100644 index 0000000..c09ce14 --- /dev/null +++ b/samples/tests/outputs/theories_regression.c.bin.err.expected @@ -0,0 +1,15 @@ +[----] theories_regression.c:52: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (1) +[----] theories_regression.c:52: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (2) +[----] theories_regression.c:52: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (3) +[----] theories_regression.c:52: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (4) +[----] theories_regression.c:52: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (5) +[FAIL] theory::gen: (0.00s) +[----] theories_regression.c:35: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::misc failed with the following parameters: ('a', true, 1, 1, 1l, 1l, 3.14f, 3.14, "test", "other test") +[FAIL] theory::misc: (0.00s) +[====] Synthesis: Tested: 2 | Passing: 0 | Failing: 2 | Crashing: 0  diff --git a/samples/tests/outputs/theories_regression.c.bin.out.expected b/samples/tests/outputs/theories_regression.c.bin.out.expected new file mode 100644 index 0000000..e69de29 diff --git a/samples/tests/outputs/theories_regression.cc.bin.err.expected b/samples/tests/outputs/theories_regression.cc.bin.err.expected new file mode 100644 index 0000000..4c10ddd --- /dev/null +++ b/samples/tests/outputs/theories_regression.cc.bin.err.expected @@ -0,0 +1,15 @@ +[----] theories_regression.cc:54: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (1) +[----] theories_regression.cc:54: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (2) +[----] theories_regression.cc:54: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (3) +[----] theories_regression.cc:54: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (4) +[----] theories_regression.cc:54: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::gen failed with the following parameters: (5) +[FAIL] theory::gen: (0.00s) +[----] theories_regression.cc:37: Assertion failed: The conditions for this assertion were not met. +[----] Theory theory::misc failed with the following parameters: ('a', true, 1, 1, 1l, 1l, 3.14f, 3.14, "test", "other test") +[FAIL] theory::misc: (0.00s) +[====] Synthesis: Tested: 2 | Passing: 0 | Failing: 2 | Crashing: 0  diff --git a/samples/tests/outputs/theories_regression.cc.bin.out.expected b/samples/tests/outputs/theories_regression.cc.bin.out.expected new file mode 100644 index 0000000..e69de29 diff --git a/samples/tests/theories_regression.c b/samples/tests/theories_regression.c new file mode 100644 index 0000000..b8d4ca5 --- /dev/null +++ b/samples/tests/theories_regression.c @@ -0,0 +1,53 @@ +#ifdef _MSC_VER +#pragma warning(disable : 4090) +#endif + +#include + +// Testing for various parameters + +TheoryDataPoints(theory, misc) = { + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(long, 1), + DataPoints(long long, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, "test"), + DataPoints(const char *, "other test"), +}; + +Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, char *str, const char *cstr), theory, misc) { + cr_assert(b); + cr_assert_eq(c, 'a'); + cr_assert_eq(s, 1); + cr_assert_eq(i, 1); + cr_assert_eq(l, 1); + cr_assert_eq(ll, 1); + cr_assert_eq(f, 3.14f); + cr_assert_eq(d, 3.14); + cr_assert_str_eq(str, "test"); + cr_assert_str_eq(cstr, "other test"); + + // abort to see the formatted string of all parameters + cr_assert_fail(); +} + +// Manually generate datapoints + +TheoryDataPoints(theory, gen) = { + DataPoints(int, 0), // placeholder +}; + +static void generate_datapoints(void) { + static int arr[] = {1, 2, 3, 4, 5}; + TheoryDataPoint(theory, gen)[0].len = 5; + TheoryDataPoint(theory, gen)[0].arr = &arr; +} + +Theory((int i), theory, gen, .init = generate_datapoints) { + (void) i; + cr_assert_fail(); // we fail to display the parameter +} diff --git a/samples/tests/theories_regression.cc b/samples/tests/theories_regression.cc new file mode 100644 index 0000000..5bebea1 --- /dev/null +++ b/samples/tests/theories_regression.cc @@ -0,0 +1,55 @@ +#ifdef _MSC_VER +#pragma warning(disable : 4090) +#endif + +#include + +// Testing for various parameters + +char test_str[] = {'t', 'e', 's', 't', '\0'}; + +TheoryDataPoints(theory, misc) = { + DataPoints(char, 'a'), + DataPoints(bool, true), + DataPoints(short, 1), + DataPoints(int, 1), + DataPoints(long, 1), + DataPoints(long long, 1), + DataPoints(float, 3.14f), + DataPoints(double, 3.14), + DataPoints(char *, test_str), + DataPoints(const char *, "other test"), +}; + +Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, char *str, const char *cstr), theory, misc) { + cr_assert(b); + cr_assert_eq(c, 'a'); + cr_assert_eq(s, 1); + cr_assert_eq(i, 1); + cr_assert_eq(l, 1); + cr_assert_eq(ll, 1); + cr_assert_eq(f, 3.14f); + cr_assert_eq(d, 3.14); + cr_assert_str_eq(str, "test"); + cr_assert_str_eq(cstr, "other test"); + + // abort to see the formatted string of all parameters + cr_assert_fail(); +} + +// Manually generate datapoints + +TheoryDataPoints(theory, gen) = { + DataPoints(int, 0), // placeholder +}; + +static void generate_datapoints(void) { + static int arr[] = {1, 2, 3, 4, 5}; + TheoryDataPoint(theory, gen)[0].len = 5; + TheoryDataPoint(theory, gen)[0].arr = &arr; +} + +Theory((int i), theory, gen, .init = generate_datapoints) { + (void) i; + cr_assert_fail(); // we fail to display the parameter +}