OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 4 # |
| 5 # Use of this source code is governed by a BSD-style license |
| 6 # that can be found in the LICENSE file in the root of the source |
| 7 # tree. An additional intellectual property rights grant can be found |
| 8 # in the file PATENTS. All contributing project authors may |
| 9 # be found in the AUTHORS file in the root of the source tree. |
| 10 |
| 11 import ast |
| 12 import os |
| 13 import unittest |
| 14 |
| 15 from check_package_boundaries import CheckPackageBoundaries |
| 16 |
| 17 |
| 18 MSG_FORMAT = 'ERROR:check_package_boundaries.py: Unexpected %s.' |
| 19 TESTDATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 20 'testdata') |
| 21 |
| 22 |
| 23 def ReadPylFile(file_path): |
| 24 with open(file_path) as f: |
| 25 return ast.literal_eval(f.read()) |
| 26 |
| 27 |
| 28 class Logger(object): |
| 29 def __init__(self, test_dir): |
| 30 self.messages = [] |
| 31 self.test_dir = test_dir |
| 32 |
| 33 def log(self, build_file_path, line_number, target_name, source_file, |
| 34 subpackage): |
| 35 build_file_path = os.path.relpath(build_file_path, self.test_dir) |
| 36 self.messages.append([build_file_path, line_number, target_name, |
| 37 source_file, subpackage]) |
| 38 |
| 39 |
| 40 class UnitTest(unittest.TestCase): |
| 41 def RunTest(self, test_dir, check_all_build_files=False): |
| 42 logger = Logger(test_dir) |
| 43 build_files = [os.path.join(test_dir, 'BUILD.gn')] |
| 44 if check_all_build_files: |
| 45 build_files = None |
| 46 CheckPackageBoundaries(test_dir, logger, build_files) |
| 47 expected_messages = ReadPylFile(os.path.join(test_dir, 'expected.pyl')) |
| 48 self.assertListEqual(sorted(expected_messages), sorted(logger.messages)) |
| 49 |
| 50 def test_no_errors(self): |
| 51 self.RunTest(os.path.join(TESTDATA_DIR, 'no_errors')) |
| 52 |
| 53 def test_multiple_errors_single_target(self): |
| 54 self.RunTest(os.path.join(TESTDATA_DIR, 'multiple_errors_single_target')) |
| 55 |
| 56 def test_multiple_errors_multiple_targets(self): |
| 57 self.RunTest(os.path.join(TESTDATA_DIR, 'multiple_errors_multiple_targets')) |
| 58 |
| 59 def test_common_prefix(self): |
| 60 self.RunTest(os.path.join(TESTDATA_DIR, 'common_prefix')) |
| 61 |
| 62 def test_all_build_files(self): |
| 63 self.RunTest(os.path.join(TESTDATA_DIR, 'all_build_files'), True) |
| 64 |
| 65 |
| 66 if __name__ == '__main__': |
| 67 unittest.main() |
OLD | NEW |