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

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

Issue 1440173002: Update MB for the new way to run 'analyze'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: original patch for review Created 5 years, 1 month 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/docs/design_spec.md ('K') | « tools/mb/mb.py ('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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 """Tests for mb.py.""" 6 """Tests for mb.py."""
7 7
8 import json 8 import json
9 import StringIO 9 import StringIO
10 import os 10 import os
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 self.check(['analyze', '-c', 'gn_debug', '//out/Default', 214 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
215 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 215 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
216 out = json.loads(mbw.files['/tmp/out.json']) 216 out = json.loads(mbw.files['/tmp/out.json'])
217 self.assertEqual(out, { 217 self.assertEqual(out, {
218 'status': 'Found dependency', 218 'status': 'Found dependency',
219 'targets': ['foo_unittests'], 219 'targets': ['foo_unittests'],
220 'build_targets': ['foo_unittests'] 220 'build_targets': ['foo_unittests']
221 }) 221 })
222 222
223 def test_gn_analyze_new_logic(self):
224 files = {'/tmp/in.json': """{\
225 "files": ["foo/foo_unittest.cc"],
226 "test_targets": ["foo_unittests", "bar_unittests"],
227 "additional_compile_targets": []
228 }"""}
229
230 mbw = self.fake_mbw(files)
231 mbw.Call = lambda cmd, env=None, buffer_output=True: (
232 0, 'out/Default/foo_unittests\n', '')
233
234 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
235 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
236 out = json.loads(mbw.files['/tmp/out.json'])
237 self.assertEqual(out, {
238 'status': 'Found dependency',
239 'compile_targets': ['foo_unittests'],
240 'test_targets': ['foo_unittests']
241 })
242
223 def test_gn_analyze_all(self): 243 def test_gn_analyze_all(self):
224 files = {'/tmp/in.json': """{\ 244 files = {'/tmp/in.json': """{\
225 "files": ["foo/foo_unittest.cc"], 245 "files": ["foo/foo_unittest.cc"],
226 "targets": ["all", "bar_unittests"] 246 "targets": ["all", "bar_unittests"]
227 }"""} 247 }"""}
228 mbw = self.fake_mbw(files) 248 mbw = self.fake_mbw(files)
229 mbw.Call = lambda cmd, env=None, buffer_output=True: ( 249 mbw.Call = lambda cmd, env=None, buffer_output=True: (
230 0, 'out/Default/foo_unittests\n', '') 250 0, 'out/Default/foo_unittests\n', '')
231 self.check(['analyze', '-c', 'gn_debug', '//out/Default', 251 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
232 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 252 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
233 out = json.loads(mbw.files['/tmp/out.json']) 253 out = json.loads(mbw.files['/tmp/out.json'])
234 self.assertEqual(out, { 254 self.assertEqual(out, {
235 'status': 'Found dependency (all)', 255 'status': 'Found dependency (all)',
236 }) 256 })
237 257
258 def test_gn_analyze_all_new_logic(self):
259 files = {'/tmp/in.json': """{\
260 "files": ["foo/foo_unittest.cc"],
261 "test_targets": ["bar_unittests"],
262 "additional_compile_targets": ["all"]
263 }"""}
264 mbw = self.fake_mbw(files)
265 mbw.Call = lambda cmd, env=None, buffer_output=True: (
266 0, 'out/Default/foo_unittests\n', '')
267 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
268 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
269 out = json.loads(mbw.files['/tmp/out.json'])
270 self.assertEqual(out, {
271 'status': 'Found dependency (all)',
272 'compile_targets': ['all', 'bar_unittests'],
273 'test_targets': ['bar_unittests'],
274 })
275
238 def test_gn_analyze_missing_file(self): 276 def test_gn_analyze_missing_file(self):
239 files = {'/tmp/in.json': """{\ 277 files = {'/tmp/in.json': """{\
240 "files": ["foo/foo_unittest.cc"], 278 "files": ["foo/foo_unittest.cc"],
241 "targets": ["bar_unittests"] 279 "targets": ["bar_unittests"]
242 }"""} 280 }"""}
243 mbw = self.fake_mbw(files) 281 mbw = self.fake_mbw(files)
244 mbw.cmds = [ 282 mbw.cmds = [
245 (0, '', ''), 283 (0, '', ''),
246 (1, 'The input matches no targets, configs, or files\n', ''), 284 (1, 'The input matches no targets, configs, or files\n', ''),
247 (1, 'The input matches no targets, configs, or files\n', ''), 285 (1, 'The input matches no targets, configs, or files\n', ''),
248 ] 286 ]
249 287
250 self.check(['analyze', '-c', 'gn_debug', '//out/Default', 288 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
251 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 289 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
252 out = json.loads(mbw.files['/tmp/out.json']) 290 out = json.loads(mbw.files['/tmp/out.json'])
253 self.assertEqual(out, { 291 self.assertEqual(out, {
254 'build_targets': [], 292 'build_targets': [],
255 'targets': [], 293 'targets': [],
256 'status': 'No dependency', 294 'status': 'No dependency',
257 }) 295 })
258 296
297 def test_gn_analyze_missing_file_new_logic(self):
298 files = {'/tmp/in.json': """{\
299 "files": ["foo/foo_unittest.cc"],
300 "test_targets": ["bar_unittests"],
301 "additional_compile_targets": []
302 }"""}
303 mbw = self.fake_mbw(files)
304 mbw.cmds = [
305 (0, '', ''),
306 (1, 'The input matches no targets, configs, or files\n', ''),
307 (1, 'The input matches no targets, configs, or files\n', ''),
308 ]
309
310 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
311 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
312 out = json.loads(mbw.files['/tmp/out.json'])
313 self.assertEqual(out, {
314 'status': 'No dependency',
315 'compile_targets': [],
316 'test_targets': [],
317 })
318
259 def test_gn_gen(self): 319 def test_gn_gen(self):
260 self.check(['gen', '-c', 'gn_debug', '//out/Default', '-g', '/goma'], 320 self.check(['gen', '-c', 'gn_debug', '//out/Default', '-g', '/goma'],
261 ret=0, 321 ret=0,
262 out=('/fake_src/buildtools/linux64/gn gen //out/Default ' 322 out=('/fake_src/buildtools/linux64/gn gen //out/Default '
263 '\'--args=is_debug=true use_goma=true goma_dir="/goma"\' ' 323 '\'--args=is_debug=true use_goma=true goma_dir="/goma"\' '
264 '--check\n')) 324 '--check\n'))
265 325
266 mbw = self.fake_mbw(win32=True) 326 mbw = self.fake_mbw(win32=True)
267 self.check(['gen', '-c', 'gn_debug', '-g', 'c:\\goma', '//out/Debug'], 327 self.check(['gen', '-c', 'gn_debug', '-g', 'c:\\goma', '//out/Debug'],
268 mbw=mbw, ret=0, 328 mbw=mbw, ret=0,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 finally: 453 finally:
394 sys.stdout = orig_stdout 454 sys.stdout = orig_stdout
395 455
396 456
397 def test_validate(self): 457 def test_validate(self):
398 self.check(['validate'], ret=0) 458 self.check(['validate'], ret=0)
399 459
400 460
401 if __name__ == '__main__': 461 if __name__ == '__main__':
402 unittest.main() 462 unittest.main()
OLDNEW
« tools/mb/docs/design_spec.md ('K') | « tools/mb/mb.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698