Show More
@@ -34,10 +34,25 b' def vlog(*msg):' | |||||
34 | print m, |
|
34 | print m, | |
35 |
|
35 | |||
36 |
|
36 | |||
|
37 | def splitnewlines(text): | |||
|
38 | '''like str.splitlines, but only split on newlines. | |||
|
39 | keep line endings.''' | |||
|
40 | i = 0 | |||
|
41 | lines = [] | |||
|
42 | while True: | |||
|
43 | n = text.find('\n', i) | |||
|
44 | if n == -1: | |||
|
45 | last = text[i:] | |||
|
46 | if last: | |||
|
47 | lines.append(last) | |||
|
48 | return lines | |||
|
49 | lines.append(text[i:n+1]) | |||
|
50 | i = n + 1 | |||
|
51 | ||||
37 | def show_diff(expected, output): |
|
52 | def show_diff(expected, output): | |
38 | for line in difflib.unified_diff(expected, output, |
|
53 | for line in difflib.unified_diff(expected, output, | |
39 | "Expected output", "Test output", lineterm=''): |
|
54 | "Expected output", "Test output", lineterm=''): | |
40 |
|
|
55 | sys.stdout.write(line) | |
41 |
|
56 | |||
42 | def find_program(program): |
|
57 | def find_program(program): | |
43 | """Search PATH for a executable program""" |
|
58 | """Search PATH for a executable program""" | |
@@ -125,7 +140,7 b' def output_coverage():' | |||||
125 | vlog("# Running: "+cmd) |
|
140 | vlog("# Running: "+cmd) | |
126 | os.system(cmd) |
|
141 | os.system(cmd) | |
127 |
|
142 | |||
128 | def run(cmd, split_lines=True): |
|
143 | def run(cmd): | |
129 | """Run command in a sub-process, capturing the output (stdout and stderr). |
|
144 | """Run command in a sub-process, capturing the output (stdout and stderr). | |
130 | Return the exist code, and output.""" |
|
145 | Return the exist code, and output.""" | |
131 | # TODO: Use subprocess.Popen if we're running on Python 2.4 |
|
146 | # TODO: Use subprocess.Popen if we're running on Python 2.4 | |
@@ -141,9 +156,7 b' def run(cmd, split_lines=True):' | |||||
141 | proc.tochild.close() |
|
156 | proc.tochild.close() | |
142 | output = proc.fromchild.read() |
|
157 | output = proc.fromchild.read() | |
143 | ret = proc.wait() |
|
158 | ret = proc.wait() | |
144 | if split_lines: |
|
159 | return ret, splitnewlines(output) | |
145 | output = output.splitlines() |
|
|||
146 | return ret, output |
|
|||
147 |
|
160 | |||
148 | def run_one(test): |
|
161 | def run_one(test): | |
149 | vlog("# Test", test) |
|
162 | vlog("# Test", test) | |
@@ -180,10 +193,10 b' def run_one(test):' | |||||
180 | # If reference output file exists, check test output against it |
|
193 | # If reference output file exists, check test output against it | |
181 | if os.path.exists(ref): |
|
194 | if os.path.exists(ref): | |
182 | f = open(ref, "r") |
|
195 | f = open(ref, "r") | |
183 |
ref_out = f.read() |
|
196 | ref_out = splitnewlines(f.read()) | |
184 | f.close() |
|
197 | f.close() | |
185 | else: |
|
198 | else: | |
186 | ref_out = '' |
|
199 | ref_out = [''] | |
187 | if out != ref_out: |
|
200 | if out != ref_out: | |
188 | diffret = 1 |
|
201 | diffret = 1 | |
189 | print "\nERROR: %s output changed" % (test) |
|
202 | print "\nERROR: %s output changed" % (test) | |
@@ -194,10 +207,9 b' def run_one(test):' | |||||
194 | ret = diffret |
|
207 | ret = diffret | |
195 |
|
208 | |||
196 | if ret != 0: # Save errors to a file for diagnosis |
|
209 | if ret != 0: # Save errors to a file for diagnosis | |
197 | f = open(err, "w") |
|
210 | f = open(err, "wb") | |
198 | for line in out: |
|
211 | for line in out: | |
199 | f.write(line) |
|
212 | f.write(line) | |
200 | f.write("\n") |
|
|||
201 | f.close() |
|
213 | f.close() | |
202 |
|
214 | |||
203 | os.chdir(TESTDIR) |
|
215 | os.chdir(TESTDIR) |
General Comments 0
You need to be logged in to leave comments.
Login now