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

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

Issue 1062613004: Implement mb - a meta-build wrapper for bots to use in the GYP->GN migration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bug fixes and tests, reorganize mb_config.pyl 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
« no previous file with comments | « 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
(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 super(FakeMB, self).__init__()
16 self.files = {}
17 self.calls = []
18 self.out = []
19 self.err = []
20 self.chromium_src_dir = '/fake_src'
21 self.default_config = '/fake_src/tools/mb/mb_config.pyl'
22
23 def ExpandUser(self, path):
24 return '$HOME/%s' % path
25
26 def Exists(self, path):
27 return self.files.get(path) is not None
28
29 def ReadFile(self, path):
30 return self.files[path]
31
32 def WriteFile(self, path, contents):
33 self.files[path] = contents
34
35 def Call(self, cmd):
36 self.calls.append(cmd)
37 return 0, '', ''
38
39 def Print(self, *args, **kwargs):
40 sep = kwargs.get('sep', ' ')
41 end = kwargs.get('end', '\n')
42 f = kwargs.get('file', sys.stdout)
43 if f == sys.stderr:
44 self.err.append(sep.join(args) + end)
45 else:
46 self.out.append(sep.join(args) + end)
47
48 class IntegrationTest(unittest.TestCase):
49 def test_validate(self):
50 # Note that this validates that the actual mb_config.pyl is valid.
51 ret = mb.main(['validate', '--quiet'])
52 self.assertEqual(ret, 0)
53
54
55 TEST_CONFIG = """\
56 {
57 'common_dev_configs': ['gn_debug'],
58 'configs': {
59 'gyp_rel_bot': ['gyp', 'rel', 'goma'],
60 'gn_debug': ['gn', 'debug'],
61 'private': ['gyp', 'fake_feature1'],
62 'unsupported': ['gn', 'fake_feature2'],
63 },
64 'masters': {
65 'fake_master': {
66 'fake_builder': 'gyp_rel_bot',
67 },
68 },
69 'mixins': {
70 'fake_feature1': {
71 'gn_args': 'enable_doom_melon=true',
72 'gyp_defines': 'doom_melon=1',
73 },
74 'fake_feature2': {
75 'gn_args': 'enable_doom_melon=false',
76 'gyp_defaults': 'doom_melon=0',
77 },
78 'gyp': {'type': 'gyp'},
79 'gn': {'type': 'gn'},
80 'goma': {
81 'gn_args': 'use_goma=true goma_dir="$(goma_dir)"',
82 'gyp_defines': 'goma=1 gomadir="$(goma_dir)"',
83 },
84 'rel': {
85 'gn_args': 'is_debug=false',
86 'gyp_config': 'Release',
87 },
88 'debug': {
89 'gn_args': 'is_debug=true',
90 },
91 },
92 'private_configs': ['private'],
93 'unsupported_configs': ['unsupported'],
94 }
95 """
96
97
98 class UnitTest(unittest.TestCase):
99 def check(self, args, files=None, cmds=None, out=None, err=None, ret=None):
100 m = FakeMB()
101 if files:
102 for path, contents in files.items():
103 m.files[path] = contents
104 m.files.setdefault(mb.default_config, TEST_CONFIG)
105 m.ParseArgs(args)
106 actual_ret = m.args.func()
107 if ret is not None:
108 self.assertEqual(actual_ret, ret)
109 if out is not None:
110 self.assertEqual(m.out, out)
111 if err is not None:
112 self.assertEqual(m.err, err)
113 if cmds is not None:
114 self.assertEqual(m.cmds, cmds)
115
116 def test_analyze(self):
117 files = {'/tmp/in.json': '{"files": [], "targets": []}'}
118 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
119 '/tmp/in.json', '/tmp/out.json'],
120 files=files, ret=0)
121 self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release',
122 '/tmp/in.json', '/tmp/out.json'],
123 ret=0)
124
125 def test_gen(self):
126 self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0)
127 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0)
128
129 def test_help(self):
130 self.assertRaises(SystemExit, self.check, ['-h'])
131 self.assertRaises(SystemExit, self.check, ['help'])
132 self.assertRaises(SystemExit, self.check, ['help', 'gen'])
133
134 def test_lookup(self):
135 self.check(['lookup', '-c', 'gn_debug'], ret=0)
136
137 def test_validate(self):
138 self.check(['validate'], ret=0)
139
140
141 if __name__ == '__main__':
142 unittest.main()
OLDNEW
« no previous file with comments | « tools/mb/mb_config.pyl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698