-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtest
executable file
·89 lines (67 loc) · 1.76 KB
/
runtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# Return errors:
#
# 0 - The test passed
# 1 - Cannot find Dillo binary
# 2 - Cannot find test or reference test
# 3 - Dillo crashed or cannot find window
# 100 - The test doesn't match the reference
set -e
#set -x
if [ ! -e "$DILLOBIN" ]; then
echo missing dillo binary, set DILLOBIN with the path to dillo
exit 1
fi
test_fpath="$1"
# Set the testfile to absolute path
testfile="$PWD/$test_fpath"
if [ ! -e "$testfile" ]; then
echo "cannot find test file: $testfile" >&2
exit 2
fi
testdir=$(dirname "$testfile")
# Get the match file
match=$(xmllint --html --xpath "string(//head/link[@rel='match']/@href)" "$testfile")
if [ -z "$match" ]; then
echo "cannot find link rel=match file" >&2
exit 2
fi
reffile="$testdir/$match"
if [ ! -e "$reffile" ]; then
echo "reference file $reffile not found" >&2
exit 2
fi
magick_bin="convert"
if command -v magick 2>&1 >/dev/null; then
magick_bin="magick"
fi
function render_page() {
htmlfile="$1"
outpic="$2"
"$DILLOBIN" -f "$htmlfile" &
dillopid=$!
# TODO: We need a better system to determine when the page loaded
sleep 0.5
# Capture only Dillo window
winid=$(xwininfo -all -root | awk '/Dillo:/ {print $1}')
if [ -z "$winid" ]; then
echo "cannot find Dillo window" >&2
exit 3
fi
xwd -id "$winid" -silent | ${magick_bin} xwd:- png:${outpic}
kill "$dillopid"
}
mkdir -p out
render_page "$testfile" "out/test.png"
render_page "$reffile" "out/ref.png"
# AE = Absolute Error count of the number of different pixels
diffcount=$(compare -metric AE "out/test.png" "out/ref.png" "out/diff.png" 2>&1 || true)
# The test passes only if both images are identical
if [ "$diffcount" = "0" ]; then
#echo "OK $testfile"
ret=0
else
#echo "FAIL $testfile"
ret=100
fi
exit $ret