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
71 money,Format: DOLLAR6.2,2
73 dump-dict.sps:5: note: SHOW: WEIGHT is money.
77 AT_SETUP([Perl writing cases to system files])
78 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
84 my $d = PSPP::Dict->new();
85 PSPP::Var->new ($d, "id",
93 PSPP::Var->new ($d, "name",
100 $d->set_documents ("This should not appear");
101 $d->clear_documents ();
102 $d->add_document ("This is a document line");
104 $d->set_label ("This is the file label");
106 # Check that we can write cases to system files.
107 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
108 my $res = $sysfile->append_case ( [34, "frederick"]);
109 die "append case" if !$res;
111 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
112 die "append case with too many variables" if $res;
115 # Check that sysfiles are closed properly automaticallly in the destructor.
116 my $sysfile2 = PSPP::Sysfile->new ("testfile2.sav", $d);
117 $res = $sysfile2->append_case ( [21, "wheelbarrow"]);
118 die "append case 2" if !$res;
120 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
121 die "append case with too many variables" if $res;
123 # Don't close. We want to test that the destructor does that.
125 AT_CHECK([RUN_PERL_MODULE test.pl])
126 AT_DATA([dump-dicts.sps],
127 [GET FILE='testfile.sav'.
133 GET FILE='testfile2.sav'.
139 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
140 [Variable,Description,Position
144 File label: This is the file label
146 Documents in the active dataset:
148 This is a document line
154 Variable,Description,Position
158 File label: This is the file label
160 Documents in the active dataset:
162 This is a document line
170 AT_SETUP([Perl write variable parameters])
171 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
177 my $dict = PSPP::Dict->new();
178 die "dictionary creation" if !ref $dict;
180 my $int = PSPP::Var->new ($dict, "integer",
181 (width=>8, decimals=>0) );
183 $int->set_label ("My Integer");
185 $int->add_value_label (99, "Silly");
186 $int->clear_value_labels ();
187 $int->add_value_label (0, "Zero");
188 $int->add_value_label (1, "Unity");
189 $int->add_value_label (2, "Duality");
191 my $str = PSPP::Var->new ($dict, "string",
192 (fmt=>PSPP::Fmt::A, width=>8) );
195 $str->set_label ("My String");
196 $str->add_value_label ("xx", "foo");
197 $str->add_value_label ("yy", "bar");
199 $str->set_missing_values ("this", "that");
201 my $longstr = PSPP::Var->new ($dict, "longstring",
202 (fmt=>PSPP::Fmt::A, width=>9) );
205 $longstr->set_label ("My Long String");
206 my $re = $longstr->add_value_label ("xxx", "xfoo");
208 $int->set_missing_values (9, 99);
210 my $sysfile = PSPP::Sysfile->new ("testfile.sav", $dict);
215 AT_CHECK([RUN_PERL_MODULE test.pl])
216 AT_DATA([dump-dict.sps],
217 [GET FILE='testfile.sav'.
220 AT_CHECK([pspp -O format=csv dump-dict.sps], [0],
221 [Variable,Description,Position
222 integer,"Label: My Integer
224 Missing Values: 9; 99
230 string,"Label: My String
232 Missing Values: ""this ""; ""that ""
237 longstring,"Label: My Long String
245 AT_SETUP([Perl dictionary survives system file])
246 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
255 my $d = PSPP::Dict->new();
257 PSPP::Var->new ($d, "id",
265 $sysfile = PSPP::Sysfile->new ("testfile.sav", $d);
268 my $res = $sysfile->append_case ([3]);
269 print "Dictionary survives sysfile\n" if $res;
271 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
272 [Dictionary survives sysfile
276 m4_define([PERL_GENERATE_SYSFILE],
277 [AT_DATA([sample.sps],
278 [[data list notable list /string (a8) longstring (a12) numeric (f10) date (date11) dollar (dollar8.2) datetime (datetime17)
280 1111 One 1 1/1/1 1 1/1/1+01:01
281 2222 Two 2 2/2/2 2 2/2/2+02:02
282 3333 Three 3 3/3/3 3 3/3/3+03:03
284 5555 Five 5 5/5/5 5 5/5/5+05:05
288 variable labels string 'A Short String Variable'
289 /longstring 'A Long String Variable'
290 /numeric 'A Numeric Variable'
291 /date 'A Date Variable'
292 /dollar 'A Dollar Variable'
293 /datetime 'A Datetime Variable'.
296 missing values numeric (9, 5, 999).
298 missing values string ("3333").
301 /string '1111' 'ones' '2222' 'twos' '3333' 'threes'
302 /numeric 1 'Unity' 2 'Duality' 3 'Thripality'.
306 attribute=colour[1]('blue') colour[2]('pink') colour[3]('violet')
307 attribute=size('large') nationality('foreign').
310 save outfile='sample.sav'.
312 AT_CHECK([pspp -O format=csv sample.sps])])
314 AT_SETUP([Perl read system file])
315 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
316 PERL_GENERATE_SYSFILE
322 my $sf = PSPP::Reader->open ("sample.sav");
324 my $dict = $sf->get_dict ();
326 for (my $v = 0 ; $v < $dict->get_var_cnt() ; $v++)
328 my $var = $dict->get_var ($v);
329 my $name = $var->get_name ();
330 my $label = $var->get_label ();
332 print "Variable $v is \"$name\", label is \"$label\"\n";
334 my $vl = $var->get_value_labels ();
336 print "Value Labels:\n";
337 print "$_ => $vl->{$_}\n" for sort (keys %$vl);
340 while (my @c = $sf->get_next_case () )
342 for (my $v = 0; $v < $dict->get_var_cnt(); $v++)
344 print "val$v: \"$c[$v]\"\n";
349 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
350 [Variable 0 is "string", label is "A Short String Variable"
355 Variable 1 is "longstring", label is "A Long String Variable"
357 Variable 2 is "numeric", label is "A Numeric Variable"
362 Variable 3 is "date", label is "A Date Variable"
364 Variable 4 is "dollar", label is "A Dollar Variable"
366 Variable 5 is "datetime", label is "A Datetime Variable"
406 AT_SETUP([Perl copying system files])
407 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
408 PERL_GENERATE_SYSFILE
414 my $input = PSPP::Reader->open ("sample.sav");
416 my $dict = $input->get_dict ();
418 my $output = PSPP::Sysfile->new ("copy.sav", $dict);
420 while (my (@c) = $input->get_next_case () )
422 $output->append_case (\@c);
427 AT_CHECK([RUN_PERL_MODULE test.pl])
428 AT_DATA([dump-dicts.sps],
429 [GET FILE='sample.sav'.
437 AT_CHECK([pspp -O format=csv dump-dicts.sps], [0],
438 [[Variable,Description,Position
439 string,"Label: A Short String Variable
441 Missing Values: ""3333 ""
447 longstring,"Label: A Long String Variable
449 numeric,"Label: A Numeric Variable
451 Missing Values: 9; 5; 999
464 date,"Label: A Date Variable
466 dollar,"Label: A Dollar Variable
467 Format: DOLLAR11.2",5
468 datetime,"Label: A Datetime Variable
469 Format: DATETIME17.0",6
472 string,longstring,numeric,date,dollar,datetime
473 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
474 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
475 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
477 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
479 Variable,Description,Position
480 string,"Label: A Short String Variable
482 Missing Values: ""3333 ""
488 longstring,"Label: A Long String Variable
490 numeric,"Label: A Numeric Variable
492 Missing Values: 9; 5; 999
505 date,"Label: A Date Variable
507 dollar,"Label: A Dollar Variable
508 Format: DOLLAR11.2",5
509 datetime,"Label: A Datetime Variable
510 Format: DATETIME17.0",6
513 string,longstring,numeric,date,dollar,datetime
514 1111 ,One ,1,01-JAN-2001,$1.00,01-JAN-2001 01:01
515 2222 ,Two ,2,02-FEB-2002,$2.00,02-FEB-2002 02:02
516 3333 ,Three ,3,03-MAR-2003,$3.00,03-MAR-2003 03:03
518 5555 ,Five ,5,05-MAY-2005,$5.00,05-MAY-2005 05:05
522 AT_SETUP([Perl value formatting])
523 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
525 [DATA LIST LIST /d (DATETIME17).
530 SAVE OUTFILE='dd.sav'.
532 AT_CHECK([pspp -O format=csv dd.sps], [0],
533 [Table: Reading free-form data from INLINE.
542 my $sf = PSPP::Reader->open ("dd.sav");
544 my $dict = $sf->get_dict ();
546 my (@c) = $sf->get_next_case ();
548 my $var = $dict->get_var (0);
550 my $formatted = PSPP::format_value ($val, $var);
551 my $str = gmtime ($val - PSPP::PERL_EPOCH);
552 print "Formatted string is \"$formatted\"\n";
553 print "Perl representation is \"$str\"\n";
555 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
556 [[Formatted string is "11-SEP-2001 08:20"
557 Perl representation is "Tue Sep 11 08:20:00 2001"
561 AT_SETUP([Perl opening nonexistent file])
562 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
568 my $sf = PSPP::Reader->open ("no-such-file.sav");
570 die "Returns undef on opening failure" if ref $sf;
571 print $PSPP::errstr, "\n";
573 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
574 [[An error occurred while opening `no-such-file.sav': No such file or directory.
576 [[Name "PSPP::errstr" used only once: possible typo at test.pl line 8.
580 AT_SETUP([Perl missing values])
581 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
582 PERL_GENERATE_SYSFILE
588 my $sf = PSPP::Reader->open ("sample.sav");
590 my $dict = $sf->get_dict ();
592 my (@c) = $sf->get_next_case ();
594 my $stringvar = $dict->get_var (0);
595 my $numericvar = $dict->get_var (2);
598 die "Missing Value Negative String"
599 if PSPP::value_is_missing ($val, $stringvar);
603 die "Missing Value Negative Num"
604 if PSPP::value_is_missing ($val, $numericvar);
606 @c = $sf->get_next_case ();
607 @c = $sf->get_next_case ();
610 die "Missing Value Positive"
611 if !PSPP::value_is_missing ($val, $stringvar);
613 @c = $sf->get_next_case ();
615 die "Missing Value Positive SYS"
616 if !PSPP::value_is_missing ($val, $numericvar);
618 @c = $sf->get_next_case ();
620 die "Missing Value Positive Num"
621 if !PSPP::value_is_missing ($val, $numericvar);
623 AT_CHECK([RUN_PERL_MODULE test.pl])
626 AT_SETUP([Perl custom attributes])
627 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
628 PERL_GENERATE_SYSFILE
634 my $sf = PSPP::Reader->open ("sample.sav");
636 my $dict = $sf->get_dict ();
638 my $var = $dict->get_var_by_name ("numeric");
640 my $attr = $var->get_attributes ();
642 foreach my $k (sort (keys (%$attr)))
644 my $ll = $attr->{$k};
646 print map "$_\n", join ', ', @$ll;
649 AT_CHECK([RUN_PERL_MODULE test.pl], [0],
651 colour =>blue, pink, violet
652 nationality =>foreign
657 AT_SETUP([Perl Pspp.t])
658 AT_SKIP_IF([test "$WITH_PERL_MODULE" = no])
659 # Skip this test if Perl's Text::Diff module is not installed.
660 AT_CHECK([perl -MText::Diff -e '' || exit 77])
661 AT_CHECK([RUN_PERL_MODULE $abs_top_builddir/perl-module/t/Pspp.t], [0],
664 ok 2 - Dictionary Creation
666 ok 4 - Trap illegal variable name
668 ok 6 - Accept legal variable name
670 ok 8 - Trap duplicate variable name
672 ok 10 - Accept valid format
674 ok 12 - Create sysfile object
675 ok 13 - Write system file
677 ok 15 - Appending Case with too many variables
679 ok 17 - Append Case 2
682 ok 20 - Dictionary Creation 2
683 ok 21 - Value label for short string
684 ok 22 - Value label for long string
685 ok 23 - Check output 2
686 ok 24 - Dictionary survives sysfile
687 ok 25 - Basic reader operation
688 ok 26 - Streaming of files
689 Formatted string is "11-SEP-2001 08:20"
690 ok 27 - format_value function
691 ok 28 - Perl representation of time
692 ok 29 - Returns undef on opening failure
693 ok 30 - Error string on open failure
694 ok 31 - Missing Value Negative String
695 ok 32 - Missing Value Negative Num
696 ok 33 - Missing Value Positive
697 ok 34 - Missing Value Positive SYS
698 ok 35 - Missing Value Positive Num
699 ok 36 - Custom Attributes