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

Side by Side Diff: tools/mb/mb_unittest.py

Issue 1074583002: Testing and bugfixing for the new MB gyp/gn wrapper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clarify comments Created 5 years, 8 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
« tools/mb/mb.py ('K') | « tools/mb/mb_config.pyl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Tests for mb.py.""" 5 """Tests for mb.py."""
6 6
7 import json
7 import sys 8 import sys
8 import unittest 9 import unittest
9 10
10 import mb 11 import mb
11 12
12 13
13 class FakeMB(mb.MetaBuildWrapper): 14 class FakeMBW(mb.MetaBuildWrapper):
14 def __init__(self): 15 def __init__(self):
15 super(FakeMB, self).__init__() 16 super(FakeMBW, self).__init__()
16 self.files = {} 17 self.files = {}
17 self.calls = [] 18 self.calls = []
18 self.out = [] 19 self.out = ''
19 self.err = [] 20 self.err = ''
20 self.chromium_src_dir = '/fake_src' 21 self.chromium_src_dir = '/fake_src'
21 self.default_config = '/fake_src/tools/mb/mb_config.pyl' 22 self.default_config = '/fake_src/tools/mb/mb_config.pyl'
22 23
23 def ExpandUser(self, path): 24 def ExpandUser(self, path):
24 return '$HOME/%s' % path 25 return '$HOME/%s' % path
25 26
26 def Exists(self, path): 27 def Exists(self, path):
27 return self.files.get(path) is not None 28 return self.files.get(path) is not None
28 29
29 def ReadFile(self, path): 30 def ReadFile(self, path):
30 return self.files[path] 31 return self.files[path]
31 32
32 def WriteFile(self, path, contents): 33 def WriteFile(self, path, contents):
33 self.files[path] = contents 34 self.files[path] = contents
34 35
35 def Call(self, cmd): 36 def Call(self, cmd):
36 self.calls.append(cmd) 37 self.calls.append(cmd)
37 return 0, '', '' 38 return 0, '', ''
38 39
39 def Print(self, *args, **kwargs): 40 def Print(self, *args, **kwargs):
40 sep = kwargs.get('sep', ' ') 41 sep = kwargs.get('sep', ' ')
41 end = kwargs.get('end', '\n') 42 end = kwargs.get('end', '\n')
42 f = kwargs.get('file', sys.stdout) 43 f = kwargs.get('file', sys.stdout)
43 if f == sys.stderr: 44 if f == sys.stderr:
44 self.err.append(sep.join(args) + end) 45 self.err += sep.join(args) + end
45 else: 46 else:
46 self.out.append(sep.join(args) + end) 47 self.out += sep.join(args) + end
47 48
48 class IntegrationTest(unittest.TestCase): 49 class IntegrationTest(unittest.TestCase):
49 def test_validate(self): 50 def test_validate(self):
50 # Note that this validates that the actual mb_config.pyl is valid. 51 # Note that this validates that the actual mb_config.pyl is valid.
51 ret = mb.main(['validate', '--quiet']) 52 ret = mb.main(['validate', '--quiet'])
52 self.assertEqual(ret, 0) 53 self.assertEqual(ret, 0)
53 54
54 55
55 TEST_CONFIG = """\ 56 TEST_CONFIG = """\
56 { 57 {
57 'common_dev_configs': ['gn_debug'], 58 'common_dev_configs': ['gn_debug'],
58 'configs': { 59 'configs': {
59 'gyp_rel_bot': ['gyp', 'rel', 'goma'], 60 'gyp_rel_bot': ['gyp', 'rel', 'goma'],
60 'gn_debug': ['gn', 'debug'], 61 'gn_debug': ['gn', 'debug'],
62 'gn_rel_bot': ['gn', 'rel', 'goma'],
61 'private': ['gyp', 'fake_feature1'], 63 'private': ['gyp', 'fake_feature1'],
62 'unsupported': ['gn', 'fake_feature2'], 64 'unsupported': ['gn', 'fake_feature2'],
63 }, 65 },
64 'masters': { 66 'masters': {
65 'fake_master': { 67 'fake_master': {
66 'fake_builder': 'gyp_rel_bot', 68 'fake_builder': 'gyp_rel_bot',
69 'fake_gn_builder': 'gn_rel_bot',
67 }, 70 },
68 }, 71 },
69 'mixins': { 72 'mixins': {
70 'fake_feature1': { 73 'fake_feature1': {
71 'gn_args': 'enable_doom_melon=true', 74 'gn_args': 'enable_doom_melon=true',
72 'gyp_defines': 'doom_melon=1', 75 'gyp_defines': 'doom_melon=1',
73 }, 76 },
74 'fake_feature2': { 77 'fake_feature2': {
75 'gn_args': 'enable_doom_melon=false', 78 'gn_args': 'enable_doom_melon=false',
76 'gyp_defaults': 'doom_melon=0', 79 'gyp_defaults': 'doom_melon=0',
(...skipping 12 matching lines...) Expand all
89 'gn_args': 'is_debug=true', 92 'gn_args': 'is_debug=true',
90 }, 93 },
91 }, 94 },
92 'private_configs': ['private'], 95 'private_configs': ['private'],
93 'unsupported_configs': ['unsupported'], 96 'unsupported_configs': ['unsupported'],
94 } 97 }
95 """ 98 """
96 99
97 100
98 class UnitTest(unittest.TestCase): 101 class UnitTest(unittest.TestCase):
99 def check(self, args, files=None, cmds=None, out=None, err=None, ret=None): 102 def fake_mbw(self, files):
100 m = FakeMB() 103 mbw = FakeMBW()
101 if files: 104 if files:
102 for path, contents in files.items(): 105 for path, contents in files.items():
103 m.files[path] = contents 106 mbw.files[path] = contents
104 m.files.setdefault(mb.default_config, TEST_CONFIG) 107 mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
105 m.ParseArgs(args) 108 return mbw
106 actual_ret = m.args.func() 109
110 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None):
111 if not mbw:
112 mbw = self.fake_mbw(files)
113 mbw.ParseArgs(args)
114 actual_ret = mbw.args.func()
107 if ret is not None: 115 if ret is not None:
108 self.assertEqual(actual_ret, ret) 116 self.assertEqual(actual_ret, ret)
109 if out is not None: 117 if out is not None:
110 self.assertEqual(m.out, out) 118 self.assertEqual(mbw.out, out)
111 if err is not None: 119 if err is not None:
112 self.assertEqual(m.err, err) 120 self.assertEqual(mbw.err, err)
113 if cmds is not None: 121 return mbw
114 self.assertEqual(m.cmds, cmds)
115 122
116 def test_analyze(self): 123 def test_gn_analyze(self):
117 files = {'/tmp/in.json': '{"files": [], "targets": []}'} 124 files = {'/tmp/in.json': """{\
125 "files": ["foo/foo_unittest.cc"],
126 "targets": ["foo_unittests", "bar_unittests"]
127 }"""}
128 mbw = self.fake_mbw(files)
129 mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '')
130
118 self.check(['analyze', '-c', 'gn_debug', '//out/Default', 131 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
119 '/tmp/in.json', '/tmp/out.json'], 132 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
120 files=files, ret=0) 133 out = json.loads(mbw.files['/tmp/out.json'])
134 self.assertEqual(out, {
135 'status': 'Found dependency',
136 'targets': ['foo_unittests'],
137 'build_targets': ['foo_unittests']
138 })
139
140 def test_gyp_analyze(self):
121 self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', 141 self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release',
122 '/tmp/in.json', '/tmp/out.json'], 142 '/tmp/in.json', '/tmp/out.json'],
123 ret=0) 143 ret=0)
124 144
125 def test_gen(self): 145 def test_gen(self):
126 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0) 146 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0)
127 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) 147 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0)
128 148
149 def test_goma_dir_expansion(self):
150 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0,
151 out=("python build/gyp_chromium -G 'output_dir=<path>' "
152 "-G config=Release -D goma=1 -D gomadir=/foo\n"))
153 self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0,
154 out=("gn gen '<path>' '--args=is_debug=false use_goma=true "
155 "goma_dir=\"/foo\"'\n" ))
156
129 def test_help(self): 157 def test_help(self):
130 self.assertRaises(SystemExit, self.check, ['-h']) 158 self.assertRaises(SystemExit, self.check, ['-h'])
131 self.assertRaises(SystemExit, self.check, ['help']) 159 self.assertRaises(SystemExit, self.check, ['help'])
132 self.assertRaises(SystemExit, self.check, ['help', 'gen']) 160 self.assertRaises(SystemExit, self.check, ['help', 'gen'])
133 161
134 def test_lookup(self): 162 def test_lookup(self):
135 self.check(['lookup', '-c', 'gn_debug'], ret=0) 163 self.check(['lookup', '-c', 'gn_debug'], ret=0)
136 164
137 def test_validate(self): 165 def test_validate(self):
138 self.check(['validate'], ret=0) 166 self.check(['validate'], ret=0)
139 167
140 168
141 if __name__ == '__main__': 169 if __name__ == '__main__':
142 unittest.main() 170 unittest.main()
OLDNEW
« tools/mb/mb.py ('K') | « tools/mb/mb_config.pyl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698