Skip to content

Commit 665ab46

Browse files
committed
acc: add negative test to contains.py
1 parent 32eb103 commit 665ab46

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

acceptance/bin/contains.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
#!/usr/bin/env python3
22
import 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+
612
found = set()
713

814
for 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

1423
sys.stdout.flush()
1524

16-
not_found = set(targets) - found
25+
not_found = set(must_find) - found
1726
for item in sorted(not_found):
1827
sys.stderr.write(f"contains error: {item!r} not found in the output.\n")
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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
44
Hello world
55
contains 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
99
Failed script
1010
contains 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
1414
Hello world
1515

16-
=== This should not complain, but errcode is propagated
16+
=== This should not complain
1717
>>> musterr python3 ./failure.py
1818
Failed 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
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
title "This should complain about "not_found" not found, but errcode is zero"
1+
title "This should complain about not_found not found"
22
trace 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"
65
trace musterr python3 ./failure.py | contains.py not_found
76

87
title "This should not complain"
98
trace python3 ./success.py | contains.py world Hello
109

11-
title "This should not complain, but errcode is propagated"
10+
title "This should not complain"
1211
trace 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

0 commit comments

Comments
 (0)