OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Implements a simple "negative compile" test for C++ on linux. | 6 """Implements a simple "negative compile" test for C++ on linux. |
7 | 7 |
8 Sometimes a C++ API needs to ensure that various usages cannot compile. To | 8 Sometimes a C++ API needs to ensure that various usages cannot compile. To |
9 enable unittesting of these assertions, we use this python script to | 9 enable unittesting of these assertions, we use this python script to |
10 invoke gcc on a source file and assert that compilation fails. | 10 invoke gcc on a source file and assert that compilation fails. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 def FailTest(resultfile, test, error, stdout=None, stderr=None): | 266 def FailTest(resultfile, test, error, stdout=None, stderr=None): |
267 """Logs the result of a test started by StartTest() | 267 """Logs the result of a test started by StartTest() |
268 | 268 |
269 Args: | 269 Args: |
270 resultfile: File object for .cc file that results are written to. | 270 resultfile: File object for .cc file that results are written to. |
271 test: An instance of the dictionary returned by StartTest() | 271 test: An instance of the dictionary returned by StartTest() |
272 error: The printable reason for the failure. | 272 error: The printable reason for the failure. |
273 stdout: The test's output to stdout. | 273 stdout: The test's output to stdout. |
274 stderr: The test's output to stderr. | 274 stderr: The test's output to stderr. |
275 """ | 275 """ |
276 resultfile.write('#error %s Failed: %s\n' % (test['name'], error)) | 276 resultfile.write('#error "%s Failed: %s"\n' % (test['name'], error)) |
277 resultfile.write('#error compile line: %s\n' % test['cmdline']) | 277 resultfile.write('#error "compile line: %s"\n' % test['cmdline']) |
278 if stdout and len(stdout) != 0: | 278 if stdout and len(stdout) != 0: |
279 resultfile.write('#error %s stdout:\n' % test['name']) | 279 resultfile.write('#error "%s stdout:"\n' % test['name']) |
280 for line in stdout.split('\n'): | 280 for line in stdout.split('\n'): |
281 resultfile.write('#error %s\n' % line) | 281 resultfile.write('#error " %s:"\n' % line) |
282 | 282 |
283 if stderr and len(stderr) != 0: | 283 if stderr and len(stderr) != 0: |
284 resultfile.write('#error %s stderr:\n' % test['name']) | 284 resultfile.write('#error "%s stderr:"\n' % test['name']) |
285 for line in stderr.split('\n'): | 285 for line in stderr.split('\n'): |
286 resultfile.write('#error %s\n' % line) | 286 resultfile.write('#error " %s"\n' % line) |
287 resultfile.write('\n') | 287 resultfile.write('\n') |
288 | 288 |
289 | 289 |
290 def WriteStats(resultfile, suite_name, timings): | 290 def WriteStats(resultfile, suite_name, timings): |
291 """Logs the peformance timings for each stage of the script into a fake test. | 291 """Logs the peformance timings for each stage of the script into a fake test. |
292 | 292 |
293 Args: | 293 Args: |
294 resultfile: File object for .cc file that results are written to. | 294 resultfile: File object for .cc file that results are written to. |
295 suite_name: The name of the GUnit suite this test belongs to. | 295 suite_name: The name of the GUnit suite this test belongs to. |
296 timings: Dictionary with timestamps for each stage of the script run. | 296 timings: Dictionary with timestamps for each stage of the script run. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 timings['results_processed'] = time.time() | 463 timings['results_processed'] = time.time() |
464 | 464 |
465 # We always know at least a sanity test was run. | 465 # We always know at least a sanity test was run. |
466 WriteStats(resultfile, finished_tests[0]['suite_name'], timings) | 466 WriteStats(resultfile, finished_tests[0]['suite_name'], timings) |
467 | 467 |
468 resultfile.close() | 468 resultfile.close() |
469 | 469 |
470 | 470 |
471 if __name__ == '__main__': | 471 if __name__ == '__main__': |
472 main() | 472 main() |
OLD | NEW |