b33fe15cb0b2d1939ccaf416f5607a02c32d438b
[pspp-builds.git] / tests / command / autorecod.sh
1 #!/bin/sh
2
3 # This program tests the autorecode command
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18 STAT_CONFIG_PATH=$top_srcdir/config
19 export STAT_CONFIG_PATH
20
21
22 cleanup()
23 {
24      cd /
25      rm -rf $TEMPDIR
26 }
27
28
29 fail()
30 {
31     echo $activity
32     echo FAILED
33     cleanup;
34     exit 1;
35 }
36
37
38 no_result()
39 {
40     echo $activity
41     echo NO RESULT;
42     cleanup;
43     exit 2;
44 }
45
46 pass()
47 {
48     cleanup;
49     exit 0;
50 }
51
52 mkdir -p $TEMPDIR
53
54 cd $TEMPDIR
55
56 activity="create program"
57 cat > $TESTFILE <<EOF
58 /* Tries AUTORECODE on some random but similar strings of characters.
59 data list /X 1-5(a) Y 7.
60 begin data.
61 lasdj 1 1                                                           3
62 asdfk 0 3 <---- These are the numbers that should be produced for a 4
63 asdfj 2 4                                                           2
64 asdfj 1 4                                                           3
65 asdfk 2 3                                                           2
66 asdfj 9 4                                                           1
67 lajks 9 2                                                           1
68 asdfk 0 3 These are the numbers that should be produced for b ----> 4
69 asdfk 1 3                                                           3
70 end data.
71
72 autorecode x y into A B/descend.
73
74 list.
75 /* Just to make sure it works on second & subsequent executions,
76 /* try it again.
77 compute Z=trunc(y/2).
78 autorecode z into W.
79 list.
80 EOF
81 if [ $? -ne 0 ] ; then no_result ; fi
82
83 activity="run program"
84 $SUPERVISOR $PSPP    -o raw-ascii $TESTFILE
85 if [ $? -ne 0 ] ; then no_result ; fi
86
87 activity="test output"
88 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
89 diff -b $TEMPDIR/pspp.list - <<EOF
90 1.1 DATA LIST.  Reading 1 record from INLINE.
91 +--------+------+-------+------+
92 |Variable|Record|Columns|Format|
93 #========#======#=======#======#
94 |X       |     1|  1-  5|A5    |
95 |Y       |     1|  7-  7|F1.0  |
96 +--------+------+-------+------+
97     X Y        A        B
98 ----- - -------- --------
99 lasdj 1     1.00     3.00 
100 asdfk 0     3.00     4.00 
101 asdfj 2     4.00     2.00 
102 asdfj 1     4.00     3.00 
103 asdfk 2     3.00     2.00 
104 asdfj 9     4.00     1.00 
105 lajks 9     2.00     1.00 
106 asdfk 0     3.00     4.00 
107 asdfk 1     3.00     3.00 
108     X Y        A        B        Z        W
109 ----- - -------- -------- -------- --------
110 lasdj 1     1.00     3.00      .00     1.00 
111 asdfk 0     3.00     4.00      .00     1.00 
112 asdfj 2     4.00     2.00     1.00     2.00 
113 asdfj 1     4.00     3.00      .00     1.00 
114 asdfk 2     3.00     2.00     1.00     2.00 
115 asdfj 9     4.00     1.00     4.00     3.00 
116 lajks 9     2.00     1.00     4.00     3.00 
117 asdfk 0     3.00     4.00      .00     1.00 
118 asdfk 1     3.00     3.00      .00     1.00 
119 EOF
120 if [ $? -ne 0 ] ; then fail ; fi
121
122 pass
123
124
125