Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
#!/bin/sh
2
 
3
# The build system runs this test from a different working directory, and may
4
# be in a build directory entirely separate from the source. So if the
5
# "srcdir" variable is set, we must use it to locate the test files and the
6
# glcpp-test script.
7
 
8
if [ ! -z "$srcdir" ]; then
9
   testdir="$srcdir/glcpp/tests"
10
   glcpp_test="$srcdir/glcpp/tests/glcpp-test"
11
else
12
   testdir=.
13
   glcpp_test=./glcpp-test
14
fi
15
 
16
total=0
17
pass=0
18
 
19
# This supports a pipe that doesn't destroy the exit status of first command
20
#
21
# http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
22
stdintoexitstatus() {
23
    read exitstatus
24
    return $exitstatus
25
}
26
 
27
run_test ()
28
{
29
    cmd="$1"
30
 
31
    total=$((total+1))
32
 
33
    if [ "$VERBOSE" = "yes" ]; then
34
	if $cmd; then
35
	    echo "PASS"
36
	    pass=$((pass+1))
37
	else
38
	    echo "FAIL"
39
	fi
40
    else
41
	# This is "$cmd | tail -2" but with the exit status of "$cmd" not "tail -2"
42
	if (((($cmd; echo $? >&3) | tail -2 | head -1 >&4) 3>&1) | stdintoexitstatus) 4>&1; then
43
	    echo "PASS"
44
	    pass=$((pass+1))
45
	else
46
	    echo "FAIL"
47
	fi
48
    fi
49
}
50
 
51
usage ()
52
{
53
	cat <
54
Usage: glcpp-cr-lf [options...]
55
 
56
Run the entire glcpp-test suite several times, each time with each source
57
file transformed to use a non-standard line-termination character. Each
58
entire run with a different line-termination character is considered a
59
single test.
60
 
61
Valid options include:
62
 
63
	-v|--verbose	Print all output from the various sub-tests
64
EOF
65
}
66
 
67
# Parse command-line options
68
for option; do
69
    case "${option}" in
70
	-v|--verbose)
71
	    VERBOSE=yes;
72
	    ;;
73
	*)
74
	    echo "Unrecognized option: $option" >&2
75
	    echo >&2
76
	    usage
77
	    exit 1
78
	    ;;
79
	esac
80
done
81
 
82
# All tests depend on the .out files being present. So first do a
83
# normal run of the test suite, (silently) just to create the .out
84
# files as a side effect.
85
rm -rf ./subtest-lf
86
mkdir subtest-lf
87
for file in "$testdir"/*.c; do
88
    base=$(basename "$file")
89
    cp "$file" subtest-lf
90
done
91
 
92
${glcpp_test} --testdir=subtest-lf >/dev/null 2>&1
93
 
94
echo "===== Testing with \\\\r line terminators (old Mac format) ====="
95
 
96
# Prepare test files with '\r' instead of '\n'
97
rm -rf ./subtest-cr
98
mkdir subtest-cr
99
for file in "$testdir"/*.c; do
100
    base=$(basename "$file")
101
    tr "\n" "\r" < "$file" > subtest-cr/"$base"
102
    cp `pwd`/glcpp/tests/subtest-lf/"$base".out subtest-cr/"$base".expected
103
done
104
 
105
run_test "${glcpp_test} --testdir=subtest-cr"
106
 
107
echo "===== Testing with \\\\r\\\\n line terminators (DOS format) ====="
108
 
109
# Prepare test files with '\r\n' instead of '\n'
110
rm -rf ./subtest-cr-lf
111
mkdir subtest-cr-lf
112
for file in "$testdir"/*.c; do
113
    base=$(basename "$file")
114
    sed -e 's/$/
/' < "$file" > subtest-cr-lf/"$base"
115
    cp `pwd`/glcpp/tests/subtest-lf/"$base".out subtest-cr-lf/"$base".expected
116
done
117
118
 
119
120
 
121
122
 
123
rm -rf ./subtest-lf-cr
124
mkdir subtest-lf-cr
125
for file in "$testdir"/*.c; do
126
    base=$(basename "$file")
127
    sed -e 's/$/
/' < "$file" | tr "\n\r" "\r\n" > subtest-lf-cr/"$base"
128
    cp `pwd`/glcpp/tests/subtest-lf/"$base".out subtest-lf-cr/"$base".expected
129
done
130
131
run_test "${glcpp_test} --testdir=subtest-lf-cr"
132
 
133
echo ""
134
 
135
echo ""
136
137
if [ "$pass" = "$total" ]; then
138
 
139
else
140
    exit 1
141
fi
142
Usage:>
143
Usage:>