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