OLD | NEW |
---|---|
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 json |
8 import sys | 8 import sys |
9 import unittest | 9 import unittest |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 'gn_args': 'is_debug=true', | 93 'gn_args': 'is_debug=true', |
94 }, | 94 }, |
95 }, | 95 }, |
96 'private_configs': ['private'], | 96 'private_configs': ['private'], |
97 'unsupported_configs': ['unsupported'], | 97 'unsupported_configs': ['unsupported'], |
98 } | 98 } |
99 """ | 99 """ |
100 | 100 |
101 | 101 |
102 class UnitTest(unittest.TestCase): | 102 class UnitTest(unittest.TestCase): |
103 def fake_mbw(self, files): | 103 def fake_mbw(self, files=None): |
104 mbw = FakeMBW() | 104 mbw = FakeMBW() |
105 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) | |
Dirk Pranke
2015/04/24 20:38:52
these diffs are unrelated to the fix, but clean up
| |
105 if files: | 106 if files: |
106 for path, contents in files.items(): | 107 for path, contents in files.items(): |
107 mbw.files[path] = contents | 108 mbw.files[path] = contents |
108 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) | |
109 return mbw | 109 return mbw |
110 | 110 |
111 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): | 111 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): |
112 if not mbw: | 112 if not mbw: |
113 mbw = self.fake_mbw(files) | 113 mbw = self.fake_mbw(files) |
114 mbw.ParseArgs(args) | 114 mbw.ParseArgs(args) |
115 actual_ret = mbw.args.func() | 115 actual_ret = mbw.args.func() |
116 if ret is not None: | 116 if ret is not None: |
117 self.assertEqual(actual_ret, ret) | 117 self.assertEqual(actual_ret, ret) |
118 if out is not None: | 118 if out is not None: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 173 |
174 def test_gyp_analyze(self): | 174 def test_gyp_analyze(self): |
175 self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', | 175 self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', |
176 '/tmp/in.json', '/tmp/out.json'], | 176 '/tmp/in.json', '/tmp/out.json'], |
177 ret=0) | 177 ret=0) |
178 | 178 |
179 def test_gen(self): | 179 def test_gen(self): |
180 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0) | 180 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0) |
181 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) | 181 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) |
182 | 182 |
183 def test_gen_fails(self): | |
184 mbw = self.fake_mbw() | |
185 mbw.Call = lambda cmd: (1, '', '') | |
186 self.check(['gen', '-c', 'gn_debug', '//out/Default'], mbw=mbw, ret=1) | |
187 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], mbw=mbw, ret=1) | |
188 | |
183 def test_goma_dir_expansion(self): | 189 def test_goma_dir_expansion(self): |
184 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0, | 190 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0, |
185 out=("python build/gyp_chromium -G 'output_dir=<path>' " | 191 out=("python build/gyp_chromium -G 'output_dir=<path>' " |
186 "-G config=Release -D goma=1 -D gomadir=/foo\n")) | 192 "-G config=Release -D goma=1 -D gomadir=/foo\n")) |
187 self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0, | 193 self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0, |
188 out=("/fake_src/buildtools/linux64/gn gen '<path>' " | 194 out=("/fake_src/buildtools/linux64/gn gen '<path>' " |
189 "'--args=is_debug=false use_goma=true " | 195 "'--args=is_debug=false use_goma=true " |
190 "goma_dir=\"/foo\"'\n" )) | 196 "goma_dir=\"/foo\"'\n" )) |
191 | 197 |
192 def test_help(self): | 198 def test_help(self): |
193 self.assertRaises(SystemExit, self.check, ['-h']) | 199 self.assertRaises(SystemExit, self.check, ['-h']) |
194 self.assertRaises(SystemExit, self.check, ['help']) | 200 self.assertRaises(SystemExit, self.check, ['help']) |
195 self.assertRaises(SystemExit, self.check, ['help', 'gen']) | 201 self.assertRaises(SystemExit, self.check, ['help', 'gen']) |
196 | 202 |
197 def test_lookup(self): | 203 def test_lookup(self): |
198 self.check(['lookup', '-c', 'gn_debug'], ret=0) | 204 self.check(['lookup', '-c', 'gn_debug'], ret=0) |
199 | 205 |
200 def test_validate(self): | 206 def test_validate(self): |
201 self.check(['validate'], ret=0) | 207 self.check(['validate'], ret=0) |
202 | 208 |
203 | 209 |
204 if __name__ == '__main__': | 210 if __name__ == '__main__': |
205 unittest.main() | 211 unittest.main() |
OLD | NEW |