diff options
Diffstat (limited to 'runtests.sh')
-rwxr-xr-x | runtests.sh | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..d313db3 --- /dev/null +++ b/runtests.sh | |||
@@ -0,0 +1,91 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PLATFORM="`uname -s`" | ||
4 | [ "$1" ] && VERSION="$1" || VERSION="1.0devel" | ||
5 | |||
6 | set -e | ||
7 | |||
8 | # Portable "ggrep -A" replacement | ||
9 | # contextgrep PATTERN POST_MATCH_LINES | ||
10 | contextgrep() { | ||
11 | awk "/$1/ { count = ($2 + 1) } count { count--; print }" | ||
12 | } | ||
13 | |||
14 | do_tests() { | ||
15 | echo | ||
16 | cd tests | ||
17 | lua -e 'require "cjson"; print("Testing Lua CJSON version " .. cjson.version)' | ||
18 | ./test.lua | contextgrep 'FAIL|Summary' 3 | grep -v PASS | cut -c -70 | ||
19 | cd .. | ||
20 | } | ||
21 | |||
22 | echo "===== Setting LuaRocks PATH =====" | ||
23 | eval "`luarocks path`" | ||
24 | |||
25 | echo "===== Building UTF-8 test data =====" | ||
26 | ( cd tests && ./genutf8.pl; ) | ||
27 | |||
28 | echo "===== Cleaning old build data =====" | ||
29 | make clean | ||
30 | rm -f tests/cjson.so | ||
31 | |||
32 | echo "===== Verifying cjson.so is not installed =====" | ||
33 | |||
34 | cd tests | ||
35 | if lua -e 'require "cjson"' 2>/dev/null | ||
36 | then | ||
37 | cat <<EOT | ||
38 | Please ensure you do not have the Lua CJSON module installed before | ||
39 | running these tests. | ||
40 | EOT | ||
41 | exit | ||
42 | fi | ||
43 | cd .. | ||
44 | |||
45 | echo "===== Testing LuaRocks build =====" | ||
46 | luarocks make --local | ||
47 | do_tests | ||
48 | luarocks remove --local lua-cjson | ||
49 | make clean | ||
50 | |||
51 | echo "===== Testing Makefile build =====" | ||
52 | make | ||
53 | cp cjson.so tests | ||
54 | do_tests | ||
55 | make clean | ||
56 | rm -f tests/cjson.so | ||
57 | |||
58 | echo "===== Testing Cmake build =====" | ||
59 | mkdir build | ||
60 | cd build | ||
61 | cmake .. | ||
62 | make | ||
63 | cd .. | ||
64 | cp build/cjson.so tests | ||
65 | do_tests | ||
66 | rm -rf build tests/cjson.so | ||
67 | |||
68 | if [ "$PLATFORM" = "Linux" ] | ||
69 | then | ||
70 | echo "===== Testing RPM build =====" | ||
71 | SRCTGZ="" | ||
72 | TGZ=lua-cjson-$VERSION.tar.gz | ||
73 | for D in .. packages . | ||
74 | do | ||
75 | [ -r "$D/$TGZ" ] && SRCTGZ="$D/$TGZ" | ||
76 | done | ||
77 | if [ "$SRCTGZ" ] | ||
78 | then | ||
79 | LOG=/tmp/build.$$ | ||
80 | rpmbuild -tb "$SRCTGZ" > "$LOG" | ||
81 | RPM="`awk '/^Wrote: / && ! /debuginfo/ { print $2}' < "$LOG"`" | ||
82 | sudo -- rpm -Uvh \"$RPM\" | ||
83 | do_tests | ||
84 | sudo -- rpm -e lua-cjson | ||
85 | rm -f "$LOG" | ||
86 | else | ||
87 | echo "==> skipping, $TGZ not found" | ||
88 | fi | ||
89 | fi | ||
90 | |||
91 | # vi:ai et sw=4 ts=4: | ||