Merge commit 'origin/stable'
[pspp-builds.git] / tests / command / attributes.sh
1 #!/bin/sh
2
3 # This program tests VARIABLE ATTRIBUTE and DATAFILE ATTRIBUTE
4 # commands, including the ability to write attributes to system files
5 # and read them back in again.
6
7 TEMPDIR=/tmp/pspp-tst-$$
8 TESTFILE=$TEMPDIR/`basename $0`.sps
9
10 # ensure that top_builddir  are absolute
11 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
12 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
13 top_builddir=`cd $top_builddir; pwd`
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 # ensure that top_srcdir is absolute
17 top_srcdir=`cd $top_srcdir; pwd`
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR" 
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61 activity="create program"
62 cat > $TESTFILE <<EOF
63 DATA LIST FREE/a b c.
64 BEGIN DATA.
65 1 2 3
66 END DATA.
67
68 DATAFILE ATTRIBUTE
69         ATTRIBUTE=key('value')
70                   array('array element 1')
71                   Array[2]('array element 2').
72 VARIABLE ATTRIBUTE
73         VARIABLES=a b
74         ATTRIBUTE=ValidationRule[2]("a + b > 2")
75                   ValidationRule[1]('a * b > 3')
76        /VARIABLES=c
77         ATTRIBUTE=QuestionWording('X or Y?').
78 DISPLAY ATTRIBUTES.
79
80 SAVE OUTFILE='attributes.sav'.
81 NEW FILE.
82 GET FILE='attributes.sav'.
83
84 DATAFILE ATTRIBUTE
85          DELETE=Array[1] Array[2].
86 VARIABLE ATTRIBUTE
87          VARIABLES=a
88          DELETE=ValidationRule
89         /VARIABLE=b
90          DELETE=validationrule[2].
91
92 DISPLAY ATTRIBUTES.
93
94 EOF
95 if [ $? -ne 0 ] ; then no_result ; fi
96
97
98 activity="run program"
99 $SUPERVISOR $PSPP --testing-mode $TESTFILE
100 if [ $? -ne 0 ] ; then no_result ; fi
101
102 activity="compare output"
103 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
104 diff -b  -w $TEMPDIR/pspp.list - << EOF
105 1.1 DISPLAY.  
106 +--------+-----------------+-----------------------------------+
107 |Variable|Description      |                                   |
108 #========#=================#===================================#
109 |a       |Custom attributes|                                   |
110 |        |ValidationRule[1]|a * b > 3                          |
111 |        |ValidationRule[2]|a + b > 2                          |
112 +--------+-----------------+-----------------------------------+
113 |b       |Custom attributes|                                   |
114 |        |ValidationRule[1]|a * b > 3                          |
115 |        |ValidationRule[2]|a + b > 2                          |
116 +--------+-----------------+-----------------------------------+
117 |c       |Custom attributes|                                   |
118 |        |QuestionWording  |X or Y?                            |
119 +--------+-----------------+-----------------------------------+
120 1.2 DISPLAY.  Custom data file attributes.
121 +---------+---------------+
122 |Attribute|Value          |
123 #=========#===============#
124 |array[1] |array element 1|
125 |array[2] |array element 2|
126 |key      |value          |
127 +---------+---------------+
128 2.1 DISPLAY.  
129 +--------+---------------+-----------------------------------+
130 |Variable|Description    |                                   |
131 #========#===============#===================================#
132 |b       |Custom attribut|s:                                 |
133 |        |ValidationRule |a * b > 3                          |
134 +--------+---------------+-----------------------------------+
135 |c       |Custom attribut|s:                                 |
136 |        |QuestionWording|X or Y?                            |
137 +--------+---------------+-----------------------------------+
138 2.2 DISPLAY.  Custom data file attributes.
139 +---------+---------------+
140 |Attribute|Value          |
141 #=========#===============#
142 |array    |array element 2|
143 |key      |value          |
144 +---------+---------------+
145 EOF
146 if [ $? -ne 0 ] ; then fail ; fi
147
148 pass;