diff --git a/Makefile b/Makefile index 30ff3ca..17c4be9 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ endif # ----- Rules ----------------------------------------------------------------- .PHONY: all dep depend clean install uninstall manual upload-manual -.PHONY: update montage +.PHONY: update montage test tests valgrind .SUFFIXES: .fig .xpm .ppm @@ -156,6 +156,18 @@ dep depend .depend: -include $(OBJS:.o=.d) +# ----- Tests ----------------------------------------------------------------- + +test tests: all + LANG= sh -c \ + 'passed=0 && cd test && \ + for n in [a-z]*; do \ + SCRIPT=$$n . ./$$n; done; \ + echo "Passed all $$passed tests"' + +valgrind: + VALGRIND="valgrind -q" $(MAKE) tests + # ----- Cleanup --------------------------------------------------------------- clean: diff --git a/README b/README index 294d712..8de9a81 100644 --- a/README +++ b/README @@ -613,4 +613,4 @@ output. %exit immediately exits fped, without invoking the GUI. %tsort is used to test-drive the topological sort algorithm. The items in the curly braces are declarations of nodes with (-) or without (+) decay or edges in the partial order. The optional number is -the edge's priority. See tsort.c for details. +the edge's priority. See tsort.c for details, test/tsort for examples. diff --git a/fped.c b/fped.c index dc8d70d..9b6c353 100644 --- a/fped.c +++ b/fped.c @@ -65,10 +65,11 @@ static void load_file(const char *name) static void usage(const char *name) { fprintf(stderr, -"usage: %s [-k] [-p|-P] [cpp_option ...] [in_file [out_file]]\n\n" +"usage: %s [-k] [-p|-P] [-T] [cpp_option ...] [in_file [out_file]]\n\n" " -k write KiCad output, then exit\n" " -p write Postscript output, then exit\n" " -P write Postscript output (full page), then exit\n" +" -T test mode. Load file, then exit\n" " cpp_option -Idir, -Dname[=value], or -Uname\n" , name); exit(1); @@ -82,12 +83,13 @@ int main(int argc, char **argv) char *args[2]; int fake_argc; char opt[] = "-?"; - int error, batch; + int error; + int batch = 0; int batch_write_kicad = 0; int batch_write_ps = 0, batch_write_ps_fullpage = 0; int c; - while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF) + while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF) switch (c) { case 'k': batch_write_kicad = 1; @@ -98,6 +100,9 @@ int main(int argc, char **argv) case 'P': batch_write_ps_fullpage = 1; break; + case 'T': + batch = 1; + break; case 'D': case 'U': case 'I': @@ -112,7 +117,8 @@ int main(int argc, char **argv) if (batch_write_ps && batch_write_ps_fullpage) usage(name); - batch = batch_write_kicad || batch_write_ps || batch_write_ps_fullpage; + if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage) + batch = 1; if (!batch) { args[0] = name; diff --git a/test/Common b/test/Common new file mode 100755 index 0000000..42989eb --- /dev/null +++ b/test/Common @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Common - Elements shared by all regression tests for fped +# +# Written 2010 by Werner Almesberger +# Copyright 2010 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +fped() +{ + echo -n "$1: " 1>&2 + shift + cat >_in + $VALGRIND ../fped -T _in "$@" >_out 2>&1 || { + echo FAILED "($SCRIPT)" 1>&2 + cat _out + rm -f _in _out + exit 1 + } + rm -f _in +} + + +fped_fail() +{ + echo -n "$1: " 1>&2 + shift + cat >_in + $VALGRIND ../fped -T _in "$@" >_out 2>&1 && { + echo FAILED "($SCRIPT)" 1>&2 + cat _out + rm -f _in _out + exit 1 + } + rm -f _in +} + + +expect() +{ + diff -u - "$@" _out >_diff || { + echo FAILED "($SCRIPT)" 1>&2 + cat _diff 1>&2 + rm -f _out _diff + exit 1 + } + echo PASSED 1>&2 + rm -f _out _diff + passed=`expr ${passed:-0} + 1` +} diff --git a/test/tsort b/test/tsort new file mode 100644 index 0000000..52806be --- /dev/null +++ b/test/tsort @@ -0,0 +1,155 @@ +#!/bin/sh +. ./Common + +############################################################################### + +fped "tsort: total order" <nodes) /* we have at least one cycle */ + if (tsort->nodes) { + fprintf(stderr, "cycle detected in partial order\n"); abort(); + } free(tsort); res[n] = NULL; return res;