--- /dev/null
+AT_BANNER([SORT VARIABLES])
+
+AT_SETUP([SORT VARIABLES])
+# This reverses the order of its input lines.
+# From the GNU sed manual.
+tac () {
+ sed -n '1! G
+$ p
+h'
+}
+
+test_sort () {
+ cat > sort-variables.sps <<EOF
+DATA LIST FREE/$1.
+$2
+SORT VARIABLES $3.
+DISPLAY NAMES.
+SORT VARIABLES $3(D).
+DISPLAY NAMES.
+EOF
+ AT_CHECK_UNQUOTED([pspp -O format=csv sort-variables.sps], [0],
+[Variable
+`for var in $4; do echo $var; done`
+
+Variable
+`for var in $4; do echo $var; done | tac`
+])
+}
+
+test_sort 'x100 c b x99 a y400 y5' '' NAME 'a b c x99 x100 y5 y400'
+test_sort 'c(a10) a(a5) b' '' TYPE 'b a c'
+test_sort 'a (datetime) b (f) c (a5) d (a2) e (a1)' '' FORMAT 'e d c b a'
+test_sort 'a b c' \
+ 'VARIABLE LABEL a "hi there".' \
+ LABEL 'b c a'
+test_sort 'a b c' \
+ 'VALUE LABELS a 123 "xyzzy".' \
+ VALUES 'b c a'
+test_sort 'a b c' \
+ 'MISSING VALUES a (123).' \
+ MISSING 'b c a'
+test_sort 'a b c' \
+ 'VARIABLE LEVEL a (SCALE) b (ORDINAL) c (NOMINAL).' \
+ MEASURE 'c b a'
+test_sort 'b n i s t p' \
+ 'VARIABLE ROLE /INPUT i /TARGET t /BOTH b /NONE n /PARTITION p /SPLIT s.' \
+ ROLE 'i t b n p s'
+test_sort 'c10 c5 c15 c9' \
+ 'VARIABLE WIDTH c10(10) c5(5) c15(15) c9(9).' \
+ COLUMNS 'c5 c9 c10 c15'
+test_sort 'c l r' \
+ 'VARIABLE ALIGNMENT c (CENTER) l (LEFT) r (RIGHT).' \
+ ALIGNMENT 'l r c'
+test_sort 'az ax ay ab' \
+ 'VARIABLE ATTRIBUTE VARIABLES=az ATTRIBUTE=key("z").
+ VARIABLE ATTRIBUTE VARIABLES=ax ATTRIBUTE=key("x").
+ VARIABLE ATTRIBUTE VARIABLES=ay ATTRIBUTE=key("y").
+ VARIABLE ATTRIBUTE VARIABLES=ab ATTRIBUTE=key("b").' \
+ 'ATTRIBUTE key' 'ab ax ay az'
+AT_CLEANUP