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

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

Issue 10533085: Add a unit test for run_test_cases.py. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """Simulate a google-test executable.
7
8 http://code.google.com/p/googletest/
9 """
10
11 import optparse
12 import sys
13
14
15 TESTS = {
16 'Foo': ['Bar1', 'Bar2', 'Bar3'],
17 'Baz': ['Fail'],
18 }
19 TOTAL = sum(len(v) for v in TESTS.itervalues())
20
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
cmp 2012/06/12 16:32:10 nit: insert an empty line
M-A Ruel 2012/06/12 17:33:48 done
50 def main():
51 parser = optparse.OptionParser()
52 parser.add_option('--gtest_list_tests', action='store_true')
53 parser.add_option('--gtest_filter')
54 options, args = parser.parse_args()
55 if args:
56 parser.error('Failed to process args %s' % args)
57
58 if options.gtest_list_tests:
59 for fixture, cases in TESTS.iteritems():
60 print '%s.' % fixture
61 for case in cases:
62 print ' ' + case
63 print ' YOU HAVE 2 tests with ignored failures (FAILS prefix)'
64 print ''
65 return 0
66
67 if options.gtest_filter:
68 # Simulate running one test.
69 print 'Note: Google Test filter = %s\n' % options.gtest_filter
70 print get_test_output(options.gtest_filter)
71 print get_footer(1)
72 # Make Baz.Fail fail.
73 return options.gtest_filter == 'Baz.Fail'
74
75 for fixture, cases in TESTS.iteritems():
76 for case in cases:
77 print get_test_output('%s.%s' % (fixture, case))
78 print get_footer(TOTAL)
79 return 1
80
81
82 if __name__ == '__main__':
83 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698