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 29 matching lines...) Expand all Loading... |
40 | 40 |
41 def Print(self, *args, **kwargs): | 41 def Print(self, *args, **kwargs): |
42 sep = kwargs.get('sep', ' ') | 42 sep = kwargs.get('sep', ' ') |
43 end = kwargs.get('end', '\n') | 43 end = kwargs.get('end', '\n') |
44 f = kwargs.get('file', sys.stdout) | 44 f = kwargs.get('file', sys.stdout) |
45 if f == sys.stderr: | 45 if f == sys.stderr: |
46 self.err += sep.join(args) + end | 46 self.err += sep.join(args) + end |
47 else: | 47 else: |
48 self.out += sep.join(args) + end | 48 self.out += sep.join(args) + end |
49 | 49 |
| 50 def TempFile(self): |
| 51 return FakeFile(self.files) |
| 52 |
| 53 def RemoveFile(self, path): |
| 54 del self.files[path] |
| 55 |
| 56 |
| 57 class FakeFile(object): |
| 58 def __init__(self, files): |
| 59 self.name = '/tmp/file' |
| 60 self.buf = '' |
| 61 self.files = files |
| 62 |
| 63 def write(self, contents): |
| 64 self.buf += contents |
| 65 |
| 66 def close(self): |
| 67 self.files[self.name] = self.buf |
| 68 |
| 69 |
50 class IntegrationTest(unittest.TestCase): | 70 class IntegrationTest(unittest.TestCase): |
51 def test_validate(self): | 71 def test_validate(self): |
52 # Note that this validates that the actual mb_config.pyl is valid. | 72 # Note that this validates that the actual mb_config.pyl is valid. |
53 ret = mb.main(['validate', '--quiet']) | 73 ret = mb.main(['validate', '--quiet']) |
54 self.assertEqual(ret, 0) | 74 self.assertEqual(ret, 0) |
55 | 75 |
56 | 76 |
57 TEST_CONFIG = """\ | 77 TEST_CONFIG = """\ |
58 { | 78 { |
59 'common_dev_configs': ['gn_debug'], | 79 'common_dev_configs': ['gn_debug'], |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 self.assertEqual(mbw.out, out) | 139 self.assertEqual(mbw.out, out) |
120 if err is not None: | 140 if err is not None: |
121 self.assertEqual(mbw.err, err) | 141 self.assertEqual(mbw.err, err) |
122 return mbw | 142 return mbw |
123 | 143 |
124 def test_gn_analyze(self): | 144 def test_gn_analyze(self): |
125 files = {'/tmp/in.json': """{\ | 145 files = {'/tmp/in.json': """{\ |
126 "files": ["foo/foo_unittest.cc"], | 146 "files": ["foo/foo_unittest.cc"], |
127 "targets": ["foo_unittests", "bar_unittests"] | 147 "targets": ["foo_unittests", "bar_unittests"] |
128 }"""} | 148 }"""} |
| 149 |
129 mbw = self.fake_mbw(files) | 150 mbw = self.fake_mbw(files) |
130 mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '') | 151 mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '') |
131 | 152 |
132 self.check(['analyze', '-c', 'gn_debug', '//out/Default', | 153 self.check(['analyze', '-c', 'gn_debug', '//out/Default', |
133 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) | 154 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) |
134 out = json.loads(mbw.files['/tmp/out.json']) | 155 out = json.loads(mbw.files['/tmp/out.json']) |
135 self.assertEqual(out, { | 156 self.assertEqual(out, { |
136 'status': 'Found dependency', | 157 'status': 'Found dependency', |
137 'targets': ['foo_unittests'], | 158 'targets': ['foo_unittests'], |
138 'build_targets': ['foo_unittests'] | 159 'build_targets': ['foo_unittests'] |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 223 |
203 def test_lookup(self): | 224 def test_lookup(self): |
204 self.check(['lookup', '-c', 'gn_debug'], ret=0) | 225 self.check(['lookup', '-c', 'gn_debug'], ret=0) |
205 | 226 |
206 def test_validate(self): | 227 def test_validate(self): |
207 self.check(['validate'], ret=0) | 228 self.check(['validate'], ret=0) |
208 | 229 |
209 | 230 |
210 if __name__ == '__main__': | 231 if __name__ == '__main__': |
211 unittest.main() | 232 unittest.main() |
OLD | NEW |