##// END OF EJS Templates
tests: fix portability issue for echo -n
TK Soh -
r1952:f4df34b6 default
parent child Browse files
Show More
@@ -1,153 +1,159
1 #!/bin/sh -e
1 #!/bin/sh -e
2
2
3 LANG="C"; export LANG
3 LANG="C"; export LANG
4 LC_CTYPE="C"; export LC_CTYPE
4 LC_CTYPE="C"; export LC_CTYPE
5 LC_NUMERIC="C"; export LC_NUMERIC
5 LC_NUMERIC="C"; export LC_NUMERIC
6 LC_TIME="C"; export LC_TIME
6 LC_TIME="C"; export LC_TIME
7 LC_COLLATE="C"; export LC_COLLATE
7 LC_COLLATE="C"; export LC_COLLATE
8 LC_MONETARY="C"; export LC_MONETARY
8 LC_MONETARY="C"; export LC_MONETARY
9 LC_MESSAGES="C"; export LC_MESSAGES
9 LC_MESSAGES="C"; export LC_MESSAGES
10 LC_PAPER="C"; export LC_PAPER
10 LC_PAPER="C"; export LC_PAPER
11 LC_NAME="C"; export LC_NAME
11 LC_NAME="C"; export LC_NAME
12 LC_ADDRESS="C"; export LC_ADDRESS
12 LC_ADDRESS="C"; export LC_ADDRESS
13 LC_TELEPHONE="C"; export LC_TELEPHONE
13 LC_TELEPHONE="C"; export LC_TELEPHONE
14 LC_MEASUREMENT="C"; export LC_MEASUREMENT
14 LC_MEASUREMENT="C"; export LC_MEASUREMENT
15 LC_IDENTIFICATION="C"; export LC_IDENTIFICATION
15 LC_IDENTIFICATION="C"; export LC_IDENTIFICATION
16 LC_ALL=""; export LC_ALL
16 LC_ALL=""; export LC_ALL
17 TZ=GMT; export TZ
17 TZ=GMT; export TZ
18 HGEDITOR=true; export HGEDITOR
18 HGEDITOR=true; export HGEDITOR
19 HGMERGE=true; export HGMERGE
19 HGMERGE=true; export HGMERGE
20 HGUSER="test"; export HGUSER
20 HGUSER="test"; export HGUSER
21 HGRCPATH=""; export HGRCPATH
21 HGRCPATH=""; export HGRCPATH
22
22
23 ECHO_N="echo -n"
23 if [ `echo -n HG` == "-n HG" ]
24 [ -x /usr/ucb/echo ] && ECHO_N="/usr/ucb/echo -n"
24 then
25 ECHO_N=echo
26 NNL="\c"
27 else
28 ECHO_N="echo -n"
29 NNL=
30 fi
25
31
26 umask 022
32 umask 022
27
33
28 tests=0
34 tests=0
29 failed=0
35 failed=0
30
36
31 HGTMP=""
37 HGTMP=""
32 cleanup_exit() {
38 cleanup_exit() {
33 rm -rf "$HGTMP"
39 rm -rf "$HGTMP"
34 }
40 }
35
41
36 # Remove temporary files even if we get interrupted
42 # Remove temporary files even if we get interrupted
37 trap "cleanup_exit" 0 # normal exit
43 trap "cleanup_exit" 0 # normal exit
38 trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
44 trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
39
45
40 HGTMP="${TMPDIR-/tmp}/hgtests.$RANDOM.$RANDOM.$RANDOM.$$"
46 HGTMP="${TMPDIR-/tmp}/hgtests.$RANDOM.$RANDOM.$RANDOM.$$"
41 (umask 077 && mkdir "$HGTMP") || {
47 (umask 077 && mkdir "$HGTMP") || {
42 echo "Could not create temporary directory! Exiting." 1>&2
48 echo "Could not create temporary directory! Exiting." 1>&2
43 exit 1
49 exit 1
44 }
50 }
45
51
46 TESTDIR="$PWD"
52 TESTDIR="$PWD"
47 export TESTDIR
53 export TESTDIR
48 INST="$HGTMP/install"
54 INST="$HGTMP/install"
49 PYTHONDIR="$INST/lib/python"
55 PYTHONDIR="$INST/lib/python"
50 cd ..
56 cd ..
51 if ${PYTHON-python} setup.py install --home="$INST" \
57 if ${PYTHON-python} setup.py install --home="$INST" \
52 --install-lib="$PYTHONDIR" > tests/install.err 2>&1
58 --install-lib="$PYTHONDIR" > tests/install.err 2>&1
53 then
59 then
54 rm tests/install.err
60 rm tests/install.err
55 else
61 else
56 cat tests/install.err
62 cat tests/install.err
57 exit 1
63 exit 1
58 fi
64 fi
59 cd "$TESTDIR"
65 cd "$TESTDIR"
60
66
61 BINDIR="$INST/bin"
67 BINDIR="$INST/bin"
62 PATH="$BINDIR:$PATH"; export PATH
68 PATH="$BINDIR:$PATH"; export PATH
63 if [ -n "$PYTHON" ]; then
69 if [ -n "$PYTHON" ]; then
64 {
70 {
65 echo "#!/bin/sh"
71 echo "#!/bin/sh"
66 echo "exec \"$PYTHON"'" "$@"'
72 echo "exec \"$PYTHON"'" "$@"'
67 } > "$BINDIR/python"
73 } > "$BINDIR/python"
68 chmod 755 "$BINDIR/python"
74 chmod 755 "$BINDIR/python"
69 fi
75 fi
70
76
71 PYTHONPATH="$PYTHONDIR"; export PYTHONPATH
77 PYTHONPATH="$PYTHONDIR"; export PYTHONPATH
72
78
73 run_one() {
79 run_one() {
74 rm -f "$1.err"
80 rm -f "$1.err"
75
81
76 mkdir "$HGTMP/$1"
82 mkdir "$HGTMP/$1"
77 cd "$HGTMP/$1"
83 cd "$HGTMP/$1"
78 fail=0
84 fail=0
79 HOME="$HGTMP/$1"; export HOME
85 HOME="$HGTMP/$1"; export HOME
80 OUT="$HGTMP/$1.out"
86 OUT="$HGTMP/$1.out"
81 OUTOK="$TESTDIR/$1.out"
87 OUTOK="$TESTDIR/$1.out"
82 ERR="$TESTDIR/$1.err"
88 ERR="$TESTDIR/$1.err"
83
89
84 if "$TESTDIR/$1" > "$OUT" 2>&1; then
90 if "$TESTDIR/$1" > "$OUT" 2>&1; then
85 : no error
91 : no error
86 else
92 else
87 echo "$1 failed with error code $?"
93 echo "$1 failed with error code $?"
88 fail=1
94 fail=1
89 fi
95 fi
90
96
91 if [ -s "$OUT" -a ! -s "$OUTOK" ] ; then
97 if [ -s "$OUT" -a ! -s "$OUTOK" ] ; then
92 cp "$OUT" "$ERR"
98 cp "$OUT" "$ERR"
93 echo
99 echo
94 echo "$1 generated unexpected output:"
100 echo "$1 generated unexpected output:"
95 cat "$ERR"
101 cat "$ERR"
96 fail=1
102 fail=1
97 elif [ -r "$OUTOK" ]; then
103 elif [ -r "$OUTOK" ]; then
98 if diff -u "$OUTOK" "$OUT" > /dev/null; then
104 if diff -u "$OUTOK" "$OUT" > /dev/null; then
99 : no differences
105 : no differences
100 else
106 else
101 cp "$OUT" "$ERR"
107 cp "$OUT" "$ERR"
102 echo
108 echo
103 echo "$1 output changed:"
109 echo "$1 output changed:"
104 diff -u "$OUTOK" "$ERR" || true
110 diff -u "$OUTOK" "$ERR" || true
105 fail=1
111 fail=1
106 fi
112 fi
107 fi
113 fi
108
114
109 cd "$TESTDIR"
115 cd "$TESTDIR"
110 rm -f "$HGTMP/$1.out"
116 rm -f "$HGTMP/$1.out"
111 rm -rf "$HGTMP/$1"
117 rm -rf "$HGTMP/$1"
112 return $fail
118 return $fail
113 }
119 }
114
120
115 # list of prerequisite programs
121 # list of prerequisite programs
116 # stuff from coreutils (cat, rm, etc) are not tested
122 # stuff from coreutils (cat, rm, etc) are not tested
117 prereqs="python merge diff grep unzip gunzip bunzip2 sed"
123 prereqs="python merge diff grep unzip gunzip bunzip2 sed"
118 missing=''
124 missing=''
119 for pre in $prereqs ; do
125 for pre in $prereqs ; do
120 if type $pre > /dev/null 2>&1 ; then
126 if type $pre > /dev/null 2>&1 ; then
121 : prereq exists
127 : prereq exists
122 else
128 else
123 missing="$pre $missing"
129 missing="$pre $missing"
124 fi
130 fi
125 done
131 done
126
132
127 if [ "$missing" != '' ] ; then
133 if [ "$missing" != '' ] ; then
128 echo "ERROR: the test suite needs some programs to execute correctly."
134 echo "ERROR: the test suite needs some programs to execute correctly."
129 echo "The following programs are missing: "
135 echo "The following programs are missing: "
130 for pre in $missing; do
136 for pre in $missing; do
131 echo " $pre"
137 echo " $pre"
132 done
138 done
133 exit 1
139 exit 1
134 fi
140 fi
135
141
136 TESTS="$*"
142 TESTS="$*"
137 if [ -z "$TESTS" ] ; then
143 if [ -z "$TESTS" ] ; then
138 TESTS=`ls test-* | grep -v "[.~]"`
144 TESTS=`ls test-* | grep -v "[.~]"`
139 fi
145 fi
140
146
141 for f in $TESTS ; do
147 for f in $TESTS ; do
142 $ECHO_N "."
148 $ECHO_N ".${NNL}"
143 run_one $f || failed=`expr $failed + 1`
149 run_one $f || failed=`expr $failed + 1`
144 tests=`expr $tests + 1`
150 tests=`expr $tests + 1`
145 done
151 done
146
152
147 echo
153 echo
148 echo "Ran $tests tests, $failed failed."
154 echo "Ran $tests tests, $failed failed."
149
155
150 if [ $failed -gt 0 ] ; then
156 if [ $failed -gt 0 ] ; then
151 exit 1
157 exit 1
152 fi
158 fi
153 exit 0
159 exit 0
General Comments 0
You need to be logged in to leave comments. Login now