File tree Expand file tree Collapse file tree 3 files changed +34
-11
lines changed Expand file tree Collapse file tree 3 files changed +34
-11
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22import sys
33
4- targets = sys .argv [1 :]
5- assert targets
4+ must_find = []
5+ must_not_find = []
6+ for arg in sys .argv [1 :]:
7+ if arg .startswith ("!" ):
8+ must_not_find .append (arg [1 :])
9+ else :
10+ must_find .append (arg )
11+
612found = set ()
713
814for line in sys .stdin :
915 sys .stdout .write (line )
10- for t in targets :
16+ for t in must_find :
1117 if t in line :
1218 found .add (t )
19+ for t in must_not_find :
20+ if t in line :
21+ sys .stderr .write (f"contains error: { t !r} was not expected\n " )
1322
1423sys .stdout .flush ()
1524
16- not_found = set (targets ) - found
25+ not_found = set (must_find ) - found
1726for item in sorted (not_found ):
1827 sys .stderr .write (f"contains error: { item !r} not found in the output.\n " )
Original file line number Diff line number Diff line change 11
2- === This should complain about not_found not found, but errcode is zero
2+ === This should complain about not_found not found
33>>> python3 ./success.py
44Hello world
55contains error: 'not_found' not found in the output.
66
7- === This should complain about not_found not found, but errcode is propagated
7+ === This should complain about not_found not found
88>>> musterr python3 ./failure.py
99Failed script
1010contains error: 'not_found' not found in the output.
@@ -13,6 +13,15 @@ contains error: 'not_found' not found in the output.
1313>>> python3 ./success.py
1414Hello world
1515
16- === This should not complain, but errcode is propagated
16+ === This should not complain
1717>>> musterr python3 ./failure.py
1818Failed script
19+
20+ === This should complain about Hello present in output
21+ >>> python3 ./success.py
22+ Hello world
23+ contains error: 'Hello' was not expected
24+
25+ === This should not complain
26+ >>> python3 ./success.py
27+ Hello world
Original file line number Diff line number Diff line change 1- title "This should complain about " not_found" not found, but errcode is zero "
1+ title "This should complain about not_found not found"
22trace python3 ./success.py | contains.py not_found
33
4- title "This should complain about "not_found" not found, but errcode is propagated"
5- # this has a race between musterr and contains.py output:
4+ title "This should complain about not_found not found"
65trace musterr python3 ./failure.py | contains.py not_found
76
87title "This should not complain"
98trace python3 ./success.py | contains.py world Hello
109
11- title "This should not complain, but errcode is propagated "
10+ title "This should not complain"
1211trace musterr python3 ./failure.py | contains.py Failed
12+
13+ title "This should complain about Hello present in output"
14+ trace python3 ./success.py | contains.py !Hello
15+
16+ title "This should not complain"
17+ trace python3 ./success.py | contains.py !not_found
You can’t perform that action at this time.
0 commit comments