Rewrite PSPP output engine.
[pspp-builds.git] / tests / expressions / valuelabel.sh
1 #!/bin/sh
2
3 # This program tests use of the VALUELABEL function in expressions.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6
7 # ensure that top_srcdir and top_builddir  are absolute
8 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 top_srcdir=`cd $top_srcdir; pwd`
11 top_builddir=`cd $top_builddir; pwd`
12 PSPP=$top_builddir/src/ui/terminal/pspp
13
14 STAT_CONFIG_PATH=$top_srcdir/config
15 export STAT_CONFIG_PATH
16
17 LANG=C
18 export LANG
19
20 cleanup()
21 {
22      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
23         echo "NOT cleaning $TEMPDIR" 
24         return ; 
25      fi
26      cd /
27      rm -rf $TEMPDIR
28 }
29
30
31 fail()
32 {
33     echo $activity
34     echo FAILED
35     cleanup;
36     exit 1;
37 }
38
39
40 no_result()
41 {
42     echo $activity
43     echo NO RESULT;
44     cleanup;
45     exit 2;
46 }
47
48 pass()
49 {
50     cleanup;
51     exit 0;
52 }
53
54 mkdir -p $TEMPDIR
55
56 cd $TEMPDIR
57
58 activity="create program"
59 cat > $TEMPDIR/valuelabel.stat <<EOF
60 DATA LIST notable /n 1 s 2(a).
61 VALUE LABELS /n 0 'Very dissatisfied'
62                 1 'Dissatisfied'
63                 1.5 'Slightly Peeved'
64                 2 'Neutral'
65                 3 'Satisfied'
66                 4 'Very satisfied'.
67 VALUE LABELS /s 'a' 'Wouldn''t buy again'
68                 'b' 'Unhappy'
69                 'c' 'Bored'
70                 'd' 'Satiated'
71                 'e' 'Elated'.
72 STRING nlabel slabel(a10).
73 COMPUTE nlabel = VALUELABEL(n).
74 COMPUTE slabel = VALUELABEL(s).
75 LIST.
76 BEGIN DATA.
77
78 0a
79 1b
80 2c
81 3d
82 4e
83 5f
84 6g
85 END DATA.
86
87 EOF
88 if [ $? -ne 0 ] ; then no_result ; fi
89
90 activity="run program"
91 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/valuelabel.stat
92 if [ $? -ne 0 ] ; then fail ; fi
93
94 activity="compare results"
95 diff -c $TEMPDIR/pspp.csv - <<EOF
96 Table: Data List
97 n,s,nlabel,slabel
98 .,,,
99 0,a,Very dissa,Wouldn't b
100 1,b,Dissatisfi,Unhappy   
101 2,c,Neutral   ,Bored     
102 3,d,Satisfied ,Satiated  
103 4,e,Very satis,Elated    
104 5,f,,
105 6,g,,
106 EOF
107 if [ $? -ne 0 ] ; then fail ; fi
108
109
110
111 pass;