Chromium Code Reviews| 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 | |
|
scottmg
2015/05/13 23:57:26
wrong indent
| |
| 68 | |
|
scottmg
2015/05/13 23:57:26
nit; extra \n
| |
| 69 | |
| 70 | |
| 50 class IntegrationTest(unittest.TestCase): | 71 class IntegrationTest(unittest.TestCase): |
| 51 def test_validate(self): | 72 def test_validate(self): |
| 52 # Note that this validates that the actual mb_config.pyl is valid. | 73 # Note that this validates that the actual mb_config.pyl is valid. |
| 53 ret = mb.main(['validate', '--quiet']) | 74 ret = mb.main(['validate', '--quiet']) |
| 54 self.assertEqual(ret, 0) | 75 self.assertEqual(ret, 0) |
| 55 | 76 |
| 56 | 77 |
| 57 TEST_CONFIG = """\ | 78 TEST_CONFIG = """\ |
| 58 { | 79 { |
| 59 'common_dev_configs': ['gn_debug'], | 80 'common_dev_configs': ['gn_debug'], |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 self.assertEqual(mbw.out, out) | 140 self.assertEqual(mbw.out, out) |
| 120 if err is not None: | 141 if err is not None: |
| 121 self.assertEqual(mbw.err, err) | 142 self.assertEqual(mbw.err, err) |
| 122 return mbw | 143 return mbw |
| 123 | 144 |
| 124 def test_gn_analyze(self): | 145 def test_gn_analyze(self): |
| 125 files = {'/tmp/in.json': """{\ | 146 files = {'/tmp/in.json': """{\ |
| 126 "files": ["foo/foo_unittest.cc"], | 147 "files": ["foo/foo_unittest.cc"], |
| 127 "targets": ["foo_unittests", "bar_unittests"] | 148 "targets": ["foo_unittests", "bar_unittests"] |
| 128 }"""} | 149 }"""} |
| 150 | |
| 129 mbw = self.fake_mbw(files) | 151 mbw = self.fake_mbw(files) |
| 130 mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '') | 152 mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '') |
| 131 | 153 |
| 132 self.check(['analyze', '-c', 'gn_debug', '//out/Default', | 154 self.check(['analyze', '-c', 'gn_debug', '//out/Default', |
| 133 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) | 155 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) |
| 134 out = json.loads(mbw.files['/tmp/out.json']) | 156 out = json.loads(mbw.files['/tmp/out.json']) |
| 135 self.assertEqual(out, { | 157 self.assertEqual(out, { |
| 136 'status': 'Found dependency', | 158 'status': 'Found dependency', |
| 137 'targets': ['foo_unittests'], | 159 'targets': ['foo_unittests'], |
| 138 'build_targets': ['foo_unittests'] | 160 'build_targets': ['foo_unittests'] |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 224 |
| 203 def test_lookup(self): | 225 def test_lookup(self): |
| 204 self.check(['lookup', '-c', 'gn_debug'], ret=0) | 226 self.check(['lookup', '-c', 'gn_debug'], ret=0) |
| 205 | 227 |
| 206 def test_validate(self): | 228 def test_validate(self): |
| 207 self.check(['validate'], ret=0) | 229 self.check(['validate'], ret=0) |
| 208 | 230 |
| 209 | 231 |
| 210 if __name__ == '__main__': | 232 if __name__ == '__main__': |
| 211 unittest.main() | 233 unittest.main() |
| OLD | NEW |