Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: tools/isolate/data/gtest_fake/gtest_fake_fail.py

Issue 10825010: Run_test_case.py now returns 1 when at least 1 test fails. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23
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(): 24 def main():
52 parser = optparse.OptionParser() 25 parser = optparse.OptionParser()
53 parser.add_option('--gtest_list_tests', action='store_true') 26 parser.add_option('--gtest_list_tests', action='store_true')
54 parser.add_option('--gtest_filter') 27 parser.add_option('--gtest_filter')
55 options, args = parser.parse_args() 28 options, args = parser.parse_args()
56 if args: 29 if args:
57 parser.error('Failed to process args %s' % args) 30 parser.error('Failed to process args %s' % args)
58 31
59 if options.gtest_list_tests: 32 if options.gtest_list_tests:
60 for fixture, cases in TESTS.iteritems(): 33 for fixture, cases in TESTS.iteritems():
61 print '%s.' % fixture 34 print '%s.' % fixture
62 for case in cases: 35 for case in cases:
63 print ' ' + case 36 print ' ' + case
64 print ' YOU HAVE 2 tests with ignored failures (FAILS prefix)' 37 print ' YOU HAVE 2 tests with ignored failures (FAILS prefix)'
65 print '' 38 print ''
66 return 0 39 return 0
67 40
68 if options.gtest_filter: 41 if options.gtest_filter:
69 # Simulate running one test. 42 # Simulate running one test.
70 print 'Note: Google Test filter = %s\n' % options.gtest_filter 43 print 'Note: Google Test filter = %s\n' % options.gtest_filter
71 print get_test_output(options.gtest_filter) 44 print gtest_fake_base.get_test_output(options.gtest_filter)
72 print get_footer(1) 45 print gtest_fake_base.get_footer(1, 1)
73 # Make Baz.Fail fail. 46 # Make Baz.Fail fail.
74 return options.gtest_filter == 'Baz.Fail' 47 return options.gtest_filter == 'Baz.Fail'
75 48
76 for fixture, cases in TESTS.iteritems(): 49 for fixture, cases in TESTS.iteritems():
77 for case in cases: 50 for case in cases:
78 print get_test_output('%s.%s' % (fixture, case)) 51 print gtest_fake_base.get_test_output('%s.%s' % (fixture, case))
79 print get_footer(TOTAL) 52 print gtest_fake_base.get_footer(TOTAL, TOTAL)
80 return 1 53 return 1
81 54
82 55
83 if __name__ == '__main__': 56 if __name__ == '__main__':
84 sys.exit(main()) 57 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/isolate/data/gtest_fake/gtest_fake_base.py ('k') | tools/isolate/data/gtest_fake/gtest_fake_pass.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698