2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl PSPP.t'
5 #########################
7 # change 'tests => 1' to 'tests => last_test_to_print';
9 use Test::More tests => 19;
11 use File::Temp qw/ tempfile tempdir /;
12 BEGIN { use_ok('PSPP') };
14 #########################
21 my $syntaxfile = "$tempdir/foo.sps";
23 open (FH, ">$syntaxfile");
27 system ("cd $tempdir; pspp -o raw-ascii $syntaxfile");
29 my $diff = diff ("$tempdir/pspp.list", \$result);
40 # Insert your test code below, the Test::More module is use()ed here so read
41 # its man page ( perldoc Test::More ) for help writing this test script.
44 my $d = PSPP::Dict->new();
45 ok (ref $d, "Dictionary Creation");
47 $d->set_label ("My Dictionary");
48 $d->set_documents ("These Documents");
50 # Tests for variable creation
52 my $var0 = PSPP::Var->new ($d, "le");
53 ok (!ref $var0, "Trap illegal variable name");
55 $var0 = PSPP::Var->new ($d, "legal");
56 ok (ref $var0, "Accept legal variable name");
58 my $var1 = PSPP::Var->new ($d, "legal");
59 ok (!ref $var1, "Trap duplicate variable name");
61 $var1 = PSPP::Var->new ($d, "money",
62 (fmt=>PSPP::Fmt::DOLLAR,
63 width=>4, decimals=>2) );
64 ok (ref $var1, "Accept valid format");
66 $d->set_weight ($var1);
69 # Tests for system file creation
70 # Make sure a system file can be created
72 my $tempdir = tempdir( CLEANUP => 1 );
73 my $tempfile = "$tempdir/testfile.sav";
74 my $syntaxfile = "$tempdir/syntax.sps";
75 my $sysfile = PSPP::Sysfile->new ("$tempfile", $d);
76 ok (ref $sysfile, "Create sysfile object");
79 ok (-s "$tempfile", "Write system file");
84 # Make sure we can write cases to a file
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 system files
110 my $tempdir = tempdir( CLEANUP => 1 );
111 my $tempfile = "$tempdir/testfile.sav";
112 my $sysfile = PSPP::Sysfile->new ("$tempfile", $d);
114 my $res = $sysfile->append_case ( [34, "frederick"]);
115 ok ($res, "Append Case");
117 $res = $sysfile->append_case ( [34, "frederick", "extra"]);
118 ok (!$res, "Appending Case with too many variables");
121 ok (-s "$tempfile", "existance");
124 # Check that sysfiles are closed properly
126 my $tempdir = tempdir( CLEANUP => 1 );
127 my $tempfile = "$tempdir/testfile.sav";
129 my $sysfile = PSPP::Sysfile->new ("$tempfile", $d);
131 my $res = $sysfile->append_case ( [21, "wheelbarrow"]);
132 ok ($res, "Append Case 2");
134 # Don't close. We want to test that the destructor does that
137 ok (-s "$tempfile", "existance2");
139 ok (run_pspp_syntax ($tempdir, <<SYNTAX, <<RESULT), "Check output");
141 GET FILE='$tempfile'.
148 +--------+-------------------------------------------+--------+
149 |Variable|Description |Position|
150 #========#===========================================#========#
151 |id |Format: F2.0 | 1|
152 | |Measure: Scale | |
153 | |Display Alignment: Right | |
154 | |Display Width: 8 | |
155 +--------+-------------------------------------------+--------+
156 |name |Format: A20 | 2|
157 | |Measure: Nominal | |
158 | |Display Alignment: Left | |
159 | |Display Width: 20 | |
160 +--------+-------------------------------------------+--------+
163 This is the file label
165 Documents in the active file:
167 This is a document line
170 -- --------------------
178 # Now do some tests to make sure all the variable parameters
179 # can be written properly.
182 my $tempdir = tempdir( CLEANUP => 1 );
183 my $tempfile = "$tempdir/testfile.sav";
184 my $dict = PSPP::Dict->new();
185 ok (ref $dict, "Dictionary Creation 2");
187 my $int = PSPP::Var->new ($dict, "integer",
188 (width=>8, decimals=>0) );
190 $int->set_label ("My Integer");
192 $int->add_value_label (99, "Silly");
193 $int->clear_value_labels ();
194 $int->add_value_label (0, "Zero");
195 $int->add_value_label (1, "Unity");
196 $int->add_value_label (2, "Duality");
198 my $str = PSPP::Var->new ($dict, "string",
199 (fmt=>PSPP::Fmt::A, width=>8) );
202 $str->set_label ("My String");
203 ok ($str->add_value_label ("xx", "foo"), "Value label for short string");
204 diag ($PSPP::errstr);
205 $str->add_value_label ("yy", "bar");
207 $str->set_missing_values ("this", "that");
209 my $longstr = PSPP::Var->new ($dict, "longstring",
210 (fmt=>PSPP::Fmt::A, width=>9) );
213 $longstr->set_label ("My Long String");
214 my $re = $longstr->add_value_label ("xxx", "xfoo");
215 ok (($re == 0), "Long strings cant have labels");
217 ok ($PSPP::errstr eq "Cannot add label to a long string variable", "Error msg");
219 $int->set_missing_values (9, 99);
221 my $sysfile = PSPP::Sysfile->new ("$tempfile", $dict);
226 ok (run_pspp_syntax ($tempdir, <<SYNTAX, <<RESULT), "Check output 2");
227 GET FILE='$tempfile'.
231 +----------+-----------------------------------------+--------+
232 |Variable |Description |Position|
233 #==========#=========================================#========#
234 |integer |My Integer | 1|
236 | |Measure: Scale | |
237 | |Display Alignment: Right | |
238 | |Display Width: 8 | |
239 | |Missing Values: 9; 99 | |
240 | +-----+-----------------------------------+ |
244 +----------+-----+-----------------------------------+--------+
245 |string |My String | 2|
247 | |Measure: Nominal | |
248 | |Display Alignment: Left | |
249 | |Display Width: 8 | |
250 | |Missing Values: "this "; "that " | |
251 | +-----+-----------------------------------+ |
254 +----------+-----+-----------------------------------+--------+
255 |longstring|My Long String | 3|
257 | |Measure: Nominal | |
258 | |Display Alignment: Left | |
259 | |Display Width: 9 | |
260 +----------+-----------------------------------------+--------+