3 TEMPDIR=/tmp/pspp-tst-$$
5 trap 'cd /; rm -rf $TEMPDIR' 0
7 # ensure that top_builddir are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
41 activity="write program to generate PSPP syntax and data"
42 cat > date-in.pl <<'EOF'
50 my @formats = (['date', 'd-m-y'],
58 ['datetime', 'd-m-y +H:M', 'd-m-y +H:M:S']);
60 my @dates = (#yyyy mm dd jjj HH MM SS
61 [1648, 6, 10, 162, 0, 0, 0],
62 [1680, 6, 30, 182, 4, 50, 38],
63 [1716, 7, 24, 206, 12, 31, 35],
64 [1768, 6, 19, 171, 12, 47, 53],
65 [1819, 8, 2, 214, 1, 26, 0],
66 [1839, 3, 27, 86, 20, 58, 11],
67 [1903, 4, 19, 109, 7, 36, 5],
68 [1929, 8, 25, 237, 15, 43, 49],
69 [1941, 9, 29, 272, 4, 25, 9],
70 [1943, 4, 19, 109, 6, 49, 27],
71 [1943, 10, 7, 280, 2, 57, 52],
72 [1992, 3, 17, 77, 16, 45, 44],
73 [1996, 2, 25, 56, 21, 30, 57],
74 [1941, 9, 29, 272, 4, 25, 9],
75 [1943, 4, 19, 109, 6, 49, 27],
76 [1943, 10, 7, 280, 2, 57, 52],
77 [1992, 3, 17, 77, 16, 45, 44],
78 [1996, 2, 25, 56, 21, 30, 57],
79 [2038, 11, 10, 314, 22, 30, 4],
80 [2094, 7, 18, 199, 1, 56, 51]);
82 open (SYNTAX, '>', 'date-in.pspp') or die "date-in.pspp: create: $!\n";
83 print SYNTAX "SET EPOCH 1930.\n";
84 for my $format (@formats) {
85 my ($name) = @$format;
86 print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
87 print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
88 print SYNTAX "EXECUTE.\n";
92 for my $format (@formats) {
93 my ($fmt_name, @templates) = @$format;
94 my ($fn) = "$fmt_name.data";
95 open (DATA, '>', $fn) or die "$fn: create: $!\n";
97 for my $template (@templates) {
98 for my $date (@dates) {
99 print_date_with_template ($date, $template) for 1...10;
105 sub print_date_with_template {
106 my ($date, $template) = @_;
107 my ($year, $month, $day, $julian, $hour, $minute, $second) = @$date;
108 my ($quarter) = int (($month - 1) / 3) + 1;
109 my ($week) = int (($julian - 1) / 7) + 1;
110 my (@year_types) = ('full');
111 push (@year_types, '2digit') if $year >= 1930 && $year < 2030;
112 for my $c (split ('', $template)) {
114 printf (+pick ('%d', '%02d'), $day);
115 } elsif ($c eq 'm') {
116 my ($type) = pick ('arabic', 'roman', 'abbrev', 'full');
117 if ($type eq 'arabic') {
118 printf (+pick ('%d', '%02d'), $month);
119 } elsif ($type eq 'roman') {
120 my ($mmm) = ('i', 'ii', 'iii',
123 'x', 'xi', 'xii')[$month - 1];
124 print_rand_case ($mmm);
125 } elsif ($type eq 'abbrev') {
126 my ($mmm) = qw (jan feb mar apr may jun
127 jul aug sep oct nov dec)[$month - 1];
128 print_rand_case ($mmm);
129 } elsif ($type eq 'full') {
130 my ($mmm) = qw (january february march
132 july august september
133 october november december)[$month - 1];
134 print_rand_case ($mmm);
138 } elsif ($c eq 'y') {
139 my ($type) = pick (@year_types);
140 if ($type eq '2digit') {
141 printf (+pick ('%d', '%02d'), $year % 100);
142 } elsif ($type eq 'full') {
147 } elsif ($c eq 'j') {
148 my ($type) = pick (@year_types);
149 if ($type eq '2digit') {
150 printf ("%02d%03d", $year % 100, $julian);
151 } elsif ($type eq 'full') {
152 printf ("%04d%03d", $year, $julian);
156 } elsif ($c eq 'q') {
158 } elsif ($c eq 'w') {
160 } elsif ($c eq 'H') {
161 printf (+pick ('%d', '%02d'), $hour);
162 } elsif ($c eq 'M') {
163 printf (+pick ('%d', '%02d'), $minute);
164 } elsif ($c eq 'S') {
165 printf (+pick ('%d', '%02d'), $second);
166 } elsif ($c eq '-') {
167 print +pick (' ', '-', '.', ',', '/');
168 } elsif ($c eq ':') {
169 print +pick (' ', ':');
170 } elsif ($c eq ' ') {
172 } elsif ($c eq 'Q') {
173 maybe_print_space ();
174 print_rand_case ('q');
175 maybe_print_space ();
176 } elsif ($c eq 'W') {
177 maybe_print_space ();
178 print_rand_case ('wk');
179 maybe_print_space ();
180 } elsif ($c eq '+') {
181 print +pick ('', '-', '+');
189 sub print_rand_case {
191 my ($case) = pick (qw (uc lc tc));
194 } elsif ($case eq 'lc') {
196 } elsif ($case eq 'tc') {
203 sub maybe_print_space {
204 print +pick ('', ' ');
208 return $_[int (my_rand ($#_ + 1))];
213 $next = ($next * 1103515245 + 12345) % (2**32);
214 return int ($next / 65536) % $modulo;
217 if [ $? -ne 0 ] ; then no_result ; fi
219 activity="generate PSPP syntax and data"
221 if [ $? -ne 0 ] ; then no_result ; fi
223 activity="run program"
224 $SUPERVISOR $PSPP --testing-mode date-in.pspp
225 if [ $? -ne 0 ] ; then no_result ; fi
227 activity="compare adate.out output"
228 diff -u adate.out - <<EOF
430 if [ $? -ne 0 ] ; then fail ; fi
432 activity="compare date.out output"
433 diff -u date.out - <<EOF
635 if [ $? -ne 0 ] ; then fail ; fi
637 activity="compare datetime.out output"
638 diff -u datetime.out - <<EOF
1040 if [ $? -ne 0 ] ; then fail ; fi
1042 activity="compare edate.out output"
1043 diff -u edate.out - <<EOF
1245 if [ $? -ne 0 ] ; then fail ; fi
1247 activity="compare jdate.out output"
1248 diff -u jdate.out - <<EOF
1450 if [ $? -ne 0 ] ; then fail ; fi
1452 activity="compare moyr.out output"
1453 diff -u moyr.out - <<EOF
1655 if [ $? -ne 0 ] ; then fail ; fi
1657 activity="compare qyr.out output"
1658 diff -u qyr.out - <<EOF
1860 if [ $? -ne 0 ] ; then fail ; fi
1862 activity="compare sdate.out output"
1863 diff -u sdate.out - <<EOF
2065 if [ $? -ne 0 ] ; then fail ; fi
2067 activity="compare wkyr.out output"
2068 diff -u wkyr.out - <<EOF
2270 if [ $? -ne 0 ] ; then fail ; fi