Assorted improvements to diagnostics.
[pspp] / tests / language / command.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([command parser])
18
19 AT_SETUP([command parser negative tests])
20 AT_DATA([command.sps], [dnl
21 DATA X.
22 XYZZY.
23 CLOSE FILE XYZZY.
24 foo.
25 ])
26 AT_CHECK([pspp command.sps], [1], [dnl
27 command.sps:1.1-1.6: error: Unknown command `DATA X'.
28     1 | DATA X.
29       | ^~~~~~
30
31 command.sps:2.1-2.5: error: Unknown command `XYZZY'.
32     2 | XYZZY.
33       | ^~~~~
34
35 command.sps:3.1-3.16: error: Unknown command `CLOSE FILE XYZZY'.
36     3 | CLOSE FILE XYZZY.
37       | ^~~~~~~~~~~~~~~~
38
39 command.sps:4.1-4.3: error: Unknown command `foo'.
40     4 | foo.
41       | ^~~
42 ])
43 AT_CLEANUP
44
45 dnl Tests for a bug which crashed pspp when given certain invalid input.
46 AT_SETUP([command parser crash bug])
47 AT_DATA([command.sps], [dnl
48 DATA rubbish.
49 EXECUTE.
50 ])
51 AT_CHECK([pspp -O format=csv command.sps], [1], [dnl
52 "command.sps:1.1-1.12: error: Unknown command `DATA rubbish'.
53     1 | DATA rubbish.
54       | ^~~~~~~~~~~~"
55
56 "command.sps:2.1-2.7: error: EXECUTE: EXECUTE is allowed only after the active dataset has been defined.
57     2 | EXECUTE.
58       | ^~~~~~~"
59 ])
60 AT_CLEANUP
61
62 dnl Tests for a bug where FINISH or EXIT wasn't executed until the lexer
63 dnl read the first token of the next command.
64 dnl
65 dnl (If this recurs, the test will run forever.)
66 AT_SETUP([FINISH executes immediately])
67 AT_CHECK([(echo "FINISH."; while echo ; do true; done) | pspp], [0], [ignore], [ignore])
68 AT_CLEANUP
69
70 AT_BANNER([ERASE])
71
72 AT_SETUP([ERASE -- safer mode])
73 AT_DATA([foobar], [contents
74 ])
75 AT_DATA([erase.sps], [dnl
76 set safer on
77
78 erase FILE='foobar'.
79 ])
80 AT_CHECK([pspp -O format=csv erase.sps], [1], [dnl
81 "erase.sps:3.1-3.5: error: ERASE: This command not allowed when the SAFER option is set.
82     3 | erase FILE='foobar'.
83       | ^~~~~"
84 ])
85 AT_CHECK([cat foobar], [0], [contents
86 ])
87 AT_CLEANUP
88
89 AT_SETUP([ERASE -- not safer mode])
90 AT_DATA([foobar], [contents
91 ])
92 AT_CHECK([test -e foobar])
93 AT_DATA([erase.sps], [dnl
94 erase FILE='foobar'.
95 ])
96 AT_CHECK([pspp -O format=csv erase.sps])
97 AT_CHECK([test ! -e foobar])
98 AT_CLEANUP
99
100 AT_BANNER([N OF CASES])
101
102 AT_SETUP([N OF CASES])
103 AT_DATA([n-of-cases.sps], [dnl
104 INPUT PROGRAM.
105 LOOP #i = 1 TO 100.
106 COMPUTE x=#i.
107 END CASE.
108 END LOOP.
109 END FILE.
110 END INPUT PROGRAM.
111
112 N OF CASES 15.
113
114 LIST.
115 ])
116 AT_CHECK([pspp -O format=csv n-of-cases.sps], [0], [dnl
117 Table: Data List
118 x
119 1.00
120 2.00
121 3.00
122 4.00
123 5.00
124 6.00
125 7.00
126 8.00
127 9.00
128 10.00
129 11.00
130 12.00
131 13.00
132 14.00
133 15.00
134 ])
135 AT_CLEANUP
136
137 AT_BANNER([COMMENT])
138
139 dnl Tests for a bug wherein a comment just before end-of-file caused an
140 dnl infinite loop.
141 AT_SETUP([COMMENT at end of file])
142 AT_DATA([comment.sps], [dnl
143 COMMENT this is a comment at end of file.
144 ])
145 AT_CHECK([pspp -O format=csv comment.sps])
146 AT_CLEANUP