Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 14 | 14 |
| 15 sys.path.append(os.path.join(ROOT_DIR, 'data', 'gtest_fake')) | 15 sys.path.append(os.path.join(ROOT_DIR, 'data', 'gtest_fake')) |
| 16 import gtest_fake | 16 import gtest_fake_base |
| 17 | |
| 18 | |
| 19 def RunTest(test_file): | |
| 20 target = os.path.join(ROOT_DIR, 'data', 'gtest_fake', test_file) | |
| 21 cmd = [ | |
| 22 sys.executable, | |
| 23 os.path.join(ROOT_DIR, 'run_test_cases.py'), | |
| 24 '--no-dump', | |
| 25 target, | |
| 26 ] | |
| 27 logging.debug(' '.join(cmd)) | |
| 28 proc = subprocess.Popen( | |
| 29 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 30 # pylint is confused. | |
| 31 out, err = proc.communicate() or ('', '') | |
| 32 | |
| 33 return_code = proc.returncode | |
| 34 | |
| 35 return (out, err, return_code) | |
|
M-A Ruel
2012/07/25 16:03:20
Replace lines 32-35 with:
return (out, err, proc.r
csharp
2012/07/25 16:55:22
Done.
| |
| 17 | 36 |
| 18 | 37 |
| 19 class TraceTestCases(unittest.TestCase): | 38 class TraceTestCases(unittest.TestCase): |
| 20 def setUp(self): | 39 def setUp(self): |
| 21 # Make sure there's no environment variable that could do side effects. | 40 # Make sure there's no environment variable that could do side effects. |
| 22 os.environ.pop('GTEST_SHARD_INDEX', '') | 41 os.environ.pop('GTEST_SHARD_INDEX', '') |
| 23 os.environ.pop('GTEST_TOTAL_SHARDS', '') | 42 os.environ.pop('GTEST_TOTAL_SHARDS', '') |
| 24 | 43 |
| 25 def test_simple(self): | 44 def _check_results(self, expected_out_re, out, err): |
| 26 target = os.path.join(ROOT_DIR, 'data', 'gtest_fake', 'gtest_fake.py') | |
| 27 cmd = [ | |
| 28 sys.executable, | |
| 29 os.path.join(ROOT_DIR, 'run_test_cases.py'), | |
| 30 '--no-dump', | |
| 31 target, | |
| 32 ] | |
| 33 logging.debug(' '.join(cmd)) | |
| 34 proc = subprocess.Popen( | |
| 35 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 36 # pylint is confused. | |
| 37 out, err = proc.communicate() or ('', '') | |
| 38 self.assertEquals(0, proc.returncode) | |
| 39 if sys.platform == 'win32': | 45 if sys.platform == 'win32': |
| 40 out = out.replace('\r\n', '\n') | 46 out = out.replace('\r\n', '\n') |
| 41 lines = out.splitlines() | 47 lines = out.splitlines() |
| 48 | |
| 49 for index in range(len(expected_out_re)): | |
| 50 line = lines.pop(0) | |
| 51 self.assertTrue( | |
| 52 re.match('^%s$' % expected_out_re[index], line), | |
| 53 (index, expected_out_re[index], repr(line))) | |
| 54 self.assertEquals([], lines) | |
| 55 self.assertEquals('', err) | |
| 56 | |
| 57 def test_simple_pass(self): | |
| 58 out, err, return_code = RunTest('gtest_fake_pass.py') | |
| 59 | |
| 60 self.assertEquals(0, return_code) | |
| 61 | |
| 42 expected_out_re = [ | 62 expected_out_re = [ |
| 43 r'\[\d/\d\] \d\.\d\ds .+', | 63 r'\[\d/\d\] \d\.\d\ds .+', |
| 44 r'\[\d/\d\] \d\.\d\ds .+', | 64 r'\[\d/\d\] \d\.\d\ds .+', |
| 65 r'\[\d/\d\] \d\.\d\ds .+', | |
| 66 re.escape('Success: 3 100.00%'), | |
| 67 re.escape('Flaky: 0 0.00%'), | |
| 68 re.escape('Fail: 0 0.00%'), | |
| 69 r'\d+\.\ds Done running 3 tests with 3 executions. \d+\.\d test/s', | |
| 70 ] | |
| 71 | |
| 72 self._check_results(expected_out_re, out, err) | |
| 73 | |
| 74 def test_simple_fail(self): | |
| 75 out, err, return_code = RunTest('gtest_fake_fail.py') | |
| 76 | |
| 77 self.assertEquals(1, return_code) | |
| 78 | |
| 79 expected_out_re = [ | |
| 80 r'\[\d/\d\] \d\.\d\ds .+', | |
| 81 r'\[\d/\d\] \d\.\d\ds .+', | |
| 45 r'\[\d/\d\] \d\.\d\ds .+', | 82 r'\[\d/\d\] \d\.\d\ds .+', |
| 46 r'\[\d/\d\] \d\.\d\ds .+', | 83 r'\[\d/\d\] \d\.\d\ds .+', |
| 47 r'\[\d/\d\] \d\.\d\ds .+', | 84 r'\[\d/\d\] \d\.\d\ds .+', |
| 48 r'\[\d/\d\] \d\.\d\ds .+', | 85 r'\[\d/\d\] \d\.\d\ds .+', |
| 49 re.escape('Note: Google Test filter = Baz.Fail'), | 86 re.escape('Note: Google Test filter = Baz.Fail'), |
| 50 r'', | 87 r'', |
| 51 ] + [ | 88 ] + [ |
| 52 re.escape(l) for l in gtest_fake.get_test_output('Baz.Fail').splitlines() | 89 re.escape(l) for l in |
| 90 gtest_fake_base.get_test_output('Baz.Fail').splitlines() | |
| 53 ] + [ | 91 ] + [ |
| 54 '', | 92 '', |
| 55 ] + [ | 93 ] + [ |
| 56 re.escape(l) for l in gtest_fake.get_footer(1).splitlines() | 94 re.escape(l) for l in gtest_fake_base.get_footer(1, 1).splitlines() |
| 57 ] + [ | 95 ] + [ |
| 58 '', | 96 '', |
| 59 re.escape('Success: 3 75.00%'), | 97 re.escape('Success: 3 75.00%'), |
| 60 re.escape('Flaky: 0 0.00%'), | 98 re.escape('Flaky: 0 0.00%'), |
| 61 re.escape('Fail: 1 25.00%'), | 99 re.escape('Fail: 1 25.00%'), |
| 62 r'\d+\.\ds Done running 4 tests with 6 executions. \d+\.\d test/s', | 100 r'\d+\.\ds Done running 4 tests with 6 executions. \d+\.\d test/s', |
| 63 ] | 101 ] |
| 64 for index in range(len(expected_out_re)): | 102 self._check_results(expected_out_re, out, err) |
| 65 line = lines.pop(0) | |
| 66 self.assertTrue( | |
| 67 re.match('^%s$' % expected_out_re[index], line), | |
| 68 (index, expected_out_re[index], repr(line))) | |
| 69 self.assertEquals([], lines) | |
| 70 self.assertEquals('', err) | |
| 71 | 103 |
| 72 | 104 |
| 73 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 74 VERBOSE = '-v' in sys.argv | 106 VERBOSE = '-v' in sys.argv |
| 75 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 107 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 76 unittest.main() | 108 unittest.main() |
| OLD | NEW |