1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([PRINT and WRITE])
dnl These tests check unusual aspects of the PRINT and WRITE
dnl transformations:
dnl
dnl - PRINT puts spaces between variables, unless a format
dnl is specified explicitly.
dnl
dnl - WRITE doesn't put space between variables.
dnl
dnl - PRINT to an external file prefixes each line with a space.
dnl
dnl - PRINT EJECT to an external file indicates a formfeed by a "1"
dnl in the first column.
dnl
dnl - WRITE writes out spaces for system-missing values, not a period.
dnl
dnl - When no output is specified, an empty record is output.
AT_SETUP([PRINT numeric variables])
AT_DATA([print.sps], [dnl
data list notable /x y 1-2.
begin data.
12
34
6
7
90
end data.
print /x y.
print eject /x y 1-2.
print /x '-' y.
print.
execute.
])
AT_CHECK([pspp -O format=csv print.sps], [0], [dnl
1 2 @&t@
12
1 -2 @&t@
3 4 @&t@
34
3 -4 @&t@
. 6 @&t@
.6
. -6 @&t@
7 . @&t@
7.
7 -. @&t@
9 0 @&t@
90
9 -0 @&t@
])
AT_CLEANUP
AT_SETUP([PRINT string variables])
AT_DATA([print.sps], [dnl
DATA LIST FREE /s8 (a8) s10 (a10) vl255 (a255) vl258 (a258).
BEGIN DATA.
12345678
AaaaaaaaaZ
AbbbbMaryHadALittleLambbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZ
AccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccZ
87654321
AnnnnnnnnZ
AmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmZ
AoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooWhyIsItSoZ
END DATA.
print
outfile='print.txt'
/s10 * vl255 * vl258 *.
EXECUTE.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat print.txt], [0], [dnl
AaaaaaaaaZ AbbbbMaryHadALittleLambbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZ AccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccZ @&t@
AnnnnnnnnZ AmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmZ AoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooWhyIsItSoZ @&t@
])
AT_CLEANUP
AT_SETUP([PRINT to file])
AT_DATA([print.sps], [dnl
data list notable /x y 1-2.
begin data.
12
34
6
7
90
end data.
print outfile='print.out' /x y.
print eject outfile='print.out' /x y (f1,f1).
print outfile='print.out' /x '-' y.
print outfile='print.out'.
execute.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat print.out], [0], [dnl
1 2 @&t@
112
1 -2 @&t@
@&t@
3 4 @&t@
134
3 -4 @&t@
@&t@
. 6 @&t@
1.6
. -6 @&t@
@&t@
7 . @&t@
17.
7 -. @&t@
@&t@
9 0 @&t@
190
9 -0 @&t@
@&t@
])
AT_CLEANUP
dnl Tests for a bug which crashed when deallocating after a bad PRINT
dnl command.
AT_SETUP([PRINT crash bug])
AT_DATA([print.sps], [dnl
DATA LIST LIST NOTABLE /a * b *.
BEGIN DATA.
1 2
3 4
END DATA.
PRINT F8.2
LIST.
])
AT_CHECK([pspp -O format=csv print.sps], [1], [dnl
"print.sps:7.7-7.10: error: PRINT: Syntax error expecting OUTFILE, ENCODING, RECORDS, TABLE, or NOTABLE.
7 | PRINT F8.2
| ^~~~"
Table: Data List
a,b
1.00,2.00
3.00,4.00
])
AT_CLEANUP
AT_SETUP([WRITE to file])
AT_DATA([write.sps], [dnl
data list notable /x y 1-2.
begin data.
12
34
6
7
90
end data.
write outfile='write.out' /x y.
write outfile='write.out' /x y (2(f1)).
write outfile='write.out' /x '-' y.
write outfile='write.out'.
execute.
])
AT_CHECK([pspp -O format=csv write.sps])
AT_CHECK([cat write.out], [0], [dnl
12
12
1-2
34
34
3-4
6
6
-6
7 @&t@
7 @&t@
7- @&t@
90
90
9-0
])
AT_CLEANUP
AT_SETUP([PRINT overwrites file])
AT_DATA([output.txt], [abcdef
])
AT_DATA([print.sps], [dnl
DATA LIST NOTABLE/x 1.
BEGIN DATA.
5
END DATA.
PRINT OUTFILE='output.txt'/x.
EXECUTE.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat output.txt], [0], [ 5 @&t@
])
AT_CLEANUP
AT_SETUP([PRINT overwrites file atomically])
AT_DATA([output.txt], [abcdef
])
AT_DATA([print.sps],
[[DATA LIST NOTABLE/x 1.
BEGIN DATA.
5
END DATA.
PRINT OUTFILE='output.txt'/x.
HOST COMMAND=['kill -TERM $PPID'].
]])
AT_CHECK([pspp -O format=csv print.sps], [143], [], [ignore])
AT_CHECK([cat output.txt], [0], [abcdef
])
AT_CHECK(
[for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
AT_CLEANUP
AT_SETUP([PRINT to same file being read])
AT_DATA([data.txt], [5
])
AT_DATA([print.sps], [dnl
DATA LIST FILE='data.txt' NOTABLE/x 1.
COMPUTE y = x + 1.
PRINT OUTFILE='data.txt'/y.
EXECUTE.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat data.txt], [0], [ 6.00 @&t@
])
AT_CHECK(
[for file in *.tmp*; do if test -e $file; then echo $file; exit 1; fi; done])
AT_CLEANUP
AT_SETUP([PRINT to special file])
AT_SKIP_IF([test ! -c /dev/null])
AT_CHECK([ln -s /dev/null foo.out || exit 77])
AT_SKIP_IF([test ! -c foo.out])
AT_DATA([print.sps], [dnl
DATA LIST NOTABLE /x 1.
BEGIN DATA.
1
2
3
4
5
END DATA.
PRINT OUTFILE='foo.out'/x.
PRINT OUTFILE='foo2.out'/x.
EXECUTE.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat foo2.out], [0], [dnl
1 @&t@
2 @&t@
3 @&t@
4 @&t@
5 @&t@
])
ls -l foo.out foo2.out
AT_CHECK([test -c foo.out])
AT_CLEANUP
AT_SETUP([PRINT with special line ends])
AT_DATA([print.sps], [dnl
FILE HANDLE lf /NAME='lf.txt' /ENDS=LF.
FILE HANDLE crlf /NAME='crlf.txt' /ENDS=CRLF.
DATA LIST NOTABLE /x 1.
BEGIN DATA.
1
2
3
4
5
END DATA.
PRINT OUTFILE=lf/x.
PRINT OUTFILE=crlf/x.
EXECUTE.
])
AT_CHECK([pspp -O format=csv print.sps])
AT_CHECK([cat lf.txt], [0], [dnl
1 @&t@
2 @&t@
3 @&t@
4 @&t@
5 @&t@
])
AT_CHECK([tr '\r' R < crlf.txt], [0], [dnl
1 R
2 R
3 R
4 R
5 R
])
AT_CLEANUP
AT_SETUP([PRINT syntax errors])
AT_DATA([print.sps], [dnl
DATA LIST LIST NOTABLE /x.
PRINT OUTFILE=**.
PRINT ENCODING=**.
PRINT RECORDS=-1.
PRINT **.
PRINT/ **.
PRINT/'string' 0.
PRINT/'string' 5-3.
PRINT/y.
PRINT/x 0.
PRINT/x (A8).
])
AT_CHECK([pspp -O format=csv print.sps], [1], [dnl
"print.sps:2.15-2.16: error: PRINT: Syntax error expecting a file name or handle name.
2 | PRINT OUTFILE=**.
| ^~"
"print.sps:3.16-3.17: error: PRINT: Syntax error expecting string.
3 | PRINT ENCODING=**.
| ^~"
"print.sps:4.15-4.16: error: PRINT: Syntax error expecting non-negative integer for RECORDS.
4 | PRINT RECORDS=-1.
| ^~"
"print.sps:5.7-5.8: error: PRINT: Syntax error expecting OUTFILE, ENCODING, RECORDS, TABLE, or NOTABLE.
5 | PRINT **.
| ^~"
"print.sps:6.8-6.9: error: PRINT: Syntax error expecting variable name.
6 | PRINT/ **.
| ^~"
"print.sps:7.16: error: PRINT: Column positions for fields must be positive.
7 | PRINT/'string' 0.
| ^"
"print.sps:8.16-8.18: error: PRINT: The ending column for a field must be greater than the starting column.
8 | PRINT/'string' 5-3.
| ^~~"
"print.sps:9.7: error: PRINT: y is not a variable name.
9 | PRINT/y.
| ^"
"print.sps:10.9: error: PRINT: Column positions for fields must be positive.
10 | PRINT/x 0.
| ^"
"print.sps:11.9-11.12: error: PRINT: Numeric variable x is not compatible with string format A8.
11 | PRINT/x (A8).
| ^~~~"
])
AT_CLEANUP
|