71e50819e0307f1e5cdc97a50c654063d9634b2a
[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: error: ERASE: This command not allowed when the SAFER option is set.
82 ])
83 AT_CHECK([cat foobar], [0], [contents
84 ])
85 AT_CLEANUP
86
87 AT_SETUP([ERASE -- not safer mode])
88 AT_DATA([foobar], [contents
89 ])
90 AT_CHECK([test -e foobar])
91 AT_DATA([erase.sps], [dnl
92 erase FILE='foobar'.
93 ])
94 AT_CHECK([pspp -O format=csv erase.sps])
95 AT_CHECK([test ! -e foobar])
96 AT_CLEANUP
97
98 AT_BANNER([N OF CASES])
99
100 AT_SETUP([N OF CASES])
101 AT_DATA([n-of-cases.sps], [dnl
102 INPUT PROGRAM.
103 LOOP #i = 1 TO 100.
104 COMPUTE x=#i.
105 END CASE.
106 END LOOP.
107 END FILE.
108 END INPUT PROGRAM.
109
110 N OF CASES 15.
111
112 LIST.
113 ])
114 AT_CHECK([pspp -O format=csv n-of-cases.sps], [0], [dnl
115 Table: Data List
116 x
117 1.00
118 2.00
119 3.00
120 4.00
121 5.00
122 6.00
123 7.00
124 8.00
125 9.00
126 10.00
127 11.00
128 12.00
129 13.00
130 14.00
131 15.00
132 ])
133 AT_CLEANUP
134
135 AT_BANNER([COMMENT])
136
137 dnl Tests for a bug wherein a comment just before end-of-file caused an
138 dnl infinite loop.
139 AT_SETUP([COMMENT at end of file])
140 AT_DATA([comment.sps], [dnl
141 COMMENT this is a comment at end of file.
142 ])
143 AT_CHECK([pspp -O format=csv comment.sps])
144 AT_CLEANUP