1 AT_BANNER([Perl module tests])
3 dnl This command can be used to run with the PSPP Perl module after it has been
4 dnl built (with "make") but before it has been installed. The -I options are
5 dnl equivalent to "use ExtUtils::testlib;" inside the Perl program, but it does
6 dnl not need to be run with the perl-module build directory as the current
8 m4_define([RUN_PERL_MODULE],
9 [LD_LIBRARY_PATH=$abs_top_builddir/src/.libs \
10 $PERL -I$abs_top_builddir/perl-module/blib/arch \
11 -I$abs_top_builddir/perl-module/blib/lib])
13 AT_SETUP([Perl create system file])
14 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
20 my $d = PSPP::Dict->new();
21 die "dictionary creation" if !ref $d;
22 die if $d->get_var_cnt () != 0;
24 $d->set_label ("My Dictionary");
25 $d->set_documents ("These Documents");
27 # Tests for variable creation
29 my $var0 = PSPP::Var->new ($d, "le");
30 die "trap illegal variable name" if ref $var0;
31 die if $d->get_var_cnt () != 0;
33 $var0 = PSPP::Var->new ($d, "legal");
34 die "accept legal variable name" if !ref $var0;
35 die if $d->get_var_cnt () != 1;
37 my $var1 = PSPP::Var->new ($d, "money",
38 (fmt=>PSPP::Fmt::DOLLAR,
39 width=>4, decimals=>2) );
40 die "cappet valid format" if !ref $var1;
41 die if $d->get_var_cnt () != 2;
43 $d->set_weight ($var1);
45 my $sysfile = PSPP::Sysfile->new ('testfile.sav', $d);
46 die "create sysfile object" if !ref $sysfile;
50 AT_CHECK([RUN_PERL_MODULE test.pl])
51 AT_DATA([dump-dict.sps],
52 [GET FILE='testfile.sav'.
58 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
63 Documents in the active file:
67 Variable,Description,,Position
70 ,Display Alignment: Right,,
72 money,Format: DOLLAR6.2,,2
74 ,Display Alignment: Right,,
77 dump-dict.sps:5: note: SHOW: WEIGHT is money.
81 AT_SETUP([Perl writing cases to system files])
82 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
88 my $d = PSPP::Dict->new();
89 PSPP::Var->new ($d, "id",
97 PSPP::Var->new ($d, "name",
104 $d->set_documents ("This should not appear");
105 $d->clear_documents ();
106 $d->add_document ("This is a document line");
108 $d->set_label ("This is the file label");
110 # Check that we can write cases to system files.
111 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
112 my $res = $sysfile->append_case ( [34, "frederick"]);
113 die "append case" if !$res;
115 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
116 die "append case with too many variables" if $res;
119 # Check that sysfiles are closed properly automaticallly in the destructor.
120 my $sysfile2 = PSPP::Sysfile->new ("testfile2.sav", $d);
121 $res = $sysfile2->append_case ( [21, "wheelbarrow"]);
122 die "append case 2" if !$res;
124 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
125 die "append case with too many variables" if $res;
127 # Don't close. We want to test that the destructor does that.
129 AT_CHECK([RUN_PERL_MODULE test.pl])
130 AT_DATA([dump-dicts.sps],
131 [GET FILE='testfile.sav'.
137 GET FILE='testfile2.sav'.
143 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
144 [Variable,Description,,Position
147 ,Display Alignment: Right,,
151 ,Display Alignment: Left,,
156 This is the file label
158 Documents in the active file:
160 This is a document line
166 Variable,Description,,Position
169 ,Display Alignment: Right,,
173 ,Display Alignment: Left,,
178 This is the file label
180 Documents in the active file:
182 This is a document line
190 AT_SETUP([Perl write variable parameters])
191 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
197 my $dict = PSPP::Dict->new();
198 die "dictionary creation" if !ref $dict;
200 my $int = PSPP::Var->new ($dict, "integer",
201 (width=>8, decimals=>0) );
203 $int->set_label ("My Integer");
205 $int->add_value_label (99, "Silly");
206 $int->clear_value_labels ();
207 $int->add_value_label (0, "Zero");
208 $int->add_value_label (1, "Unity");
209 $int->add_value_label (2, "Duality");
211 my $str = PSPP::Var->new ($dict, "string",
212 (fmt=>PSPP::Fmt::A, width=>8) );
215 $str->set_label ("My String");
216 $str->add_value_label ("xx", "foo");
217 $str->add_value_label ("yy", "bar");
219 $str->set_missing_values ("this", "that");
221 my $longstr = PSPP::Var->new ($dict, "longstring",
222 (fmt=>PSPP::Fmt::A, width=>9) );
225 $longstr->set_label ("My Long String");
226 my $re = $longstr->add_value_label ("xxx", "xfoo");
228 $int->set_missing_values (9, 99);
230 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $dict);
235 AT_CHECK([RUN_PERL_MODULE test.pl])
236 AT_DATA([dump-dict.sps],
237 [GET FILE='testfile.sav'.
240 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
241 [Variable,Description,,Position
242 integer,My Integer,,1
245 ,Display Alignment: Right,,
247 ,Missing Values: 9; 99,,
254 ,Display Alignment: Left,,
256 ,"Missing Values: ""this ""; ""that """,,
259 longstring,My Long String,,3
262 ,Display Alignment: Left,,
268 AT_SETUP([Perl dictionary survives system file])
269 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
278 my $d = PSPP::Dict->new();
280 PSPP::Var->new ($d, "id",
288 $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
291 my $res = $sysfile->append_case ([3]);
292 print "Dictionary survives sysfile\n" if $res;
294 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
295 [Dictionary survives sysfile
299 m4_define([PERL_GENERATE_SYSFILE],
300 [AT_DATA([sample.sps],
301 [[data list notable list /string (a8) longstring (a12) numeric (f10) date (date11) dollar (dollar8.2) datetime (datetime17)
303 1111 One 1 1/1/1 1 1/1/1+01:01
304 2222 Two 2 2/2/2 2 2/2/2+02:02
305 3333 Three 3 3/3/3 3 3/3/3+03:03
307 5555 Five 5 5/5/5 5 5/5/5+05:05
311 variable labels string 'A Short String Variable'
312 /longstring 'A Long String Variable'
313 /numeric 'A Numeric Variable'
314 /date 'A Date Variable'
315 /dollar 'A Dollar Variable'
316 /datetime 'A Datetime Variable'.
319 missing values numeric (9, 5, 999).
321 missing values string ("3333").
324 /string '1111' 'ones' '2222' 'twos' '3333' 'threes'
325 /numeric 1 'Unity' 2 'Duality' 3 'Thripality'.
329 attribute=colour[1]('blue') colour[2]('pink') colour[3]('violet')
330 attribute=size('large') nationality('foreign').
333 save outfile='sample.sav'.
335 AT_CHECK([pspp -O format=csv sample.sps])])
337 AT_SETUP([Perl read system file])
338 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
339 PERL_GENERATE_SYSFILE
345 my $sf = PSPP::Reader->open ("sample.sav");
347 my $dict = $sf->get_dict ();
349 for (my $v = 0 ; $v < $dict->get_var_cnt() ; $v++)
351 my $var = $dict->get_var ($v);
352 my $name = $var->get_name ();
353 my $label = $var->get_label ();
355 print "Variable $v is \"$name\", label is \"$label\"\n";
357 my $vl = $var->get_value_labels ();
359 print "Value Labels:\n";
360 print "$_ => $vl->{$_}\n" for keys %$vl;
363 while (my @c = $sf->get_next_case () )
365 for (my $v = 0; $v < $dict->get_var_cnt(); $v++)
367 print "val$v: \"$c[$v]\"\n";
372 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
373 [Variable 0 is "string", label is "A Short String Variable"
378 Variable 1 is "longstring", label is "A Long String Variable"
380 Variable 2 is "numeric", label is "A Numeric Variable"
385 Variable 3 is "date", label is "A Date Variable"
387 Variable 4 is "dollar", label is "A Dollar Variable"
389 Variable 5 is "datetime", label is "A Datetime Variable"
429 AT_SETUP([Perl copying system files])
430 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
431 PERL_GENERATE_SYSFILE
437 my $input = PSPP::Reader->open ("sample.sav");
439 my $dict = $input->get_dict ();
441 my $output = PSPP::Sysfile->new ("copy.sav", $dict);
443 while (my (@c) = $input->get_next_case () )
445 $output->append_case (\@c);
450 AT_CHECK([RUN_PERL_MODULE test.pl])
451 AT_DATA([dump-dicts.sps],
452 [GET FILE='sample.sav'.
460 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
461 [[Variable,Description,,Position
462 string,A Short String Variable,,1
465 ,Display Alignment: Left,,
467 ,"Missing Values: ""3333 """,,
471 longstring,A Long String Variable,,2
474 ,Display Alignment: Left,,
476 numeric,A Numeric Variable,,3
479 ,Display Alignment: Right,,
481 ,Missing Values: 9; 5; 999,,
485 ,Custom attributes:,,
487 ,nationality,foreign,
491 date,A Date Variable,,4
494 ,Display Alignment: Right,,
496 dollar,A Dollar Variable,,5
497 ,Format: DOLLAR11.2,,
499 ,Display Alignment: Right,,
501 datetime,A Datetime Variable,,6
502 ,Format: DATETIME17.0,,
504 ,Display Alignment: Right,,
508 string,longstring,numeric,date,dollar,datetime
509 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
510 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
511 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
513 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
515 Variable,Description,,Position
516 string,A Short String Variable,,1
519 ,Display Alignment: Left,,
521 ,"Missing Values: ""3333 """,,
525 longstring,A Long String Variable,,2
528 ,Display Alignment: Left,,
530 numeric,A Numeric Variable,,3
533 ,Display Alignment: Right,,
535 ,Missing Values: 9; 5; 999,,
539 ,Custom attributes:,,
541 ,nationality,foreign,
545 date,A Date Variable,,4
548 ,Display Alignment: Right,,
550 dollar,A Dollar Variable,,5
551 ,Format: DOLLAR11.2,,
553 ,Display Alignment: Right,,
555 datetime,A Datetime Variable,,6
556 ,Format: DATETIME17.0,,
558 ,Display Alignment: Right,,
562 string,longstring,numeric,date,dollar,datetime
563 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
564 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
565 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
567 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
571 AT_SETUP([Perl value formatting])
572 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
574 [DATA LIST LIST /d (DATETIME17).
579 SAVE OUTFILE='dd.sav'.
581 AT_CHECK([pspp -O format=csv dd.sps], [0],
582 [Table: Reading free-form data from INLINE.
591 my $sf = PSPP::Reader->open ("dd.sav");
593 my $dict = $sf->get_dict ();
595 my (@c) = $sf->get_next_case ();
597 my $var = $dict->get_var (0);
599 my $formatted = PSPP::format_value ($val, $var);
600 my $str = gmtime ($val - PSPP::PERL_EPOCH);
601 print "Formatted string is \"$formatted\"\n";
602 print "Perl representation is \"$str\"\n";
604 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
605 [[Formatted string is "11-SEP-2001 08:20"
606 Perl representation is "Tue Sep 11 08:20:00 2001"
610 AT_SETUP([Perl opening nonexistent file])
611 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
617 my $sf = PSPP::Reader->open ("no-such-file.sav");
619 die "Returns undef on opening failure" if ref $sf;
620 print $PSPP::errstr, "\n";
622 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
623 [[Error opening `no-such-file.sav' for reading as a system file: No such file or directory.
625 [[Name "PSPP::errstr" used only once: possible typo at test.pl line 8.
629 AT_SETUP([Perl missing values])
630 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
631 PERL_GENERATE_SYSFILE
637 my $sf = PSPP::Reader->open ("sample.sav");
639 my $dict = $sf->get_dict ();
641 my (@c) = $sf->get_next_case ();
643 my $stringvar = $dict->get_var (0);
644 my $numericvar = $dict->get_var (2);
647 die "Missing Value Negative String"
648 if PSPP::value_is_missing ($val, $stringvar);
652 die "Missing Value Negative Num"
653 if PSPP::value_is_missing ($val, $numericvar);
655 @c = $sf->get_next_case ();
656 @c = $sf->get_next_case ();
659 die "Missing Value Positive"
660 if !PSPP::value_is_missing ($val, $stringvar);
662 @c = $sf->get_next_case ();
664 die "Missing Value Positive SYS"
665 if !PSPP::value_is_missing ($val, $numericvar);
667 @c = $sf->get_next_case ();
669 die "Missing Value Positive Num"
670 if !PSPP::value_is_missing ($val, $numericvar);
672 AT_CHECK([RUN_PERL_MODULE test.pl])
675 AT_SETUP([Perl custom attributes])
676 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
677 PERL_GENERATE_SYSFILE
683 my $sf = PSPP::Reader->open ("sample.sav");
685 my $dict = $sf->get_dict ();
687 my $var = $dict->get_var_by_name ("numeric");
689 my $attr = $var->get_attributes ();
691 foreach my $k (keys %$attr)
693 my $ll = $attr->{$k};
695 print map "$_\n", join ', ', @$ll;
698 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
699 [[colour =>blue, pink, violet
700 nationality =>foreign
705 AT_SETUP([Perl Pspp.t])
706 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
707 AT_CHECK([RUN_PERL_MODULE $abs_top_builddir/perl-module/t/Pspp.t], [0],
710 ok 2 - Dictionary Creation
712 ok 4 - Trap illegal variable name
714 ok 6 - Accept legal variable name
716 ok 8 - Trap duplicate variable name
718 ok 10 - Accept valid format
720 ok 12 - Create sysfile object
721 ok 13 - Write system file
723 ok 15 - Appending Case with too many variables
725 ok 17 - Append Case 2
728 ok 20 - Dictionary Creation 2
729 ok 21 - Value label for short string
730 ok 22 - Value label for long string
731 ok 23 - Check output 2
732 ok 24 - Dictionary survives sysfile
733 ok 25 - Basic reader operation
734 ok 26 - Streaming of files
735 Formatted string is "11-SEP-2001 08:20"
736 ok 27 - format_value function
737 ok 28 - Perl representation of time
738 ok 29 - Returns undef on opening failure
739 ok 30 - Error string on open failure
740 ok 31 - Missing Value Negative String
741 ok 32 - Missing Value Negative Num
742 ok 33 - Missing Value Positive
743 ok 34 - Missing Value Positive SYS
744 ok 35 - Missing Value Positive Num
745 ok 36 - Custom Attributes