From 2aef4a44ef3e4dd7f4fe8bfd4659f86e8165a4b6 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 10 Oct 2012 14:04:29 +0200 Subject: cesar/lib/test/test: test that only the expected tests fail --- cesar/lib/test/test/src/test_test.c | 56 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'cesar/lib/test') 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; } -- cgit v1.2.3