-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
repeat.py
46 lines (36 loc) · 1 KB
/
repeat.py
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
import subprocess
import difflib
import sys
count = int(sys.argv[1])
cmd = sys.argv[2:]
counter = 0
next_print = 1
error = 0
expected = None
for counter in range(1, count + 1):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
out, err = p.communicate('')
out += err or ''
if expected is None:
expected = out
continue
failed = False
if p.wait() != 0:
failed = True
sys.stderr.write("Return code: %s\n" % p.wait())
if expected != out:
failed = True
sys.stderr.write('\nOutput changed:\n\n')
d = difflib.Differ()
diff = d.compare(expected.split('\n'), out.split('\n'))
sys.stderr.write('\n'.join(diff) + '\n')
if failed:
error += 1
if counter >= next_print or failed:
sys.stderr.write("%s failed out of%5s\n" % (error, counter))
if counter >= next_print:
next_print *= 2
if error:
break
if error:
sys.exit(1)