Merge ~jslarraz/review-tools:remove-duplicate-tests-in-test-sh into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Merged
Merged at revision: 022d283078d27f44976c2ae63ee54d538546d6f8
Proposed branch: ~jslarraz/review-tools:remove-duplicate-tests-in-test-sh
Merge into: review-tools:master
Diff against target: 201 lines (+37/-77)
4 files modified
bin/snap-review (+27/-6)
dev/null (+0/-1)
tests/test.sh (+7/-67)
tests/test.sh.expected (+3/-3)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466960@code.launchpad.net

Commit message

tests/test.sh: only run tests once per snap. A special environment variable `RT_FUNC_TEST` is used to instruct snap-review to prints the report in the three different formats ('', '--skd', '--json')

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM except minor change needed.

review: Needs Fixing
Revision history for this message
Jorge Sancho Larraz (jslarraz) wrote :
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM - thanks @jslarraz

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/click-review b/bin/click-review
2deleted file mode 120000
3index 768dbca..0000000
4--- a/bin/click-review
5+++ /dev/null
6@@ -1 +0,0 @@
7-snap-review
8\ No newline at end of file
9diff --git a/bin/snap-review b/bin/snap-review
10index 6a70d1c..d457965 100755
11--- a/bin/snap-review
12+++ b/bin/snap-review
13@@ -193,20 +193,41 @@ def main():
14 "Could not write state output: %s" % e,
15 )
16
17+ # tests/test.sh called snap-review three times for each snap to generate
18+ # the output in different formats ("", "--sdk", "--json"). RT_FUNC_TEST env
19+ # variable is used to generate the expected output (tests/test.sh.expected)
20+ # only running the review once
21+ if os.getenv("RT_FUNC_TEST"):
22+ allow_classic = " --allow-classic" if args.allow_classic else ""
23+ rt_extras = " RT_EXTRAS_PATH with" if os.getenv("RT_EXTRAS_PATH") else ""
24+ prefix = allow_classic + rt_extras
25+
26+ print("=%s %s =" % (prefix, os.path.basename(args.filename)))
27+ report.show_results("console")
28+ print("")
29+
30+ print("=%s --sdk %s =" % (prefix, os.path.basename(args.filename)))
31+ report.show_results("sdk")
32+ print("")
33+
34+ print("=%s --json %s =" % (prefix, os.path.basename(args.filename)))
35+ report.show_results("json")
36+ print("")
37+
38+ sys.exit(0)
39+
40 # Show the results of the report
41 if args.json:
42- report_type = "json"
43+ report.show_results("json")
44 elif args.sdk:
45- report_type = "sdk"
46+ report.show_results("sdk")
47 if report.errors or report.warnings:
48 # TODO: harmonize return codes
49 rc = 1
50 else:
51- report_type = "console"
52-
53- # Show results updates of report.errors and report.warnings
54- report.show_results(report_type)
55+ report.show_results("console")
56
57+ # Return codes
58 if rc == 1:
59 # always exit(1) if there are errors
60 pass
61diff --git a/tests/test.sh b/tests/test.sh
62index 947b773..29dd02c 100755
63--- a/tests/test.sh
64+++ b/tests/test.sh
65@@ -15,10 +15,9 @@ if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
66 exit
67 fi
68
69-# TODO: figure out a different way to determine if performing system tests
70-testtype="click-review"
71+review_executable="bin/snap-review"
72 if [ "$1" = "system" ]; then
73- testtype="snap-review"
74+ review_executable="review-tools.snap-review"
75 # shellcheck disable=SC2230
76 if ! which review-tools.snap-review >/dev/null 2>&1 ; then
77 echo "Could not find snap-review. Is the review-tools snap installed?"
78@@ -38,60 +37,18 @@ tmpjson=$(mktemp)
79
80 for i in ./tests/*.snap ; do
81 echo "$i" | grep -q "/test-resquash_" && continue # test these elsewhere
82- for j in "" "--sdk" "--json" ; do
83- snap=$(basename "$i")
84- echo "= $j $snap ="
85- if [ "$testtype" = "snap-review" ]; then
86- review-tools.snap-review $j "$i" 2>&1 | sed -e 's#./tests/##g' -e 's/"text": "SKIPPED (could not import apt_pkg)"/"text": "OK"/' | tee "$tmpjson"
87- else
88- PYTHONPATH=./ ./bin/click-review $j "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
89- fi
90-
91- if [ "$j" = "--json" ]; then
92- jq '.' "$tmpjson" >/dev/null || {
93- echo "'jq . $tmpjson' failed"
94- cat "$tmpjson"
95- exit 1
96- }
97- fi
98- echo
99- done
100+ RT_FUNC_TEST=1 PYTHONPATH=. "$review_executable" "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
101 done | tee "$tmp"
102
103 for i in ./tests/test-classic*.snap ; do
104- for j in "" "--sdk" "--json" ; do
105- snap=$(basename "$i")
106- echo "= --allow-classic $j $snap ="
107- if [ "$testtype" = "snap-review" ]; then
108- review-tools.snap-review --allow-classic $j "$i" 2>&1 | sed -e 's#./tests/##g' -e 's/"text": "SKIPPED (could not import apt_pkg)"/"text": "OK"/' | tee "$tmpjson"
109- else
110- PYTHONPATH=./ ./bin/click-review --allow-classic $j "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
111- fi
112-
113- if [ "$j" = "--json" ]; then
114- jq '.' "$tmpjson" >/dev/null || {
115- echo "'jq . $tmpjson' failed"
116- exit 1
117- }
118- fi
119- echo
120- done
121+ RT_FUNC_TEST=1 PYTHONPATH=. "$review_executable" --allow-classic "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
122 done | tee -a "$tmp"
123
124 # test-resquash_0.snap takes forever. Just test it with --json
125 for i in ./tests/test-resquash_*.snap ; do
126 snap=$(basename "$i")
127 echo "= --json $snap ="
128- if [ "$testtype" = "snap-review" ]; then
129- review-tools.snap-review --json "$i" 2>&1 | sed -e 's#./tests/##g' -e 's/"text": "SKIPPED (could not import apt_pkg)"/"text": "OK"/' > "$tmpjson"
130- else
131- PYTHONPATH=./ ./bin/click-review --json "$i" 2>&1 | sed -e 's#./tests/##g' > "$tmpjson"
132- fi
133-
134- jq '.' "$tmpjson" >/dev/null || {
135- echo "'jq . $tmpjson' failed"
136- exit 1
137- }
138+ PYTHONPATH=. "$review_executable" --json "$i" 2>&1 | sed -e 's#./tests/##g' > "$tmpjson"
139
140 # now show all the output that with the deleted error text
141 jq 'del(."snap.v2_security"."error"."security-snap-v2:squashfs_files"."text")' "$tmpjson"
142@@ -101,26 +58,9 @@ for i in ./tests/test-resquash_*.snap ; do
143 done | tee -a "$tmp"
144
145 # test RT_EXTRAS_PATH
146-testsnap="./tests/hello-world_25.snap"
147 rtpath="./tests/review-tools-extras"
148-for j in "" "--sdk" "--json" ; do
149- snap=$(basename "$testsnap")
150- echo "= RT_EXTRAS_PATH with $j $testsnap ="
151- if [ "$testtype" = "snap-review" ]; then
152- RT_EXTRAS_PATH="$rtpath" review-tools.snap-review $j "$testsnap" 2>&1 | sed -e 's#./tests/##g' -e 's/"text": "SKIPPED (could not import apt_pkg)"/"text": "OK"/' | tee "$tmpjson"
153- else
154- RT_EXTRAS_PATH="$rtpath" PYTHONPATH=./ ./bin/click-review $j "$testsnap" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
155- fi
156-
157- if [ "$j" = "--json" ]; then
158- jq '.' "$tmpjson" >/dev/null || {
159- echo "'jq . $tmpjson' failed"
160- cat "$tmpjson"
161- exit 1
162- }
163- fi
164- echo
165-done | tee -a "$tmp"
166+testsnap="./tests/hello-world_25.snap"
167+RT_FUNC_TEST=1 PYTHONPATH=. RT_EXTRAS_PATH="$rtpath" "$review_executable" "$testsnap" 2>&1 | sed -e 's#./tests/##g' | tee -a "$tmp"
168
169 echo
170 echo "Checking for differences in output..."
171diff --git a/tests/test.sh.expected b/tests/test.sh.expected
172index e74cc2c..4a8281f 100644
173--- a/tests/test.sh.expected
174+++ b/tests/test.sh.expected
175@@ -116895,7 +116895,7 @@ unusual mode 'rwxrwxrwt' for entry './file/1777-daemon:daemon'
176 unusual mode 'rwxrwxrwt' for entry './file/1777-daemon:root'
177 unusual mode 'rwxrwxrwt' for entry './file/1777-root:daemon'
178 unusual mode 'rwxrwxrwt' for entry './file/1777-root:root'
179-= RT_EXTRAS_PATH with ./tests/hello-world_25.snap =
180+= RT_EXTRAS_PATH with hello-world_25.snap =
181 Errors
182 ------
183 - extras-tests-v2:error
184@@ -116906,7 +116906,7 @@ Warnings
185 test warn
186 hello-world_25.snap: FAIL
187
188-= RT_EXTRAS_PATH with --sdk ./tests/hello-world_25.snap =
189+= RT_EXTRAS_PATH with --sdk hello-world_25.snap =
190 = snap.v2_declaration =
191 {
192 "error": {},
193@@ -117188,7 +117188,7 @@ hello-world_25.snap: FAIL
194 "warn": {}
195 }
196
197-= RT_EXTRAS_PATH with --json ./tests/hello-world_25.snap =
198+= RT_EXTRAS_PATH with --json hello-world_25.snap =
199 {
200 "snap.v2_declaration": {
201 "error": {},

Subscribers

People subscribed via source and target branches