(main): When testing mode is enabled, use a built-in output driver
[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      cd /
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53
54 activity="create program"
55 cat > $TEMPDIR/valuelabel.stat <<EOF
56 DATA LIST notable /n 1 s 2(a).
57 VALUE LABELS /n 0 'Very dissatisfied'
58                 1 'Dissatisfied'
59                 2 'Neutral'
60                 3 'Satisfied'
61                 4 'Very satisfied'.
62 VALUE LABELS /s 'a' 'Wouldn''t buy again'
63                 'b' 'Unhappy'
64                 'c' 'Bored'
65                 'd' 'Satiated'
66                 'e' 'Elated'.
67 STRING nlabel slabel(a10).
68 COMPUTE nlabel = VALUELABEL(n).
69 COMPUTE slabel = VALUELABEL(s).
70 LIST.
71 BEGIN DATA.
72
73 0a
74 1b
75 2c
76 3d
77 4e
78 5f
79 6g
80 END DATA.
81 EOF
82 if [ $? -ne 0 ] ; then no_result ; fi
83
84 activity="run program"
85 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/valuelabel.stat
86 if [ $? -ne 0 ] ; then fail ; fi
87
88 activity="compare results"
89 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
90 diff -b  $TEMPDIR/pspp.list - <<EOF
91 n s     nlabel     slabel
92 - - ---------- ----------
93 .                         
94 0 a Very dissa Wouldn't b 
95 1 b Dissatisfi Unhappy    
96 2 c Neutral    Bored      
97 3 d Satisfied  Satiated   
98 4 e Very satis Elated     
99 5 f                       
100 6 g                       
101 EOF
102 if [ $? -ne 0 ] ; then fail ; fi
103
104
105
106 pass;