| 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 """Simulate a google-test executable. | 6 """Simulate a failing google-test executable. |
| 7 | 7 |
| 8 http://code.google.com/p/googletest/ | 8 http://code.google.com/p/googletest/ |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import optparse | 11 import optparse |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 import gtest_fake_base |
| 15 |
| 14 | 16 |
| 15 TESTS = { | 17 TESTS = { |
| 16 'Foo': ['Bar1', 'Bar2', 'Bar3'], | 18 'Foo': ['Bar1', 'Bar2', 'Bar3'], |
| 17 'Baz': ['Fail'], | 19 'Baz': ['Fail'], |
| 18 } | 20 } |
| 19 TOTAL = sum(len(v) for v in TESTS.itervalues()) | 21 TOTAL = sum(len(v) for v in TESTS.itervalues()) |
| 20 | 22 |
| 21 | |
| 22 def get_test_output(test_name): | |
| 23 fixture, case = test_name.split('.', 1) | |
| 24 return ( | |
| 25 '[==========] Running 1 test from 1 test case.\n' | |
| 26 '[----------] Global test environment set-up.\n' | |
| 27 '[----------] 1 test from %(fixture)s\n' | |
| 28 '[ RUN ] %(fixture)s.%(case)s\n' | |
| 29 '[ OK ] %(fixture)s.%(case)s (0 ms)\n' | |
| 30 '[----------] 1 test from %(fixture)s (0 ms total)\n' | |
| 31 '\n') % { | |
| 32 'fixture': fixture, | |
| 33 'case': case, | |
| 34 } | |
| 35 | |
| 36 | |
| 37 def get_footer(number): | |
| 38 return ( | |
| 39 '[----------] Global test environment tear-down\n' | |
| 40 '[==========] %(number)d test from %(total)d test case ran. (0 ms total)\n' | |
| 41 '[ PASSED ] %(number)d test.\n' | |
| 42 '\n' | |
| 43 ' YOU HAVE 5 DISABLED TESTS\n' | |
| 44 '\n' | |
| 45 ' YOU HAVE 2 tests with ignored failures (FAILS prefix)\n') % { | |
| 46 'number': number, | |
| 47 'total': TOTAL, | |
| 48 } | |
| 49 | |
| 50 | |
| 51 def main(): | 23 def main(): |
| 52 parser = optparse.OptionParser() | 24 parser = optparse.OptionParser() |
| 53 parser.add_option('--gtest_list_tests', action='store_true') | 25 parser.add_option('--gtest_list_tests', action='store_true') |
| 54 parser.add_option('--gtest_filter') | 26 parser.add_option('--gtest_filter') |
| 55 options, args = parser.parse_args() | 27 options, args = parser.parse_args() |
| 56 if args: | 28 if args: |
| 57 parser.error('Failed to process args %s' % args) | 29 parser.error('Failed to process args %s' % args) |
| 58 | 30 |
| 59 if options.gtest_list_tests: | 31 if options.gtest_list_tests: |
| 60 for fixture, cases in TESTS.iteritems(): | 32 for fixture, cases in TESTS.iteritems(): |
| 61 print '%s.' % fixture | 33 print '%s.' % fixture |
| 62 for case in cases: | 34 for case in cases: |
| 63 print ' ' + case | 35 print ' ' + case |
| 64 print ' YOU HAVE 2 tests with ignored failures (FAILS prefix)' | 36 print ' YOU HAVE 2 tests with ignored failures (FAILS prefix)' |
| 65 print '' | 37 print '' |
| 66 return 0 | 38 return 0 |
| 67 | 39 |
| 68 if options.gtest_filter: | 40 if options.gtest_filter: |
| 69 # Simulate running one test. | 41 # Simulate running one test. |
| 70 print 'Note: Google Test filter = %s\n' % options.gtest_filter | 42 print 'Note: Google Test filter = %s\n' % options.gtest_filter |
| 71 print get_test_output(options.gtest_filter) | 43 print gtest_fake_base.get_test_output(options.gtest_filter) |
| 72 print get_footer(1) | 44 print gtest_fake_base.get_footer(1, 1) |
| 73 # Make Baz.Fail fail. | 45 # Make Baz.Fail fail. |
| 74 return options.gtest_filter == 'Baz.Fail' | 46 return options.gtest_filter == 'Baz.Fail' |
| 75 | 47 |
| 76 for fixture, cases in TESTS.iteritems(): | 48 for fixture, cases in TESTS.iteritems(): |
| 77 for case in cases: | 49 for case in cases: |
| 78 print get_test_output('%s.%s' % (fixture, case)) | 50 print gtest_fake_base.get_test_output('%s.%s' % (fixture, case)) |
| 79 print get_footer(TOTAL) | 51 print gtest_fake_base.get_footer(TOTAL, TOTAL) |
| 80 return 1 | 52 return 1 |
| 81 | 53 |
| 82 | 54 |
| 83 if __name__ == '__main__': | 55 if __name__ == '__main__': |
| 84 sys.exit(main()) | 56 sys.exit(main()) |
| OLD | NEW |