From: amalec Date: Tue, 12 Jun 2001 17:28:10 +0000 (+0000) Subject: Added new tests for line number X-Git-Tag: 0.10.0~1115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81d70bf419d4d41b5b6aec5dee7001d35f613923;p=check Added new tests for line number git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@27 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/check/configure b/check/configure index 14bc32a..4441b67 100755 --- a/check/configure +++ b/check/configure @@ -691,7 +691,7 @@ fi PACKAGE=check -VERSION=0.5.2 +VERSION=0.6.0 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/check/configure.in b/check/configure.in index 55e771f..2c14b5d 100644 --- a/check/configure.in +++ b/check/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(src/check.c) -AM_INIT_AUTOMAKE(check,0.5.2) +AM_INIT_AUTOMAKE(check,0.6.0) dnl Checks for programs. AC_PROG_AWK diff --git a/check/src/check.h b/check/src/check.h index 6e8d926..c1a6a04 100644 --- a/check/src/check.h +++ b/check/src/check.h @@ -117,7 +117,10 @@ typedef struct SRunner SRunner; /* Opaque type for a test failure */ typedef struct TestResult TestResult; +/* Failure message */ char *tr_msg (TestResult *tr); +/* Line number at which failure occured */ +int tr_lno (TestResult *tr); SRunner *srunner_create (Suite *s); void srunner_free (SRunner *sr); diff --git a/check/src/check_run.c b/check/src/check_run.c index 3e9cbfb..93254f9 100644 --- a/check/src/check_run.c +++ b/check/src/check_run.c @@ -274,6 +274,11 @@ char *tr_msg (TestResult *tr) return tr->msg; } +int tr_lno (TestResult *tr) +{ + return tr->line; +} + static int percent_passed (TestStats *t) { if (t->n_failed == 0 && t->n_errors == 0) diff --git a/check/tests/check_check.c b/check/tests/check_check.c index 59f8542..6cd214c 100644 --- a/check/tests/check_check.c +++ b/check/tests/check_check.c @@ -5,11 +5,23 @@ #include "check.h" #include "error.h" - void setup (void); void cleanup (void); Suite *make_suite(void); +START_TEST(test_lno) +{ + fail("Failure expected"); /*line 14*/ +} +END_TEST + +START_TEST(test_mark_lno) +{ + mark_point(); /*line 20*/ + exit(1); /*should fail at line 20*/ +} +END_TEST + START_TEST(test_pass) { fail_unless (1==1, "This test should pass"); @@ -86,7 +98,7 @@ TestResult **trarray; START_TEST(test_check_nfailures) { - fail_unless (nfailures == 7, "Unexpected number of failures received"); + fail_unless (nfailures == 9, "Unexpected number of failures received"); } END_TEST @@ -94,6 +106,8 @@ START_TEST(test_check_failures) { int i; char *msgar[] = { + "Failure expected", + "Early exit with return value 1", "Completed properly", "This test should fail", "Received signal 11", @@ -101,12 +115,32 @@ START_TEST(test_check_failures) "Received signal 8", "Early exit with return value 1", "Completed properly"}; + int lnos[] = { + 14, + 20, + -1, + -1, + -1, + -1, + -1, + -1, + -1}; + for (i = 0; i < nfailures; i++) { char *msg; + + if (lnos[i] > 0 && tr_lno(trarray[i]) != lnos[i]) { + char *emsg = emalloc (CMAXMSG); + snprintf (emsg, CMAXMSG, "Expected lno %d, got %d", + lnos[i], tr_lno(trarray[i])); + fail (emsg); + free (emsg); + } + msg = tr_msg(trarray[i]); if (strcmp (msg, msgar[i]) != 0) { char *emsg = emalloc (CMAXMSG); - snprintf (emsg, CMAXMSG,"Expected %s, got %s", msg, msgar[i]); + snprintf (emsg, CMAXMSG,"Expected %s, got %s", msgar[i], msg); fail (emsg); } } @@ -122,6 +156,8 @@ Suite *make_suite(void) suite_add_tcase (s, tc_simple); suite_add_tcase (s, tc_signal); suite_add_tcase (s, tc_limit); + tcase_add_test (tc_simple, test_lno); + tcase_add_test (tc_simple, test_mark_lno); tcase_add_test (tc_simple, test_pass); tcase_add_test (tc_simple, test_fail); tcase_add_test (tc_signal, test_segv);