/* 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 */
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 */
};
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);
}
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)
if (WIFSIGNALED(status)) {
tr->rtype = CRERROR;
- tr->exact_loc = 0;
tr->msg = signal_msg (WTERMSIG(status));
return tr;
}
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 {
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);
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;
}
(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);
}
-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
check_check_msg_SOURCES=\
check_check_msg.c
+ex_output_SOURCES=\
+ ex_output.c
+
INCLUDES= -I$(srcdir)/../src
LDADD= ../src/libcheck.a
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
check_check_msg_SOURCES = check_check_msg.c
+ex_output_SOURCES = ex_output.c
+
+
INCLUDES = -I$(srcdir)/../src
LDADD = ../src/libcheck.a
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)
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:
@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)
{
fail_unless (1==1, "This test should pass");
fail_unless (9999, "This test should pass");
- fail("Completed properly");
}
END_TEST
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
char *msgar[] = {
"Failure expected",
"Early exit with return value 1",
- "Completed properly",
+ "Test passed",
"This test should fail",
"Received signal 11",
"Received signal 8",
int ftypes[] = {
CRFAILURE,
CRERROR,
- CRFAILURE,
+ CRPASS,
CRFAILURE,
CRERROR,
CRERROR,
--- /dev/null
+#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;
+}
+
--- /dev/null
+#!/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