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],
59 [File label: My Dictionary
61 Documents in the active dataset:
65 Variable,Description,,Position
68 ,Display Alignment: Right,,
70 money,Format: DOLLAR6.2,,2
72 ,Display Alignment: Right,,
75 dump-dict.sps:5: note: SHOW: WEIGHT is money.
79 AT_SETUP([Perl writing cases to system files])
80 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
86 my $d = PSPP::Dict->new();
87 PSPP::Var->new ($d, "id",
95 PSPP::Var->new ($d, "name",
102 $d->set_documents ("This should not appear");
103 $d->clear_documents ();
104 $d->add_document ("This is a document line");
106 $d->set_label ("This is the file label");
108 # Check that we can write cases to system files.
109 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
110 my $res = $sysfile->append_case ( [34, "frederick"]);
111 die "append case" if !$res;
113 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
114 die "append case with too many variables" if $res;
117 # Check that sysfiles are closed properly automaticallly in the destructor.
118 my $sysfile2 = PSPP::Sysfile->new ("testfile2.sav", $d);
119 $res = $sysfile2->append_case ( [21, "wheelbarrow"]);
120 die "append case 2" if !$res;
122 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
123 die "append case with too many variables" if $res;
125 # Don't close. We want to test that the destructor does that.
127 AT_CHECK([RUN_PERL_MODULE test.pl])
128 AT_DATA([dump-dicts.sps],
129 [GET FILE='testfile.sav'.
135 GET FILE='testfile2.sav'.
141 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
142 [Variable,Description,,Position
145 ,Display Alignment: Right,,
149 ,Display Alignment: Left,,
152 File label: This is the file label
154 Documents in the active dataset:
156 This is a document line
162 Variable,Description,,Position
165 ,Display Alignment: Right,,
169 ,Display Alignment: Left,,
172 File label: This is the file label
174 Documents in the active dataset:
176 This is a document line
184 AT_SETUP([Perl write variable parameters])
185 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
191 my $dict = PSPP::Dict->new();
192 die "dictionary creation" if !ref $dict;
194 my $int = PSPP::Var->new ($dict, "integer",
195 (width=>8, decimals=>0) );
197 $int->set_label ("My Integer");
199 $int->add_value_label (99, "Silly");
200 $int->clear_value_labels ();
201 $int->add_value_label (0, "Zero");
202 $int->add_value_label (1, "Unity");
203 $int->add_value_label (2, "Duality");
205 my $str = PSPP::Var->new ($dict, "string",
206 (fmt=>PSPP::Fmt::A, width=>8) );
209 $str->set_label ("My String");
210 $str->add_value_label ("xx", "foo");
211 $str->add_value_label ("yy", "bar");
213 $str->set_missing_values ("this", "that");
215 my $longstr = PSPP::Var->new ($dict, "longstring",
216 (fmt=>PSPP::Fmt::A, width=>9) );
219 $longstr->set_label ("My Long String");
220 my $re = $longstr->add_value_label ("xxx", "xfoo");
222 $int->set_missing_values (9, 99);
224 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $dict);
229 AT_CHECK([RUN_PERL_MODULE test.pl])
230 AT_DATA([dump-dict.sps],
231 [GET FILE='testfile.sav'.
234 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
235 [Variable,Description,,Position
236 integer,My Integer,,1
239 ,Display Alignment: Right,,
241 ,Missing Values: 9; 99,,
248 ,Display Alignment: Left,,
250 ,"Missing Values: ""this ""; ""that """,,
253 longstring,My Long String,,3
256 ,Display Alignment: Left,,
262 AT_SETUP([Perl dictionary survives system file])
263 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
272 my $d = PSPP::Dict->new();
274 PSPP::Var->new ($d, "id",
282 $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
285 my $res = $sysfile->append_case ([3]);
286 print "Dictionary survives sysfile\n" if $res;
288 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
289 [Dictionary survives sysfile
293 m4_define([PERL_GENERATE_SYSFILE],
294 [AT_DATA([sample.sps],
295 [[data list notable list /string (a8) longstring (a12) numeric (f10) date (date11) dollar (dollar8.2) datetime (datetime17)
297 1111 One 1 1/1/1 1 1/1/1+01:01
298 2222 Two 2 2/2/2 2 2/2/2+02:02
299 3333 Three 3 3/3/3 3 3/3/3+03:03
301 5555 Five 5 5/5/5 5 5/5/5+05:05
305 variable labels string 'A Short String Variable'
306 /longstring 'A Long String Variable'
307 /numeric 'A Numeric Variable'
308 /date 'A Date Variable'
309 /dollar 'A Dollar Variable'
310 /datetime 'A Datetime Variable'.
313 missing values numeric (9, 5, 999).
315 missing values string ("3333").
318 /string '1111' 'ones' '2222' 'twos' '3333' 'threes'
319 /numeric 1 'Unity' 2 'Duality' 3 'Thripality'.
323 attribute=colour[1]('blue') colour[2]('pink') colour[3]('violet')
324 attribute=size('large') nationality('foreign').
327 save outfile='sample.sav'.
329 AT_CHECK([pspp -O format=csv sample.sps])])
331 AT_SETUP([Perl read system file])
332 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
333 PERL_GENERATE_SYSFILE
339 my $sf = PSPP::Reader->open ("sample.sav");
341 my $dict = $sf->get_dict ();
343 for (my $v = 0 ; $v < $dict->get_var_cnt() ; $v++)
345 my $var = $dict->get_var ($v);
346 my $name = $var->get_name ();
347 my $label = $var->get_label ();
349 print "Variable $v is \"$name\", label is \"$label\"\n";
351 my $vl = $var->get_value_labels ();
353 print "Value Labels:\n";
354 print "$_ => $vl->{$_}\n" for keys %$vl;
357 while (my @c = $sf->get_next_case () )
359 for (my $v = 0; $v < $dict->get_var_cnt(); $v++)
361 print "val$v: \"$c[$v]\"\n";
366 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
367 [Variable 0 is "string", label is "A Short String Variable"
372 Variable 1 is "longstring", label is "A Long String Variable"
374 Variable 2 is "numeric", label is "A Numeric Variable"
379 Variable 3 is "date", label is "A Date Variable"
381 Variable 4 is "dollar", label is "A Dollar Variable"
383 Variable 5 is "datetime", label is "A Datetime Variable"
423 AT_SETUP([Perl copying system files])
424 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
425 PERL_GENERATE_SYSFILE
431 my $input = PSPP::Reader->open ("sample.sav");
433 my $dict = $input->get_dict ();
435 my $output = PSPP::Sysfile->new ("copy.sav", $dict);
437 while (my (@c) = $input->get_next_case () )
439 $output->append_case (\@c);
444 AT_CHECK([RUN_PERL_MODULE test.pl])
445 AT_DATA([dump-dicts.sps],
446 [GET FILE='sample.sav'.
454 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
455 [[Variable,Description,,Position
456 string,A Short String Variable,,1
459 ,Display Alignment: Left,,
461 ,"Missing Values: ""3333 """,,
465 longstring,A Long String Variable,,2
468 ,Display Alignment: Left,,
470 numeric,A Numeric Variable,,3
473 ,Display Alignment: Right,,
475 ,Missing Values: 9; 5; 999,,
479 ,Custom attributes:,,
481 ,nationality,foreign,
485 date,A Date Variable,,4
488 ,Display Alignment: Right,,
490 dollar,A Dollar Variable,,5
491 ,Format: DOLLAR11.2,,
493 ,Display Alignment: Right,,
495 datetime,A Datetime Variable,,6
496 ,Format: DATETIME17.0,,
498 ,Display Alignment: Right,,
502 string,longstring,numeric,date,dollar,datetime
503 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
504 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
505 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
507 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
509 Variable,Description,,Position
510 string,A Short String Variable,,1
513 ,Display Alignment: Left,,
515 ,"Missing Values: ""3333 """,,
519 longstring,A Long String Variable,,2
522 ,Display Alignment: Left,,
524 numeric,A Numeric Variable,,3
527 ,Display Alignment: Right,,
529 ,Missing Values: 9; 5; 999,,
533 ,Custom attributes:,,
535 ,nationality,foreign,
539 date,A Date Variable,,4
542 ,Display Alignment: Right,,
544 dollar,A Dollar Variable,,5
545 ,Format: DOLLAR11.2,,
547 ,Display Alignment: Right,,
549 datetime,A Datetime Variable,,6
550 ,Format: DATETIME17.0,,
552 ,Display Alignment: Right,,
556 string,longstring,numeric,date,dollar,datetime
557 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
558 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
559 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
561 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
565 AT_SETUP([Perl value formatting])
566 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
568 [DATA LIST LIST /d (DATETIME17).
573 SAVE OUTFILE='dd.sav'.
575 AT_CHECK([pspp -O format=csv dd.sps], [0],
576 [Table: Reading free-form data from INLINE.
585 my $sf = PSPP::Reader->open ("dd.sav");
587 my $dict = $sf->get_dict ();
589 my (@c) = $sf->get_next_case ();
591 my $var = $dict->get_var (0);
593 my $formatted = PSPP::format_value ($val, $var);
594 my $str = gmtime ($val - PSPP::PERL_EPOCH);
595 print "Formatted string is \"$formatted\"\n";
596 print "Perl representation is \"$str\"\n";
598 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
599 [[Formatted string is "11-SEP-2001 08:20"
600 Perl representation is "Tue Sep 11 08:20:00 2001"
604 AT_SETUP([Perl opening nonexistent file])
605 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
611 my $sf = PSPP::Reader->open ("no-such-file.sav");
613 die "Returns undef on opening failure" if ref $sf;
614 print $PSPP::errstr, "\n";
616 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
617 [[Error opening `no-such-file.sav' for reading as a system file: No such file or directory.
619 [[Name "PSPP::errstr" used only once: possible typo at test.pl line 8.
623 AT_SETUP([Perl missing values])
624 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
625 PERL_GENERATE_SYSFILE
631 my $sf = PSPP::Reader->open ("sample.sav");
633 my $dict = $sf->get_dict ();
635 my (@c) = $sf->get_next_case ();
637 my $stringvar = $dict->get_var (0);
638 my $numericvar = $dict->get_var (2);
641 die "Missing Value Negative String"
642 if PSPP::value_is_missing ($val, $stringvar);
646 die "Missing Value Negative Num"
647 if PSPP::value_is_missing ($val, $numericvar);
649 @c = $sf->get_next_case ();
650 @c = $sf->get_next_case ();
653 die "Missing Value Positive"
654 if !PSPP::value_is_missing ($val, $stringvar);
656 @c = $sf->get_next_case ();
658 die "Missing Value Positive SYS"
659 if !PSPP::value_is_missing ($val, $numericvar);
661 @c = $sf->get_next_case ();
663 die "Missing Value Positive Num"
664 if !PSPP::value_is_missing ($val, $numericvar);
666 AT_CHECK([RUN_PERL_MODULE test.pl])
669 AT_SETUP([Perl custom attributes])
670 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
671 PERL_GENERATE_SYSFILE
677 my $sf = PSPP::Reader->open ("sample.sav");
679 my $dict = $sf->get_dict ();
681 my $var = $dict->get_var_by_name ("numeric");
683 my $attr = $var->get_attributes ();
685 foreach my $k (keys %$attr)
687 my $ll = $attr->{$k};
689 print map "$_\n", join ', ', @$ll;
692 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
693 [[colour =>blue, pink, violet
694 nationality =>foreign
699 AT_SETUP([Perl Pspp.t])
700 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
701 # Skip this test if Perl's Text::Diff module is not installed.
702 AT_CHECK([perl -MText::Diff -e '' || exit 77])
703 AT_CHECK([RUN_PERL_MODULE $abs_top_builddir/perl-module/t/Pspp.t], [0],
706 ok 2 - Dictionary Creation
708 ok 4 - Trap illegal variable name
710 ok 6 - Accept legal variable name
712 ok 8 - Trap duplicate variable name
714 ok 10 - Accept valid format
716 ok 12 - Create sysfile object
717 ok 13 - Write system file
719 ok 15 - Appending Case with too many variables
721 ok 17 - Append Case 2
724 ok 20 - Dictionary Creation 2
725 ok 21 - Value label for short string
726 ok 22 - Value label for long string
727 ok 23 - Check output 2
728 ok 24 - Dictionary survives sysfile
729 ok 25 - Basic reader operation
730 ok 26 - Streaming of files
731 Formatted string is "11-SEP-2001 08:20"
732 ok 27 - format_value function
733 ok 28 - Perl representation of time
734 ok 29 - Returns undef on opening failure
735 ok 30 - Error string on open failure
736 ok 31 - Missing Value Negative String
737 ok 32 - Missing Value Negative Num
738 ok 33 - Missing Value Positive
739 ok 34 - Missing Value Positive SYS
740 ok 35 - Missing Value Positive Num
741 ok 36 - Custom Attributes