| OLD | NEW |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 def MaybeMakeDirectory(self, path): | 49 def MaybeMakeDirectory(self, path): |
| 50 self.files[path] = True | 50 self.files[path] = True |
| 51 | 51 |
| 52 def PathJoin(self, *comps): | 52 def PathJoin(self, *comps): |
| 53 return self.sep.join(comps) | 53 return self.sep.join(comps) |
| 54 | 54 |
| 55 def ReadFile(self, path): | 55 def ReadFile(self, path): |
| 56 return self.files[path] | 56 return self.files[path] |
| 57 | 57 |
| 58 def WriteFile(self, path, contents, force_verbose=False): | 58 def WriteFile(self, path, contents, force_verbose=False): |
| 59 if self.args.dryrun or self.args.verbose or force_verbose: |
| 60 self.Print('\nWriting """\\\n%s""" to %s.\n' % (contents, path)) |
| 59 self.files[path] = contents | 61 self.files[path] = contents |
| 60 | 62 |
| 61 def Call(self, cmd, env=None, buffer_output=True): | 63 def Call(self, cmd, env=None, buffer_output=True): |
| 62 if env: | 64 if env: |
| 63 self.cross_compile = env.get('GYP_CROSSCOMPILE') | 65 self.cross_compile = env.get('GYP_CROSSCOMPILE') |
| 64 self.calls.append(cmd) | 66 self.calls.append(cmd) |
| 65 if self.cmds: | 67 if self.cmds: |
| 66 return self.cmds.pop(0) | 68 return self.cmds.pop(0) |
| 67 return 0, '', '' | 69 return 0, '', '' |
| 68 | 70 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 out = json.loads(mbw.files['/tmp/out.json']) | 300 out = json.loads(mbw.files['/tmp/out.json']) |
| 299 self.assertEqual(out, { | 301 self.assertEqual(out, { |
| 300 'status': 'No dependency', | 302 'status': 'No dependency', |
| 301 'compile_targets': [], | 303 'compile_targets': [], |
| 302 'test_targets': [], | 304 'test_targets': [], |
| 303 }) | 305 }) |
| 304 | 306 |
| 305 def test_gn_gen(self): | 307 def test_gn_gen(self): |
| 306 mbw = self.fake_mbw() | 308 mbw = self.fake_mbw() |
| 307 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'], | 309 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'], |
| 308 mbw=mbw, ret=0, | 310 mbw=mbw, ret=0) |
| 309 out=('/fake_src/buildtools/linux64/gn gen //out/Default ' | |
| 310 '--check\n')) | |
| 311 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], | 311 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], |
| 312 ('goma_dir = "/goma"\n' | 312 ('goma_dir = "/goma"\n' |
| 313 'is_debug = true\n' | 313 'is_debug = true\n' |
| 314 'use_goma = true\n')) | 314 'use_goma = true\n')) |
| 315 | 315 |
| 316 # Make sure we log both what is written to args.gn and the command line. |
| 317 self.assertIn('Writing """', mbw.out) |
| 318 self.assertIn('/fake_src/buildtools/linux64/gn gen //out/Default --check', |
| 319 mbw.out) |
| 320 |
| 316 mbw = self.fake_mbw(win32=True) | 321 mbw = self.fake_mbw(win32=True) |
| 317 self.check(['gen', '-c', 'gn_debug_goma', '-g', 'c:\\goma', '//out/Debug'], | 322 self.check(['gen', '-c', 'gn_debug_goma', '-g', 'c:\\goma', '//out/Debug'], |
| 318 mbw=mbw, ret=0, | 323 mbw=mbw, ret=0) |
| 319 out=('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug ' | |
| 320 '--check\n')) | |
| 321 self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'], | 324 self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'], |
| 322 ('goma_dir = "c:\\\\goma"\n' | 325 ('goma_dir = "c:\\\\goma"\n' |
| 323 'is_debug = true\n' | 326 'is_debug = true\n' |
| 324 'use_goma = true\n')) | 327 'use_goma = true\n')) |
| 328 self.assertIn('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug ' |
| 329 '--check\n', mbw.out) |
| 325 | 330 |
| 326 mbw = self.fake_mbw() | 331 mbw = self.fake_mbw() |
| 327 self.check(['gen', '-m', 'fake_master', '-b', 'fake_gn_args_bot', | 332 self.check(['gen', '-m', 'fake_master', '-b', 'fake_gn_args_bot', |
| 328 '//out/Debug'], | 333 '//out/Debug'], |
| 329 mbw=mbw, ret=0) | 334 mbw=mbw, ret=0) |
| 330 self.assertEqual( | 335 self.assertEqual( |
| 331 mbw.files['/fake_src/out/Debug/args.gn'], | 336 mbw.files['/fake_src/out/Debug/args.gn'], |
| 332 'import("//build/args/bots/fake_master/fake_gn_args_bot.gn")\n') | 337 'import("//build/args/bots/fake_master/fake_gn_args_bot.gn")\n') |
| 333 | 338 |
| 334 | 339 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 self.check(['validate'], mbw=mbw, ret=0) | 468 self.check(['validate'], mbw=mbw, ret=0) |
| 464 | 469 |
| 465 def test_bad_validate(self): | 470 def test_bad_validate(self): |
| 466 mbw = self.fake_mbw() | 471 mbw = self.fake_mbw() |
| 467 mbw.files[mbw.default_config] = TEST_BAD_CONFIG | 472 mbw.files[mbw.default_config] = TEST_BAD_CONFIG |
| 468 self.check(['validate'], mbw=mbw, ret=1) | 473 self.check(['validate'], mbw=mbw, ret=1) |
| 469 | 474 |
| 470 | 475 |
| 471 if __name__ == '__main__': | 476 if __name__ == '__main__': |
| 472 unittest.main() | 477 unittest.main() |
| OLD | NEW |