OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Tests for mb.py.""" |
| 6 |
| 7 import sys |
| 8 import unittest |
| 9 |
| 10 import mb |
| 11 |
| 12 |
| 13 class FakeMB(mb.MetaBuildWrapper): |
| 14 def __init__(self): |
| 15 self.files = {} |
| 16 self.calls = [] |
| 17 self.out = [] |
| 18 self.err = [] |
| 19 self.chromium_src_dir = '/fake_src' |
| 20 self.default_config = '/fake_src/tools/mb/mb_config.pyl' |
| 21 |
| 22 def ExpandUser(self, path): |
| 23 return '$HOME/%s' % path |
| 24 |
| 25 def Exists(self, path): |
| 26 return self.files.get(path) is not None |
| 27 |
| 28 def ReadFile(self, path): |
| 29 return self.files[path] |
| 30 |
| 31 def Call(self, cmd): |
| 32 self.calls.append(cmd) |
| 33 return 0, '', '' |
| 34 |
| 35 def Print(self, *args, sep=' ', end='\n', stream=None): |
| 36 if stream == sys.stderr: |
| 37 self.err.append(sep.join(args) + end) |
| 38 else: |
| 39 self.out.append(sep.join(args) + end) |
| 40 |
| 41 class IntegrationTest(unittest.TestCase): |
| 42 def test_validate(self): |
| 43 # Note that this validates that the actual mb_config.pyl is valid. |
| 44 ret = mb.main(['validate', '--quiet']) |
| 45 self.assertEqual(ret, 0) |
| 46 |
| 47 |
| 48 TEST_CONFIG = """\ |
| 49 { |
| 50 'common_dev_configs': ['gn_debug'], |
| 51 'configs': { |
| 52 'gyp_rel_bot': ['gyp', 'rel', 'goma'], |
| 53 'gn_debug': ['gn', 'debug'], |
| 54 'private': ['gyp', 'fake_feature1'], |
| 55 'unsupported': ['gn', 'fake_feature2'], |
| 56 }, |
| 57 'masters': { |
| 58 'fake_master': { |
| 59 'fake_builder': 'gyp_rel_bot', |
| 60 }, |
| 61 }, |
| 62 'mixins': { |
| 63 'fake_feature1': { |
| 64 'gn_args': 'enable_doom_melon=true', |
| 65 'gyp_defines': 'doom_melon=1', |
| 66 }, |
| 67 'fake_feature2': { |
| 68 'gn_args': 'enable_doom_melon=false', |
| 69 'gyp_defaults': 'doom_melon=0', |
| 70 }, |
| 71 'gyp': {'type': 'gyp'}, |
| 72 'gn': {'type': 'gn'}, |
| 73 'goma': { |
| 74 'gn_args': 'use_goma=true goma_dir="$(goma_dir)"', |
| 75 'gyp_defines': 'goma=1 gomadir="$(goma_dir)"', |
| 76 }, |
| 77 'rel': { |
| 78 'gn_args': 'is_debug=false', |
| 79 'gyp_config': 'Release', |
| 80 }, |
| 81 'debug': { |
| 82 'gn_args': 'is_debug=true', |
| 83 }, |
| 84 }, |
| 85 'private_configs': ['private'], |
| 86 'unsupported_configs': ['unsupported'], |
| 87 } |
| 88 """ |
| 89 |
| 90 |
| 91 |
| 92 class UnitTest(unittest.TestCase): |
| 93 def check(self, args, files=None, cmds=None, out=None, err=None, ret=None): |
| 94 mb = FakeMB() |
| 95 if not files: |
| 96 files = {} |
| 97 files[mb.default_config] = TEST_CONFIG |
| 98 mb.files = files |
| 99 mb.ParseArgs(args) |
| 100 actual_ret = mb.args.func() |
| 101 if ret is not None: |
| 102 self.assertEqual(actual_ret, ret) |
| 103 if out is not None: |
| 104 self.assertEqual(mb.out, out) |
| 105 if err is not None: |
| 106 self.assertEqual(mb.err, err) |
| 107 if cmds is not None: |
| 108 self.assertEqual(mb.cmds, cmds) |
| 109 |
| 110 def disabled_test_analyze(self): |
| 111 self.fail() # TODO: implement me. |
| 112 |
| 113 def test_gen(self): |
| 114 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0) |
| 115 |
| 116 def test_help(self): |
| 117 return |
| 118 self.check(['-h'], ret=0) |
| 119 self.check(['help'], ret=0) |
| 120 self.check(['help', 'gen'], ret=0) |
| 121 |
| 122 def test_lookup(self): |
| 123 self.check(['lookup', '-c', 'gn_debug'], ret=0) |
| 124 |
| 125 def test_validate(self): |
| 126 self.check(['validate'], ret=0) |
| 127 |
| 128 |
| 129 if __name__ == '__main__': |
| 130 unittest.main() |
OLD | NEW |