From: amalec Date: Fri, 22 Jun 2001 00:36:49 +0000 (+0000) Subject: Changed test output, added end-to-end test, and removed redundant field from TestResu... X-Git-Tag: 0.10.0~1111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80414aad6e2ab96f50274fda0d787163ae592e52;p=check Changed test output, added end-to-end test, and removed redundant field from TestResult struct git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@31 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/check/src/check.h b/check/src/check.h index b2e96db..6972d9b 100644 --- a/check/src/check.h +++ b/check/src/check.h @@ -155,8 +155,9 @@ TestResult **srunner_failures (SRunner *sr); /* Print a summary report of %passed, #checks, failures */ void print_summary_report (SRunner *sr); -/* Print a detailed report of failures (one failure per line) */ -void print_failures (SRunner *sr); +/* Print a detailed report of test results + print_mode works like with srunner_run_all*/ +void print_results (SRunner *sr, int print_mode); #endif /* CHECK_H */ diff --git a/check/src/check_run.c b/check/src/check_run.c index a06cac2..964918d 100644 --- a/check/src/check_run.c +++ b/check/src/check_run.c @@ -44,7 +44,6 @@ struct TestResult { int rtype; /* Type of result */ char *file; /* File where the test occured */ int line; /* Line number where the test occurred */ - int exact_loc; /* Is the location given by file:line exact? */ char *tcname; /* Test case that generated the result */ char *msg; /* Failure message */ }; @@ -55,7 +54,7 @@ static void srunner_add_failure (SRunner *sr, TestResult *tf); static TestResult *tfun_run (int msqid, char *tcname, TF *tf); static List *srunner_resultlst (SRunner *sr); -static void print_failure (TestResult *tr); +static void tr_print (TestResult *tr); static char *signal_msg (int sig); static char *exit_msg (int exitstatus); static int non_pass (int val); @@ -114,8 +113,7 @@ void srunner_run_all (SRunner *sr, int print_mode) } if (print_mode >= CRMINIMAL) print_summary_report (sr); - if (print_mode >= CRNORMAL) - print_failures (sr); + print_results (sr, print_mode); } static void srunner_add_failure (SRunner *sr, TestResult *tr) @@ -171,7 +169,6 @@ static TestResult *receive_failure_info (int msqid, int status, char *tcname) if (WIFSIGNALED(status)) { tr->rtype = CRERROR; - tr->exact_loc = 0; tr->msg = signal_msg (WTERMSIG(status)); return tr; } @@ -180,7 +177,9 @@ static TestResult *receive_failure_info (int msqid, int status, char *tcname) if (WEXITSTATUS(status) == 0) { tr->rtype = CRPASS; - tr->exact_loc = 1; + /* TODO: It would be cleaner to strdup this & + not special case the free...*/ + tr->msg = "Test passed"; } else { @@ -188,11 +187,9 @@ static TestResult *receive_failure_info (int msqid, int status, char *tcname) if (fmsg == NULL) { /* implies early exit */ tr->rtype = CRERROR; tr->msg = exit_msg (WEXITSTATUS(status)); - tr->exact_loc = 0; } else { tr->rtype = CRFAILURE; - tr->exact_loc = 1; tr->msg = emalloc(strlen(fmsg->msg) + 1); strcpy (tr->msg, fmsg->msg); free (fmsg); @@ -231,13 +228,23 @@ void print_summary_report (SRunner *sr) return; } -void print_failures (SRunner *sr) +void print_results (SRunner *sr, int print_mode) { List *resultlst; + if (print_mode < CRNORMAL) + return; + resultlst = sr->resultlst; for (list_front(resultlst); !list_at_end(resultlst); list_advance(resultlst)) { - print_failure (list_val(resultlst)); + TestResult *tr = list_val(resultlst); + if (tr_rtype(tr) == CRPASS) + if (print_mode >= CRVERBOSE) + tr_print (tr); + else + ; + else + tr_print (tr); } return; } @@ -303,13 +310,27 @@ static int percent_passed (TestStats *t) (float) t->n_checked * 100); } -static void print_failure (TestResult *tr) +static char *rtype_to_string (int rtype) +{ + switch (rtype) { + case CRPASS: + return "P"; + break; + case CRFAILURE: + return "F"; + break; + case CRERROR: + return "E"; + break; + } +} + +static void tr_print (TestResult *tr) { char *exact_msg; - if (tr->rtype == CRPASS) - return; - exact_msg = (tr->exact_loc) ? "" : "(after this point) "; - printf ("%s:%d:%s: %s%s\n", tr->file, tr->line, tr->tcname, + exact_msg = (tr->rtype == CRERROR) ? "(after this point) ": ""; + printf ("%s:%d:%s:%s: %s%s\n", tr->file, tr->line, + rtype_to_string(tr->rtype), tr->tcname, exact_msg, tr->msg); } diff --git a/check/tests/Makefile.am b/check/tests/Makefile.am index a068974..0af06be 100644 --- a/check/tests/Makefile.am +++ b/check/tests/Makefile.am @@ -1,6 +1,6 @@ -TESTS=check_check check_list check_check_msg +TESTS=check_check check_list check_check_msg test_output.sh -noinst_PROGRAMS=check_check check_list check_stress check_check_msg +noinst_PROGRAMS=check_check check_list check_stress check_check_msg ex_output check_check_SOURCES= \ check_check.c @@ -14,6 +14,9 @@ check_stress_SOURCES=\ check_check_msg_SOURCES=\ check_check_msg.c +ex_output_SOURCES=\ + ex_output.c + INCLUDES= -I$(srcdir)/../src LDADD= ../src/libcheck.a diff --git a/check/tests/Makefile.in b/check/tests/Makefile.in index 0f47345..d40cfde 100644 --- a/check/tests/Makefile.in +++ b/check/tests/Makefile.in @@ -67,9 +67,9 @@ VERSION = @VERSION@ have_lyx = @have_lyx@ have_sgmltools = @have_sgmltools@ -TESTS = check_check check_list check_check_msg +TESTS = check_check check_list check_check_msg test_output.sh -noinst_PROGRAMS = check_check check_list check_stress check_check_msg +noinst_PROGRAMS = check_check check_list check_stress check_check_msg ex_output check_check_SOURCES = check_check.c @@ -83,6 +83,9 @@ check_stress_SOURCES = check_stress.c check_check_msg_SOURCES = check_check_msg.c +ex_output_SOURCES = ex_output.c + + INCLUDES = -I$(srcdir)/../src LDADD = ../src/libcheck.a @@ -113,6 +116,10 @@ check_check_msg_OBJECTS = check_check_msg.o check_check_msg_LDADD = $(LDADD) check_check_msg_DEPENDENCIES = ../src/libcheck.a check_check_msg_LDFLAGS = +ex_output_OBJECTS = ex_output.o +ex_output_LDADD = $(LDADD) +ex_output_DEPENDENCIES = ../src/libcheck.a +ex_output_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -125,9 +132,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = gtar GZIP_ENV = --best DEP_FILES = .deps/check_check.P .deps/check_check_msg.P \ -.deps/check_list.P .deps/check_stress.P -SOURCES = $(check_check_SOURCES) $(check_list_SOURCES) $(check_stress_SOURCES) $(check_check_msg_SOURCES) -OBJECTS = $(check_check_OBJECTS) $(check_list_OBJECTS) $(check_stress_OBJECTS) $(check_check_msg_OBJECTS) +.deps/check_list.P .deps/check_stress.P .deps/ex_output.P +SOURCES = $(check_check_SOURCES) $(check_list_SOURCES) $(check_stress_SOURCES) $(check_check_msg_SOURCES) $(ex_output_SOURCES) +OBJECTS = $(check_check_OBJECTS) $(check_list_OBJECTS) $(check_stress_OBJECTS) $(check_check_msg_OBJECTS) $(ex_output_OBJECTS) all: all-redirect .SUFFIXES: @@ -181,6 +188,10 @@ check_check_msg: $(check_check_msg_OBJECTS) $(check_check_msg_DEPENDENCIES) @rm -f check_check_msg $(LINK) $(check_check_msg_LDFLAGS) $(check_check_msg_OBJECTS) $(check_check_msg_LDADD) $(LIBS) +ex_output: $(ex_output_OBJECTS) $(ex_output_DEPENDENCIES) + @rm -f ex_output + $(LINK) $(ex_output_LDFLAGS) $(ex_output_OBJECTS) $(ex_output_LDADD) $(LIBS) + tags: TAGS ID: $(HEADERS) $(SOURCES) $(LISP) diff --git a/check/tests/check_check.c b/check/tests/check_check.c index 79eb8d7..7393a3d 100644 --- a/check/tests/check_check.c +++ b/check/tests/check_check.c @@ -27,7 +27,6 @@ START_TEST(test_pass) { fail_unless (1==1, "This test should pass"); fail_unless (9999, "This test should pass"); - fail("Completed properly"); } END_TEST @@ -99,7 +98,7 @@ TestResult **trarray; START_TEST(test_check_nfailures) { - fail_unless (nfailures == 9, "Unexpected number of failures received"); + fail_unless (nfailures == 8, "Unexpected number of failures received"); } END_TEST @@ -109,7 +108,7 @@ START_TEST(test_check_failure_msgs) char *msgar[] = { "Failure expected", "Early exit with return value 1", - "Completed properly", + "Test passed", "This test should fail", "Received signal 11", "Received signal 8", @@ -163,7 +162,7 @@ START_TEST(test_check_failure_ftypes) int ftypes[] = { CRFAILURE, CRERROR, - CRFAILURE, + CRPASS, CRFAILURE, CRERROR, CRERROR, diff --git a/check/tests/ex_output.c b/check/tests/ex_output.c new file mode 100644 index 0000000..9d0b1ab --- /dev/null +++ b/check/tests/ex_output.c @@ -0,0 +1,72 @@ +#include +#include +#include + +START_TEST(test_pass) +{ + fail_unless (1==1, "Shouldn't see this"); +} +END_TEST + +START_TEST(test_fail) +{ + fail("Failure"); +} +END_TEST + +START_TEST(test_exit) +{ + exit(1); +} +END_TEST + +Suite *make_suite (void) +{ + Suite *s; + TCase *tc; + + s = suite_create("Master"); + tc = tcase_create ("Core"); + suite_add_tcase(s, tc); + tcase_add_test (tc, test_pass); + tcase_add_test (tc, test_fail); + tcase_add_test (tc, test_exit); + + return s; +} + +void run_tests (int printmode) +{ + SRunner *sr; + Suite *s; + + s = make_suite(); + sr = srunner_create(s); + srunner_run_all(sr, printmode); +} + +int main (int argc, char **argv) +{ + + if (argc != 2) { + printf ("Usage: ex_output (CRSILENT | CRMINIMAL | CRNORMAL | CRVERBOSE)\n"); + return EXIT_FAILURE; + } + + if (strcmp (argv[1], "CRSILENT") == 0) + run_tests(CRSILENT); + else if (strcmp (argv[1], "CRMINIMAL") == 0) + run_tests(CRMINIMAL); + else if (strcmp (argv[1], "CRNORMAL") == 0) + run_tests(CRNORMAL); + else if (strcmp (argv[1], "CRVERBOSE") == 0) + run_tests(CRVERBOSE); + else { + printf ("Usage: ex_output (CRSILENT | CRMINIMAL | CRNORMAL | CRVERBOSE)\n"); + return EXIT_FAILURE; + } + + + return EXIT_SUCCESS; +} + diff --git a/check/tests/test_output.sh b/check/tests/test_output.sh new file mode 100755 index 0000000..dc4e54f --- /dev/null +++ b/check/tests/test_output.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +t0="x" +t1="xRunning suite: Master +33%: Checks: 3, Failures: 1, Errors: 1" +t2="xRunning suite: Master +33%: Checks: 3, Failures: 1, Errors: 1 +ex_output.c:13:F:Core: Failure +ex_output.c:17:E:Core: (after this point) Early exit with return value 1" +t3="xRunning suite: Master +33%: Checks: 3, Failures: 1, Errors: 1 +ex_output.c:7:P:Core: Test passed +ex_output.c:13:F:Core: Failure +ex_output.c:17:E:Core: (after this point) Early exit with return value 1" + +op0=`./ex_output CRSILENT` +op1=`./ex_output CRMINIMAL` +op2=`./ex_output CRNORMAL` +op3=`./ex_output CRVERBOSE` + +if [ "$t0" != x"$op0" ]; then + echo "Problem with ex_output CRSILENT"; + exit 1 +fi +if [ "$t1" != x"$op1" ]; then + echo "Problem with ex_output CRMINIMAL"; + exit 1 +fi +if [ "$t2" != x"$op2" ]; then + echo "Problem with ex_output CRNORMAL"; + exit 1 +fi +if [ "$t3" != x"$op3" ]; then + echo "Problem with ex_output CRVERBOSE"; + exit 1 +fi + +exit 0