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
diff --git a/bin/click-review b/bin/click-review
0deleted file mode 1200000deleted file mode 120000
index 768dbca..0000000
--- a/bin/click-review
+++ /dev/null
@@ -1 +0,0 @@
1snap-review
2\ No newline at end of file0\ No newline at end of file
diff --git a/bin/snap-review b/bin/snap-review
index 6a70d1c..d457965 100755
--- a/bin/snap-review
+++ b/bin/snap-review
@@ -193,20 +193,41 @@ def main():
193 "Could not write state output: %s" % e,193 "Could not write state output: %s" % e,
194 )194 )
195195
196 # tests/test.sh called snap-review three times for each snap to generate
197 # the output in different formats ("", "--sdk", "--json"). RT_FUNC_TEST env
198 # variable is used to generate the expected output (tests/test.sh.expected)
199 # only running the review once
200 if os.getenv("RT_FUNC_TEST"):
201 allow_classic = " --allow-classic" if args.allow_classic else ""
202 rt_extras = " RT_EXTRAS_PATH with" if os.getenv("RT_EXTRAS_PATH") else ""
203 prefix = allow_classic + rt_extras
204
205 print("=%s %s =" % (prefix, os.path.basename(args.filename)))
206 report.show_results("console")
207 print("")
208
209 print("=%s --sdk %s =" % (prefix, os.path.basename(args.filename)))
210 report.show_results("sdk")
211 print("")
212
213 print("=%s --json %s =" % (prefix, os.path.basename(args.filename)))
214 report.show_results("json")
215 print("")
216
217 sys.exit(0)
218
196 # Show the results of the report219 # Show the results of the report
197 if args.json:220 if args.json:
198 report_type = "json"221 report.show_results("json")
199 elif args.sdk:222 elif args.sdk:
200 report_type = "sdk"223 report.show_results("sdk")
201 if report.errors or report.warnings:224 if report.errors or report.warnings:
202 # TODO: harmonize return codes225 # TODO: harmonize return codes
203 rc = 1226 rc = 1
204 else:227 else:
205 report_type = "console"228 report.show_results("console")
206
207 # Show results updates of report.errors and report.warnings
208 report.show_results(report_type)
209229
230 # Return codes
210 if rc == 1:231 if rc == 1:
211 # always exit(1) if there are errors232 # always exit(1) if there are errors
212 pass233 pass
diff --git a/tests/test.sh b/tests/test.sh
index 947b773..29dd02c 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -15,10 +15,9 @@ if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
15 exit15 exit
16fi16fi
1717
18# TODO: figure out a different way to determine if performing system tests18review_executable="bin/snap-review"
19testtype="click-review"
20if [ "$1" = "system" ]; then19if [ "$1" = "system" ]; then
21 testtype="snap-review"20 review_executable="review-tools.snap-review"
22 # shellcheck disable=SC223021 # shellcheck disable=SC2230
23 if ! which review-tools.snap-review >/dev/null 2>&1 ; then22 if ! which review-tools.snap-review >/dev/null 2>&1 ; then
24 echo "Could not find snap-review. Is the review-tools snap installed?"23 echo "Could not find snap-review. Is the review-tools snap installed?"
@@ -38,60 +37,18 @@ tmpjson=$(mktemp)
3837
39for i in ./tests/*.snap ; do38for i in ./tests/*.snap ; do
40 echo "$i" | grep -q "/test-resquash_" && continue # test these elsewhere39 echo "$i" | grep -q "/test-resquash_" && continue # test these elsewhere
41 for j in "" "--sdk" "--json" ; do40 RT_FUNC_TEST=1 PYTHONPATH=. "$review_executable" "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
42 snap=$(basename "$i")
43 echo "= $j $snap ="
44 if [ "$testtype" = "snap-review" ]; then
45 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"
46 else
47 PYTHONPATH=./ ./bin/click-review $j "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
48 fi
49
50 if [ "$j" = "--json" ]; then
51 jq '.' "$tmpjson" >/dev/null || {
52 echo "'jq . $tmpjson' failed"
53 cat "$tmpjson"
54 exit 1
55 }
56 fi
57 echo
58 done
59done | tee "$tmp"41done | tee "$tmp"
6042
61for i in ./tests/test-classic*.snap ; do43for i in ./tests/test-classic*.snap ; do
62 for j in "" "--sdk" "--json" ; do44 RT_FUNC_TEST=1 PYTHONPATH=. "$review_executable" --allow-classic "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
63 snap=$(basename "$i")
64 echo "= --allow-classic $j $snap ="
65 if [ "$testtype" = "snap-review" ]; then
66 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"
67 else
68 PYTHONPATH=./ ./bin/click-review --allow-classic $j "$i" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
69 fi
70
71 if [ "$j" = "--json" ]; then
72 jq '.' "$tmpjson" >/dev/null || {
73 echo "'jq . $tmpjson' failed"
74 exit 1
75 }
76 fi
77 echo
78 done
79done | tee -a "$tmp"45done | tee -a "$tmp"
8046
81# test-resquash_0.snap takes forever. Just test it with --json47# test-resquash_0.snap takes forever. Just test it with --json
82for i in ./tests/test-resquash_*.snap ; do48for i in ./tests/test-resquash_*.snap ; do
83 snap=$(basename "$i")49 snap=$(basename "$i")
84 echo "= --json $snap ="50 echo "= --json $snap ="
85 if [ "$testtype" = "snap-review" ]; then51 PYTHONPATH=. "$review_executable" --json "$i" 2>&1 | sed -e 's#./tests/##g' > "$tmpjson"
86 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"
87 else
88 PYTHONPATH=./ ./bin/click-review --json "$i" 2>&1 | sed -e 's#./tests/##g' > "$tmpjson"
89 fi
90
91 jq '.' "$tmpjson" >/dev/null || {
92 echo "'jq . $tmpjson' failed"
93 exit 1
94 }
9552
96 # now show all the output that with the deleted error text53 # now show all the output that with the deleted error text
97 jq 'del(."snap.v2_security"."error"."security-snap-v2:squashfs_files"."text")' "$tmpjson"54 jq 'del(."snap.v2_security"."error"."security-snap-v2:squashfs_files"."text")' "$tmpjson"
@@ -101,26 +58,9 @@ for i in ./tests/test-resquash_*.snap ; do
101done | tee -a "$tmp"58done | tee -a "$tmp"
10259
103# test RT_EXTRAS_PATH60# test RT_EXTRAS_PATH
104testsnap="./tests/hello-world_25.snap"
105rtpath="./tests/review-tools-extras"61rtpath="./tests/review-tools-extras"
106for j in "" "--sdk" "--json" ; do62testsnap="./tests/hello-world_25.snap"
107 snap=$(basename "$testsnap")63RT_FUNC_TEST=1 PYTHONPATH=. RT_EXTRAS_PATH="$rtpath" "$review_executable" "$testsnap" 2>&1 | sed -e 's#./tests/##g' | tee -a "$tmp"
108 echo "= RT_EXTRAS_PATH with $j $testsnap ="
109 if [ "$testtype" = "snap-review" ]; then
110 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"
111 else
112 RT_EXTRAS_PATH="$rtpath" PYTHONPATH=./ ./bin/click-review $j "$testsnap" 2>&1 | sed -e 's#./tests/##g' | tee "$tmpjson"
113 fi
114
115 if [ "$j" = "--json" ]; then
116 jq '.' "$tmpjson" >/dev/null || {
117 echo "'jq . $tmpjson' failed"
118 cat "$tmpjson"
119 exit 1
120 }
121 fi
122 echo
123done | tee -a "$tmp"
12464
125echo65echo
126echo "Checking for differences in output..."66echo "Checking for differences in output..."
diff --git a/tests/test.sh.expected b/tests/test.sh.expected
index e74cc2c..4a8281f 100644
--- a/tests/test.sh.expected
+++ b/tests/test.sh.expected
@@ -116895,7 +116895,7 @@ unusual mode 'rwxrwxrwt' for entry './file/1777-daemon:daemon'
116895unusual mode 'rwxrwxrwt' for entry './file/1777-daemon:root'116895unusual mode 'rwxrwxrwt' for entry './file/1777-daemon:root'
116896unusual mode 'rwxrwxrwt' for entry './file/1777-root:daemon'116896unusual mode 'rwxrwxrwt' for entry './file/1777-root:daemon'
116897unusual mode 'rwxrwxrwt' for entry './file/1777-root:root'116897unusual mode 'rwxrwxrwt' for entry './file/1777-root:root'
116898= RT_EXTRAS_PATH with ./tests/hello-world_25.snap =116898= RT_EXTRAS_PATH with hello-world_25.snap =
116899Errors116899Errors
116900------116900------
116901 - extras-tests-v2:error116901 - extras-tests-v2:error
@@ -116906,7 +116906,7 @@ Warnings
116906 test warn116906 test warn
116907hello-world_25.snap: FAIL116907hello-world_25.snap: FAIL
116908116908
116909= RT_EXTRAS_PATH with --sdk ./tests/hello-world_25.snap =116909= RT_EXTRAS_PATH with --sdk hello-world_25.snap =
116910= snap.v2_declaration =116910= snap.v2_declaration =
116911{116911{
116912 "error": {},116912 "error": {},
@@ -117188,7 +117188,7 @@ hello-world_25.snap: FAIL
117188 "warn": {}117188 "warn": {}
117189}117189}
117190117190
117191= RT_EXTRAS_PATH with --json ./tests/hello-world_25.snap =117191= RT_EXTRAS_PATH with --json hello-world_25.snap =
117192{117192{
117193 "snap.v2_declaration": {117193 "snap.v2_declaration": {
117194 "error": {},117194 "error": {},

Subscribers

People subscribed via source and target branches