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
9 dnl XXX "libtool --mode=execute" is probably better than setting
11 m4_define([RUN_PERL_MODULE],
12 [LD_LIBRARY_PATH=$abs_top_builddir/src/.libs \
13 DYLD_LIBRARY_PATH=$abs_top_builddir/src/.libs \
14 $PERL -I$abs_top_builddir/perl-module/blib/arch \
15 -I$abs_top_builddir/perl-module/blib/lib])
17 AT_SETUP([Perl create system file])
18 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
24 my $d = PSPP::Dict->new();
25 die "dictionary creation" if !ref $d;
26 die if $d->get_var_cnt () != 0;
28 $d->set_label ("My Dictionary");
29 $d->set_documents ("These Documents");
31 # Tests for variable creation
33 my $var0 = PSPP::Var->new ($d, "le");
34 die "trap illegal variable name" if ref $var0;
35 die if $d->get_var_cnt () != 0;
37 $var0 = PSPP::Var->new ($d, "legal");
38 die "accept legal variable name" if !ref $var0;
39 die if $d->get_var_cnt () != 1;
41 my $var1 = PSPP::Var->new ($d, "money",
42 (fmt=>PSPP::Fmt::DOLLAR,
43 width=>4, decimals=>2) );
44 die "cappet valid format" if !ref $var1;
45 die if $d->get_var_cnt () != 2;
47 $d->set_weight ($var1);
49 my $sysfile = PSPP::Sysfile->new ('testfile.sav', $d);
50 die "create sysfile object" if !ref $sysfile;
54 AT_CHECK([RUN_PERL_MODULE test.pl])
55 AT_DATA([dump-dict.sps],
56 [GET FILE='testfile.sav'.
62 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
63 [File label: My Dictionary
65 Documents in the active dataset:
69 Variable,Description,,Position
72 ,Display Alignment: Right,,
74 money,Format: DOLLAR6.2,,2
76 ,Display Alignment: Right,,
79 dump-dict.sps:5: note: SHOW: WEIGHT is money.
83 AT_SETUP([Perl writing cases to system files])
84 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
90 my $d = PSPP::Dict->new();
91 PSPP::Var->new ($d, "id",
99 PSPP::Var->new ($d, "name",
106 $d->set_documents ("This should not appear");
107 $d->clear_documents ();
108 $d->add_document ("This is a document line");
110 $d->set_label ("This is the file label");
112 # Check that we can write cases to system files.
113 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
114 my $res = $sysfile->append_case ( [34, "frederick"]);
115 die "append case" if !$res;
117 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
118 die "append case with too many variables" if $res;
121 # Check that sysfiles are closed properly automaticallly in the destructor.
122 my $sysfile2 = PSPP::Sysfile->new ("testfile2.sav", $d);
123 $res = $sysfile2->append_case ( [21, "wheelbarrow"]);
124 die "append case 2" if !$res;
126 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
127 die "append case with too many variables" if $res;
129 # Don't close. We want to test that the destructor does that.
131 AT_CHECK([RUN_PERL_MODULE test.pl])
132 AT_DATA([dump-dicts.sps],
133 [GET FILE='testfile.sav'.
139 GET FILE='testfile2.sav'.
145 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
146 [Variable,Description,,Position
149 ,Display Alignment: Right,,
153 ,Display Alignment: Left,,
156 File label: This is the file label
158 Documents in the active dataset:
160 This is a document line
166 Variable,Description,,Position
169 ,Display Alignment: Right,,
173 ,Display Alignment: Left,,
176 File label: This is the file label
178 Documents in the active dataset:
180 This is a document line
188 AT_SETUP([Perl write variable parameters])
189 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
195 my $dict = PSPP::Dict->new();
196 die "dictionary creation" if !ref $dict;
198 my $int = PSPP::Var->new ($dict, "integer",
199 (width=>8, decimals=>0) );
201 $int->set_label ("My Integer");
203 $int->add_value_label (99, "Silly");
204 $int->clear_value_labels ();
205 $int->add_value_label (0, "Zero");
206 $int->add_value_label (1, "Unity");
207 $int->add_value_label (2, "Duality");
209 my $str = PSPP::Var->new ($dict, "string",
210 (fmt=>PSPP::Fmt::A, width=>8) );
213 $str->set_label ("My String");
214 $str->add_value_label ("xx", "foo");
215 $str->add_value_label ("yy", "bar");
217 $str->set_missing_values ("this", "that");
219 my $longstr = PSPP::Var->new ($dict, "longstring",
220 (fmt=>PSPP::Fmt::A, width=>9) );
223 $longstr->set_label ("My Long String");
224 my $re = $longstr->add_value_label ("xxx", "xfoo");
226 $int->set_missing_values (9, 99);
228 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $dict);
233 AT_CHECK([RUN_PERL_MODULE test.pl])
234 AT_DATA([dump-dict.sps],
235 [GET FILE='testfile.sav'.
238 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
239 [Variable,Description,,Position
240 integer,My Integer,,1
243 ,Display Alignment: Right,,
245 ,Missing Values: 9; 99,,
252 ,Display Alignment: Left,,
254 ,"Missing Values: ""this ""; ""that """,,
257 longstring,My Long String,,3
260 ,Display Alignment: Left,,
266 AT_SETUP([Perl dictionary survives system file])
267 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
276 my $d = PSPP::Dict->new();
278 PSPP::Var->new ($d, "id",
286 $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
289 my $res = $sysfile->append_case ([3]);
290 print "Dictionary survives sysfile\n" if $res;
292 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
293 [Dictionary survives sysfile
297 m4_define([PERL_GENERATE_SYSFILE],
298 [AT_DATA([sample.sps],
299 [[data list notable list /string (a8) longstring (a12) numeric (f10) date (date11) dollar (dollar8.2) datetime (datetime17)
301 1111 One 1 1/1/1 1 1/1/1+01:01
302 2222 Two 2 2/2/2 2 2/2/2+02:02
303 3333 Three 3 3/3/3 3 3/3/3+03:03
305 5555 Five 5 5/5/5 5 5/5/5+05:05
309 variable labels string 'A Short String Variable'
310 /longstring 'A Long String Variable'
311 /numeric 'A Numeric Variable'
312 /date 'A Date Variable'
313 /dollar 'A Dollar Variable'
314 /datetime 'A Datetime Variable'.
317 missing values numeric (9, 5, 999).
319 missing values string ("3333").
322 /string '1111' 'ones' '2222' 'twos' '3333' 'threes'
323 /numeric 1 'Unity' 2 'Duality' 3 'Thripality'.
327 attribute=colour[1]('blue') colour[2]('pink') colour[3]('violet')
328 attribute=size('large') nationality('foreign').
331 save outfile='sample.sav'.
333 AT_CHECK([pspp -O format=csv sample.sps])])
335 AT_SETUP([Perl read system file])
336 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
337 PERL_GENERATE_SYSFILE
343 my $sf = PSPP::Reader->open ("sample.sav");
345 my $dict = $sf->get_dict ();
347 for (my $v = 0 ; $v < $dict->get_var_cnt() ; $v++)
349 my $var = $dict->get_var ($v);
350 my $name = $var->get_name ();
351 my $label = $var->get_label ();
353 print "Variable $v is \"$name\", label is \"$label\"\n";
355 my $vl = $var->get_value_labels ();
357 print "Value Labels:\n";
358 print "$_ => $vl->{$_}\n" for keys %$vl;
361 while (my @c = $sf->get_next_case () )
363 for (my $v = 0; $v < $dict->get_var_cnt(); $v++)
365 print "val$v: \"$c[$v]\"\n";
370 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
371 [Variable 0 is "string", label is "A Short String Variable"
376 Variable 1 is "longstring", label is "A Long String Variable"
378 Variable 2 is "numeric", label is "A Numeric Variable"
383 Variable 3 is "date", label is "A Date Variable"
385 Variable 4 is "dollar", label is "A Dollar Variable"
387 Variable 5 is "datetime", label is "A Datetime Variable"
427 AT_SETUP([Perl copying system files])
428 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
429 PERL_GENERATE_SYSFILE
435 my $input = PSPP::Reader->open ("sample.sav");
437 my $dict = $input->get_dict ();
439 my $output = PSPP::Sysfile->new ("copy.sav", $dict);
441 while (my (@c) = $input->get_next_case () )
443 $output->append_case (\@c);
448 AT_CHECK([RUN_PERL_MODULE test.pl])
449 AT_DATA([dump-dicts.sps],
450 [GET FILE='sample.sav'.
458 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
459 [[Variable,Description,,Position
460 string,A Short String Variable,,1
463 ,Display Alignment: Left,,
465 ,"Missing Values: ""3333 """,,
469 longstring,A Long String Variable,,2
472 ,Display Alignment: Left,,
474 numeric,A Numeric Variable,,3
477 ,Display Alignment: Right,,
479 ,Missing Values: 9; 5; 999,,
483 ,Custom attributes:,,
485 ,nationality,foreign,
489 date,A Date Variable,,4
492 ,Display Alignment: Right,,
494 dollar,A Dollar Variable,,5
495 ,Format: DOLLAR11.2,,
497 ,Display Alignment: Right,,
499 datetime,A Datetime Variable,,6
500 ,Format: DATETIME17.0,,
502 ,Display Alignment: Right,,
506 string,longstring,numeric,date,dollar,datetime
507 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
508 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
509 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
511 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
513 Variable,Description,,Position
514 string,A Short String Variable,,1
517 ,Display Alignment: Left,,
519 ,"Missing Values: ""3333 """,,
523 longstring,A Long String Variable,,2
526 ,Display Alignment: Left,,
528 numeric,A Numeric Variable,,3
531 ,Display Alignment: Right,,
533 ,Missing Values: 9; 5; 999,,
537 ,Custom attributes:,,
539 ,nationality,foreign,
543 date,A Date Variable,,4
546 ,Display Alignment: Right,,
548 dollar,A Dollar Variable,,5
549 ,Format: DOLLAR11.2,,
551 ,Display Alignment: Right,,
553 datetime,A Datetime Variable,,6
554 ,Format: DATETIME17.0,,
556 ,Display Alignment: Right,,
560 string,longstring,numeric,date,dollar,datetime
561 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
562 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
563 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
565 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
569 AT_SETUP([Perl value formatting])
570 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
572 [DATA LIST LIST /d (DATETIME17).
577 SAVE OUTFILE='dd.sav'.
579 AT_CHECK([pspp -O format=csv dd.sps], [0],
580 [Table: Reading free-form data from INLINE.
589 my $sf = PSPP::Reader->open ("dd.sav");
591 my $dict = $sf->get_dict ();
593 my (@c) = $sf->get_next_case ();
595 my $var = $dict->get_var (0);
597 my $formatted = PSPP::format_value ($val, $var);
598 my $str = gmtime ($val - PSPP::PERL_EPOCH);
599 print "Formatted string is \"$formatted\"\n";
600 print "Perl representation is \"$str\"\n";
602 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
603 [[Formatted string is "11-SEP-2001 08:20"
604 Perl representation is "Tue Sep 11 08:20:00 2001"
608 AT_SETUP([Perl opening nonexistent file])
609 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
615 my $sf = PSPP::Reader->open ("no-such-file.sav");
617 die "Returns undef on opening failure" if ref $sf;
618 print $PSPP::errstr, "\n";
620 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
621 [[Error opening `no-such-file.sav' for reading as a system file: No such file or directory.
623 [[Name "PSPP::errstr" used only once: possible typo at test.pl line 8.
627 AT_SETUP([Perl missing values])
628 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
629 PERL_GENERATE_SYSFILE
635 my $sf = PSPP::Reader->open ("sample.sav");
637 my $dict = $sf->get_dict ();
639 my (@c) = $sf->get_next_case ();
641 my $stringvar = $dict->get_var (0);
642 my $numericvar = $dict->get_var (2);
645 die "Missing Value Negative String"
646 if PSPP::value_is_missing ($val, $stringvar);
650 die "Missing Value Negative Num"
651 if PSPP::value_is_missing ($val, $numericvar);
653 @c = $sf->get_next_case ();
654 @c = $sf->get_next_case ();
657 die "Missing Value Positive"
658 if !PSPP::value_is_missing ($val, $stringvar);
660 @c = $sf->get_next_case ();
662 die "Missing Value Positive SYS"
663 if !PSPP::value_is_missing ($val, $numericvar);
665 @c = $sf->get_next_case ();
667 die "Missing Value Positive Num"
668 if !PSPP::value_is_missing ($val, $numericvar);
670 AT_CHECK([RUN_PERL_MODULE test.pl])
673 AT_SETUP([Perl custom attributes])
674 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
675 PERL_GENERATE_SYSFILE
681 my $sf = PSPP::Reader->open ("sample.sav");
683 my $dict = $sf->get_dict ();
685 my $var = $dict->get_var_by_name ("numeric");
687 my $attr = $var->get_attributes ();
689 foreach my $k (keys %$attr)
691 my $ll = $attr->{$k};
693 print map "$_\n", join ', ', @$ll;
696 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
697 [[colour =>blue, pink, violet
698 nationality =>foreign
703 AT_SETUP([Perl Pspp.t])
704 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
705 # Skip this test if Perl's Text::Diff module is not installed.
706 AT_CHECK([perl -MText::Diff -e '' || exit 77])
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