-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-matrix-docker.sh
More file actions
executable file
·153 lines (133 loc) · 4.96 KB
/
cli-matrix-docker.sh
File metadata and controls
executable file
·153 lines (133 loc) · 4.96 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
set -euo pipefail
if ! command -v docker >/dev/null 2>&1; then
echo "Docker is required. Install Docker Desktop and try again." >&2
exit 1
fi
versions=("$@")
if [ "${#versions[@]}" -eq 0 ]; then
versions=(7.4 8.0 8.1 8.2 8.3 8.4 8.5)
fi
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fixture="examples/fixtures/wikipedia-earth.html"
if [ ! -f "${root_dir}/${fixture}" ]; then
echo "Missing fixture: ${fixture}" >&2
exit 1
fi
baseline_version="${versions[0]}"
baseline_dir="$(mktemp -d)"
current_dir=""
cleanup() {
if [ -n "${current_dir}" ] && [ -d "${current_dir}" ]; then
rm -rf "${current_dir}"
fi
if [ -n "${baseline_dir}" ] && [ -d "${baseline_dir}" ]; then
rm -rf "${baseline_dir}"
fi
}
trap cleanup EXIT
fail() {
echo "FAIL: $1" >&2
exit 1
}
assert_eq() {
local expected="$1"
local actual="$2"
if [ "$actual" != "$expected" ]; then
fail "Expected '${expected}', got '${actual}'"
fi
}
record_output() {
local name="$1"
local value="$2"
local diff_output=""
if [ "$v" = "$baseline_version" ]; then
printf '%s' "$value" > "${baseline_dir}/${name}"
return
fi
printf '%s' "$value" > "${current_dir}/${name}"
diff_output="$(diff -u "${baseline_dir}/${name}" "${current_dir}/${name}" || true)"
if [ -n "${diff_output}" ]; then
echo "${diff_output}" >&2
fail "Output mismatch for ${name} between PHP ${baseline_version} and PHP ${v}"
fi
}
for v in "${versions[@]}"; do
echo "== PHP ${v} =="
current_dir="$(mktemp -d)"
run_php() {
docker run --rm -v "${root_dir}":/work -w /work "php:${v}-cli" php "$@"
}
run_sh() {
docker run --rm -v "${root_dir}":/work -w /work "php:${v}-cli" sh -lc "$1"
}
# --count
out="$(run_php bin/justhtml "${fixture}" --selector "h1#firstHeading" --count)"
assert_eq "1" "$out"
record_output "count" "$out"
# --inner / --outer
out="$(run_php bin/justhtml "${fixture}" --selector "h1#firstHeading" --format html --outer)"
echo "$out" | grep -q "<h1" || fail "--outer did not include <h1"
record_output "outer" "$out"
out="$(run_php bin/justhtml "${fixture}" --selector "h1#firstHeading" --format html --inner)"
echo "$out" | grep -q "<h1" && fail "--inner unexpectedly included <h1"
echo "$out" | grep -q "mw-page-title-main" || fail "--inner missing title span"
record_output "inner" "$out"
# --limit / --first
out="$(run_sh "php bin/justhtml ${fixture} --selector 'p' --format text --limit 1 | wc -l | tr -d ' '")"
assert_eq "1" "$out"
record_output "limit1_lines" "$out"
out="$(run_sh "php bin/justhtml ${fixture} --selector 'p' --format text --first | wc -l | tr -d ' '")"
assert_eq "1" "$out"
record_output "first_lines" "$out"
# --format text output consistency
out="$(run_php bin/justhtml "${fixture}" --selector "title" --format text --first)"
assert_eq "Earth - Wikipedia" "$out"
record_output "text_title" "$out"
# --attr / --missing / --separator
out="$(run_php bin/justhtml "${fixture}" --selector "a.mw-jump-link" --attr href --first)"
assert_eq "#bodyContent" "$out"
record_output "attr_href" "$out"
out="$(run_php bin/justhtml "${fixture}" --selector "a.mw-jump-link" --attr href --attr class --first)"
assert_eq "#bodyContent mw-jump-link" "$out"
record_output "attr_href_class" "$out"
out="$(run_php bin/justhtml "${fixture}" --selector "a.mw-jump-link" --attr href --attr rel --first)"
assert_eq "#bodyContent __MISSING__" "$out"
record_output "attr_href_rel_missing" "$out"
out="$(run_php bin/justhtml "${fixture}" --selector "a.mw-jump-link" --attr href --attr rel --missing NA --first)"
assert_eq "#bodyContent NA" "$out"
record_output "attr_href_rel_missing_override" "$out"
out="$(run_php bin/justhtml "${fixture}" --selector "a.mw-jump-link" --attr href --attr rel --separator "," --first)"
assert_eq "#bodyContent,__MISSING__" "$out"
record_output "attr_separator" "$out"
# Conflict checks
if run_sh "php bin/justhtml ${fixture} --selector 'p' --count --format text" >/dev/null 2>&1; then
fail "--count should fail with --format"
fi
if run_sh "php bin/justhtml ${fixture} --selector 'a' --attr href --format text" >/dev/null 2>&1; then
fail "--attr should fail with --format"
fi
if run_sh "php bin/justhtml ${fixture} --selector 'p' --first --limit 2" >/dev/null 2>&1; then
fail "--first should fail with --limit"
fi
# --limit validation messages
set +e
out="$(run_sh "php bin/justhtml ${fixture} --selector 'p' --limit 0" 2>&1)"
status=$?
set -e
if [ "$status" -eq 0 ]; then
fail "--limit 0 should fail"
fi
echo "$out" | grep -q "Invalid value for --limit" || fail "Missing invalid --limit error"
set +e
out="$(run_sh "php bin/justhtml ${fixture} --selector 'p' --limit 999999999999999999999999" 2>&1)"
status=$?
set -e
if [ "$status" -eq 0 ]; then
fail "--limit overflow should fail"
fi
echo "$out" | grep -q "Value for --limit is too large" || fail "Missing overflow --limit error"
rm -rf "${current_dir}"
current_dir=""
echo ""
done