summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2012-10-10 14:04:29 +0200
committerNicolas Schodet2012-10-17 15:20:33 +0200
commit2aef4a44ef3e4dd7f4fe8bfd4659f86e8165a4b6 (patch)
treea3b89a7383828641f0ca2e0e9b81af8e61136a2b
parent8faf6a4098e12a885f0a19b98a9aeb26f0addf05 (diff)
cesar/lib/test/test: test that only the expected tests fail
-rw-r--r--cesar/lib/test/test/src/test_test.c56
-rw-r--r--common/tests/tests2
2 files changed, 37 insertions, 21 deletions
diff --git a/cesar/lib/test/test/src/test_test.c b/cesar/lib/test/test/src/test_test.c
index 78409f8f5d..1f3ef9df94 100644
--- a/cesar/lib/test/test/src/test_test.c
+++ b/cesar/lib/test/test/src/test_test.c
@@ -14,11 +14,12 @@
#include "lib/test.h"
-void
-mytest_basic_test_case (test_t t)
+bool
+mytest_ok_test_case (test_t t)
{
- uint i;
- test_case_begin (t, "basic");
+ uint old_attempted = test_nb_attempted (t);
+ uint old_failed = test_nb_failed (t);
+ test_case_begin (t, "ok");
test_begin (t, "test no fail")
{
} test_end;
@@ -26,6 +27,29 @@ mytest_basic_test_case (test_t t)
{
test_fail_unless (1 == 1);
} test_end;
+ test_begin (t, "catch assert")
+ {
+ dbg_fatal_try_begin
+ {
+ dbg_assert (1 == 2);
+ }
+ dbg_fatal_try_catch (const char *the_error)
+ {
+ test_verbose_print ("catched: %s", the_error);
+ }
+ dbg_fatal_try_end;
+ } test_end;
+ return test_nb_attempted (t) == old_attempted + 3
+ && test_nb_failed (t) == old_failed + 0;
+}
+
+bool
+mytest_nok_test_case (test_t t)
+{
+ uint i;
+ uint old_attempted = test_nb_attempted (t);
+ uint old_failed = test_nb_failed (t);
+ test_case_begin (t, "nok");
test_begin (t, "test_fail_unless nok")
{
test_fail_unless (1 == 2);
@@ -43,18 +67,6 @@ mytest_basic_test_case (test_t t)
test_fail ("fail at i = %d", i);
}
} test_end;
- test_begin (t, "catch assert")
- {
- dbg_fatal_try_begin
- {
- dbg_assert (1 == 2);
- }
- dbg_fatal_try_catch (const char *the_error)
- {
- test_verbose_print ("catched: %s", the_error);
- }
- dbg_fatal_try_end;
- } test_end;
test_begin (t, "no catch assert")
{
dbg_assert (1 == 2);
@@ -70,13 +82,17 @@ mytest_basic_test_case (test_t t)
{
*(u32 *) NULL = 0;
} test_end;
+ return test_nb_attempted (t) == old_attempted + 6
+ && test_nb_failed (t) == old_failed + 6;
}
-void
+bool
mytest_test_suite (test_t t)
{
test_suite_begin (t, "mytest");
- mytest_basic_test_case (t);
+ bool success_ok = mytest_ok_test_case (t);
+ bool success_nok = mytest_nok_test_case (t);
+ return success_ok && success_nok;
}
int
@@ -84,7 +100,7 @@ main (int argc, char **argv)
{
test_t t;
test_init (t, argc, argv);
- mytest_test_suite (t);
+ bool success = mytest_test_suite (t);
test_result (t);
- return test_nb_failed (t) == 0 ? 0 : 1;
+ return success ? 0 : 1;
}
diff --git a/common/tests/tests b/common/tests/tests
index 327c9c5ecf..c79a38fa48 100644
--- a/common/tests/tests
+++ b/common/tests/tests
@@ -135,7 +135,7 @@ cov test_stats: ./obj/test_stats
cesar/lib/test/test:
make
-!run: ./obj/test_test
+run: ./obj/test_test
cesar/lib/test/trace:
make: make HOST_COV=y