This patch sets up an autotest framework and tests two typical lines from an rc file.
-- William Pursell
commit b3376e31d67ec354939b9d8850d3e764c648d070 Author: William Pursell <[EMAIL PROTECTED]> Date: Sat Oct 11 23:59:39 2008 +0100 Setup autotest framework, validate some rc parsing. This commit sets up autotest, and links the test program against the real code. Also, some typical lines from an rc file are parsed and (superficially) validated. diff --git a/configure.ac b/configure.ac index 270251a..73be694 100644 --- a/configure.ac +++ b/configure.ac @@ -1276,7 +1276,15 @@ test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq" AC_TRY_RUN(main(){exit(0);},,AC_MSG_ERROR(Can't run the compiler - internal error. Sorry.)) -AC_CONFIG_FILES([ Makefile tests/Makefile src/Makefile src/doc/Makefile]) + +AC_CONFIG_TESTDIR([tests]) + +AC_CONFIG_FILES([ Makefile + tests/Makefile + src/Makefile + src/doc/Makefile +]) +AC_CONFIG_FILES([tests/rc-parse-sh],[chmod +x tests/rc-parse-sh]) AC_OUTPUT for i in term.sh tty.sh comm.sh osdef.sh; do diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c2402bb --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +package.m4 +testsuite diff --git a/tests/Makefile.am b/tests/Makefile.am index 8fb3644..47945b4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,68 @@ -TESTS = screen-test -check_PROGRAMS = screen-test +check_PROGRAMS = rc-parse +rc_parse_SOURCES = rc-parse.c \ + $(srcdir)/../src/process.c \ + $(srcdir)/../src/display.c \ + $(srcdir)/../src/resize.c \ + $(srcdir)/../src/screen.c \ + $(srcdir)/../src/mark.c \ + $(srcdir)/../src/window.c \ + $(srcdir)/../src/socket.c \ + $(srcdir)/../src/utmp.c \ + $(srcdir)/../src/encoding.c \ + $(srcdir)/../src/layer.c \ + $(srcdir)/../src/help.c \ + $(srcdir)/../src/acls.c \ + $(srcdir)/../src/fileio.c \ + $(srcdir)/../src/logfile.c \ + $(srcdir)/../src/misc.c \ + $(srcdir)/../src/termcap.c \ + $(srcdir)/../src/attacher.c \ + $(srcdir)/../src/ansi.c \ + $(srcdir)/../src/input.c \ + $(srcdir)/../src/nethack.c \ + $(srcdir)/../src/loadav.c \ + $(srcdir)/../src/search.c \ + $(srcdir)/../src/term.c \ + $(srcdir)/../src/comm.c \ + $(srcdir)/../src/pty.c \ + $(srcdir)/../src/sched.c \ + ../src/tty.c \ + ../src/kmapdef.c +rc_parse_CPPFLAGS = $(AM_CPPFLAGS) -Dmain=main_test + +AM_CPPFLAGS = -I$(srcdir)/../src -I../src -DETCSCREENRC='"$(ETCSCREENRC)"' \ + -DSCREENENCODINGS='"$(SCREENENCODINGS)"' + +# The `:;' works around a Bash 3.2 bug when the output is not writeable. +$(srcdir)/package.m4: $(top_srcdir)/configure.ac + :;{ \ + echo '# Signature of the current package.' && \ + echo 'm4_define([AT_PACKAGE_NAME], [EMAIL PROTECTED]@])' && \ + echo 'm4_define([AT_PACKAGE_TARNAME], [EMAIL PROTECTED]@])' && \ + echo 'm4_define([AT_PACKAGE_VERSION], [EMAIL PROTECTED]@])' && \ + echo 'm4_define([AT_PACKAGE_STRING], [EMAIL PROTECTED]@])' && \ + echo 'm4_define([AT_PACKAGE_BUGREPORT], [EMAIL PROTECTED]@])'; \ + } >'$(srcdir)/package.m4' + + +EXTRA_DIST = $(srcdir)/package.m4 +EXTRA_DIST += testsuite.at $(TESTSUITE) +TESTSUITE = $(srcdir)/testsuite + +check-local: atconfig $(TESTSUITE) + $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) + +installcheck-local: atconfig $(TESTSUITE) + $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \ + $(TESTSUITEFLAGS) + +clean-local: + test ! -f '$(TESTSUITE)' || \ + $(SHELL) '$(TESTSUITE)' --clean + +AUTOM4TE = autom4te +AUTOTEST = $(AUTOM4TE) --language=autotest +$(TESTSUITE): $(srcdir)/testsuite.at + $(AUTOTEST) -I '$(srcdir)' -o [EMAIL PROTECTED] [EMAIL PROTECTED] + mv [EMAIL PROTECTED] $@ diff --git a/tests/rc-parse-sh.in b/tests/rc-parse-sh.in new file mode 100644 index 0000000..aa8c5aa --- /dev/null +++ b/tests/rc-parse-sh.in @@ -0,0 +1,3 @@ +#!/bin/bash + +unit-test diff --git a/tests/rc-parse.c b/tests/rc-parse.c new file mode 100644 index 0000000..18fa78b --- /dev/null +++ b/tests/rc-parse.c @@ -0,0 +1,48 @@ + +#include <stdio.h> +#include <stdlib.h> +#include "screen.h" + +/* + * We are linking with screen.o that contains a main + * symbol, which we rename with a -D directive. + * Here, we must undo that to get a real main. + */ +#undef main + +struct line { + char *line; + int args; +}; + +/* Lines to test for rc parser. */ +struct line test_lines[] = { + { "termcap xterm hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l", 3 }, + { "terminfo xterm hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l", + 3 }, + { 0 } +}; + +int +main( void ) +{ + struct line *line; + char buf[ 2048 ]; + char *args[ MAXARGS ]; + int argl[ MAXARGS ]; + int status; + + status = EXIT_SUCCESS; + for( line = test_lines; line->line; line++ ) { + strcpy( buf, line->line ); + Parse( buf, sizeof buf, args, argl ); + if( args[ line->args ] != NULL ) { + status = EXIT_FAILURE; + fprintf( stderr, "Expected %d args in %s\n", + line->args, line->line ); + } + } + + return status; +} + diff --git a/tests/screen-test.c b/tests/screen-test.c deleted file mode 100644 index 66cd396..0000000 --- a/tests/screen-test.c +++ /dev/null @@ -1,14 +0,0 @@ - -#include <stdio.h> - -int -main( void ) -{ - puts( "No unit tests have been written!" ); - - /* - * Automake interprets a return of 77 to mean - * that the test was skipped. - */ - return 77; -} diff --git a/tests/testsuite.at b/tests/testsuite.at new file mode 100644 index 0000000..9e9793b --- /dev/null +++ b/tests/testsuite.at @@ -0,0 +1,5 @@ + +AT_INIT([]) +AT_SETUP([rc files]) +AT_CHECK([rc-parse-sh],[0],[stdout],[stderr]) +AT_CLEANUP