02b713f8b96aad762efa8cf8c5b1f60143639de1
[pspp] / tests / language / expressions / parse.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([expression parsing])
18
19 AT_SETUP([parse expression with unknown variable crash])
20 AT_DATA([parse.sps], [dnl
21 INPUT PROGRAM.
22 LOOP c=1 to 10.
23 COMPUTE var1=NORMAL(100).
24 END CASE.
25 END LOOP.
26 END FILE.
27 END INPUT PROGRAM.
28
29
30 IF ( y > 0 ) .
31 COMPUTE x=y.
32 END IF.
33 ])
34 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
35 parse.sps:10: error: IF: Unknown identifier y.
36
37 parse.sps:11: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
38 ])
39 AT_CLEANUP
40
41 AT_SETUP([parsing boolean expression with type mismatch])
42 AT_DATA([parse.sps], [dnl
43 DATA LIST NOTABLE/x 1(A).
44 IF 'foo'.
45 ])
46 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
47 "parse.sps:2: error: IF: Type mismatch: expression has string type, but a boolean value is required here."
48 ])
49 AT_CLEANUP
50
51 AT_SETUP([parsing numeric expression with type mismatch])
52 AT_DATA([parse.sps], [dnl
53 DATA LIST NOTABLE/x 1.
54 COMPUTE x='foo'.
55 ])
56 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
57 "parse.sps:2: error: COMPUTE: Type mismatch: expression has string type, but a numeric value is required here."
58 ])
59 AT_CLEANUP
60
61 AT_SETUP([parsing string expression with type mismatch])
62 AT_KEYWORDS([expression negative])
63 AT_DATA([parse.sps], [dnl
64 DATA LIST NOTABLE/x 1(A).
65 COMPUTE x=1.
66 ])
67 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
68 "parse.sps:2: error: COMPUTE: Type mismatch: expression has number type, but a string value is required here."
69 ])
70 AT_CLEANUP
71
72 AT_SETUP([assigning string expression to new variable])
73 AT_KEYWORDS([expression negative])
74 AT_DATA([parse.sps], [dnl
75 DATA LIST NOTABLE/x 1(A).
76 COMPUTE y='a'.
77 ])
78 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
79 "parse.sps:2: error: COMPUTE: This command tries to create a new variable y by assigning a string value to it, but this is not supported.  Use the STRING command to create the new variable with the correct width before assigning to it, e.g. STRING y(A20)."
80 ])
81 AT_CLEANUP
82
83 AT_SETUP([parse expression with unknown system variable])
84 AT_KEYWORDS([expression negative])
85 AT_DATA([parse.sps], [dnl
86 DATA LIST NOTABLE/x 1.
87 COMPUTE x=$nonexistent.
88 ])
89 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
90 parse.sps:2: error: COMPUTE: Unknown system variable $nonexistent.
91 ])
92 AT_CLEANUP
93
94 AT_SETUP([parse expression with unknown identifier])
95 AT_KEYWORDS([expression negative])
96 AT_DATA([parse.sps], [dnl
97 DATA LIST NOTABLE/x 1.
98 COMPUTE x=y.
99 ])
100 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
101 parse.sps:2: error: COMPUTE: Unknown identifier y.
102 ])
103 AT_CLEANUP
104
105 AT_SETUP([parse expression with extension function in compatibility mode])
106 AT_KEYWORDS([expression negative])
107 AT_DATA([parse.sps], [dnl
108 DEBUG EVALUATE/ACOS(0)*0.
109 ])
110 AT_CHECK([pspp --testing-mode --syntax=compatible -O format=csv parse.sps], [0], [dnl
111 parse.sps:1: warning: DEBUG EVALUATE: ACOS(number) is a PSPP extension.
112
113 0.00
114 ])
115 AT_CLEANUP
116
117 AT_SETUP([LAG expression following TEMPORARY])
118 AT_KEYWORDS([expression negative])
119 AT_DATA([parse.sps], [dnl
120 DATA LIST NOTABLE/x 1.
121 TEMPORARY
122 COMPUTE y=LAG(x).
123 ])
124 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
125 parse.sps:3: error: COMPUTE: LAG(num_variable) may not appear after TEMPORARY.
126 ])
127 AT_CLEANUP
128
129 AT_SETUP([parse expression with invalid logical expression])
130 AT_DATA([parse.sps], [dnl
131 INPUT PROGRAM.
132 LOOP c=1 to 10.
133 COMPUTE var1=NORMAL(100).
134 END CASE.
135 END LOOP.
136 END FILE.
137 END INPUT PROGRAM.
138
139 SELECT IF 2.
140 ])
141 AT_CHECK([pspp -O format=csv parse.sps], [1], [dnl
142 "parse.sps:9: error: SELECT IF: A logical expression was found to have a value other than 0 (false), 1 (true), or the system-missing value.  The result was forced to 0."
143 ])
144 AT_CLEANUP