]> granicus.if.org Git - check/commitdiff
Changed test output, added end-to-end test, and removed redundant field from TestResu...
authoramalec <amalec@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Fri, 22 Jun 2001 00:36:49 +0000 (00:36 +0000)
committeramalec <amalec@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Fri, 22 Jun 2001 00:36:49 +0000 (00:36 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@31 64e312b2-a51f-0410-8e61-82d0ca0eb02a

check/src/check.h
check/src/check_run.c
check/tests/Makefile.am
check/tests/Makefile.in
check/tests/check_check.c
check/tests/ex_output.c [new file with mode: 0644]
check/tests/test_output.sh [new file with mode: 0755]

index b2e96dbb2abfcb66bdf5e63998e082d1ab88007b..6972d9be37cd293f7bdef58f9b3911742bfab073 100644 (file)
@@ -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 */
index a06cac2efdc176be110f71d5b6fc31f34c65ea5c..964918d2a6c1b7946c21ed64156a72e9bf9c87d5 100644 (file)
@@ -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);
 }
 
index a0689746f2caeeb178cb252a457c045b13eefb79..0af06be475cfa1a0fb43577ec56887ac53fcbcb4 100644 (file)
@@ -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
 
index 0f473451d51b6bc751f841c4711a8a934a9dfce9..d40cfdef565b0d445b2016f5812dec78f6c13196 100644 (file)
@@ -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)
index 79eb8d7de7550358a49b7e94fe5ddc54deced486..7393a3d254317b56c46ea59ed529ec379161ae30 100644 (file)
@@ -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 (file)
index 0000000..9d0b1ab
--- /dev/null
@@ -0,0 +1,72 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <check.h>
+
+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 (executable)
index 0000000..dc4e54f
--- /dev/null
@@ -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