Fix handling of #! at beginning of PSPP syntax file; add regression test.
authorBen Pfaff <blp@gnu.org>
Mon, 8 Jun 2009 04:57:36 +0000 (21:57 -0700)
committerBen Pfaff <blp@gnu.org>
Mon, 8 Jun 2009 04:57:36 +0000 (21:57 -0700)
Fixes bug #26518.

Thanks to John Darrington for testing.

src/language/syntax-file.c
tests/automake.mk
tests/bugs/shbang.sh [new file with mode: 0755]

index 678d2f51fa96b9217f6b172d190d7abf4dfbc01f..0771ade3a9e92dccc0c3063a7c14d13014c010e3 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
 
    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
@@ -100,6 +100,7 @@ read_syntax_file (struct getl_interface *s,
   do
     {
       sfs->ln++;
+      ds_clear (line);
       if (!ds_read_line (line, sfs->syntax_file, SIZE_MAX))
         {
           if (ferror (sfs->syntax_file))
index 0fa61752bfe5c9ca68de6651c0c2c88622176bbb..7bfd77bf69a2552cbca99e3c24287f80f8f5578f 100644 (file)
@@ -134,6 +134,7 @@ dist_TESTS = \
        tests/bugs/overwrite-special-file.sh \
        tests/bugs/piechart.sh \
        tests/bugs/random.sh \
+       tests/bugs/shbang.sh \
        tests/bugs/signals.sh \
        tests/bugs/t-test-with-temp.sh \
        tests/bugs/t-test.sh \
diff --git a/tests/bugs/shbang.sh b/tests/bugs/shbang.sh
new file mode 100755 (executable)
index 0000000..826d5dc
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+# This program tests that PSPP ignores the first line of a PSPP syntax
+# file that begins with #!, without issuing an error (bug #26518).
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+# ensure that top_srcdir and top_builddir  are absolute
+if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
+if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
+top_srcdir=`cd $top_srcdir; pwd`
+top_builddir=`cd $top_builddir; pwd`
+
+PSPP=$top_builddir/src/ui/terminal/pspp
+
+STAT_CONFIG_PATH=$top_srcdir/config
+export STAT_CONFIG_PATH
+
+
+cleanup()
+{
+     if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
+       echo "NOT cleaning $TEMPDIR"
+       return ; 
+     fi
+     cd /
+     rm -rf $TEMPDIR
+}
+
+
+fail()
+{
+    echo $activity
+    echo FAILED
+    cleanup;
+    exit 1;
+}
+
+
+no_result()
+{
+    echo $activity
+    echo NO RESULT;
+    cleanup;
+    exit 2;
+}
+
+pass()
+{
+    cleanup;
+    exit 0;
+}
+
+mkdir -p $TEMPDIR
+
+cd $TEMPDIR
+
+cat > $TESTFILE << EOF
+#! $PSPP
+DATA LIST LIST NOTABLE /a.
+BEGIN DATA.
+1
+2
+END DATA.
+LIST.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$SUPERVISOR $PSPP --testing-mode -e /dev/null $TESTFILE 
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+activity="compare output"
+perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
+diff -b  -w $TEMPDIR/pspp.list - << EOF
+       a
+--------
+    1.00
+    2.00
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+pass;