DELETE VARIABLES: Fix bugs related to details of case compaction.
[pspp] / tests / language / commands / delete-variables.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([DELETE VARIABLES])
18
19 dnl Checks for regressions against a crash reported in bug #38843.
20 AT_SETUP([DELETE VARIABLES with FILTER])
21 AT_DATA([delete-variables.sps], [dnl
22 DATA LIST LIST /a b.
23 BEGIN DATA.
24 1 3
25 4 6
26 7 9
27 END DATA.
28
29 FILTER BY b.
30 DELETE VARIABLES a.
31 LIST.
32 ])
33 AT_CHECK([pspp -O format=csv delete-variables.sps], [0], [dnl
34 Table: Reading free-form data from INLINE.
35 Variable,Format
36 a,F8.0
37 b,F8.0
38
39 Table: Data List
40 b
41 3.00
42 6.00
43 9.00
44 ])
45 AT_CLEANUP
46
47 dnl Checks for regression against a crash reported on pspp-users:
48 dnl https://lists.gnu.org/archive/html/pspp-users/2021-03/msg00025.html
49 AT_SETUP([DELETE VARIABLES with string variables])
50 AT_DATA([delete-variables.sps], [dnl
51 DATA LIST NOTABLE /s1 TO s2 1-2(A).
52 BEGIN DATA
53 12
54 END DATA.
55 DELETE VARIABLES s1.
56 NUMERIC n1.
57 LIST.
58 ])
59 AT_CHECK([pspp -O format=csv delete-variables.sps], [0], [dnl
60 Table: Data List
61 s2,n1
62 2,.  @&t@
63 ])
64 AT_CLEANUP
65
66 dnl Checks for regression against a crash by Frans Houuweling
67 dnl on Feb. 18, 2023.
68 AT_SETUP([DELETE VARIABLES crash])
69 AT_DATA([delete-variables.sps], [dnl
70 DATA LIST NOTABLE LIST
71   /ID (A8) respondent_city_of_birth (A25) respondent_name (A20) respondent_surname (A30) respondent_year_of_birth (F4.0).
72 BEGIN DATA
73 195 Amsterdam Floris "van Gelder" 1958
74 END DATA.
75 STRING varlist (A64).
76 COMPUTE found = 0.
77 EXECUTE.
78 MATCH FILES FILE= * /KEEP = ID TO respondent_name ALL.
79 EXECUTE.
80 DELETE VARIABLES respondent_surname found .
81 LIST.
82 ])
83 AT_CHECK([pspp --testing-mode -O format=csv delete-variables.sps], [0], [dnl
84 Table: Data List
85 ID,respondent_city_of_birth,respondent_name,respondent_year_of_birth,varlist
86 195,Amsterdam,Floris,1958,
87 ])
88 AT_CLEANUP
89
90 AT_SETUP([DELETE VARIABLES syntax errors])
91 AT_DATA([delete-variables.sps], [dnl
92 DATA LIST LIST NOTABLE /x y z.
93 BEGIN DATA.
94 1 2 3
95 END DATA.
96 DELETE VARIABLES x y z.
97 TEMPORARY.
98 DELETE VARIABLES x.
99 COMPUTE y=0.
100 DELETE VARIABLES x.
101 ])
102 AT_DATA([insert.sps], [dnl
103 INSERT FILE='delete-variables.sps' ERROR=IGNORE.
104 ])
105 AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
106 "delete-variables.sps:5.1-5.22: error: DELETE VARIABLES: DELETE VARIABLES may not be used to delete all variables from the active dataset dictionary.  Use NEW FILE instead.
107     5 | DELETE VARIABLES x y z.
108       | ^~~~~~~~~~~~~~~~~~~~~~"
109
110 "delete-variables.sps:7.1-7.16: error: DELETE VARIABLES: DELETE VARIABLES may not be used after TEMPORARY.
111     7 | DELETE VARIABLES x.
112       | ^~~~~~~~~~~~~~~~"
113
114 "delete-variables.sps:9.1-9.16: error: DELETE VARIABLES: DELETE VARIABLES may not be used when there are pending transformations (use EXECUTE to execute transformations).
115     9 | DELETE VARIABLES x.
116       | ^~~~~~~~~~~~~~~~"
117 ])
118 AT_CLEANUP