Andrew Grieve | 68549948 | 2022-09-09 23:14:08 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright 2022 The Chromium Authors |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import os |
| 7 | import sys |
| 8 | import unittest |
| 9 | |
| 10 | import PRESUBMIT |
| 11 | |
| 12 | sys.path.append(os.path.join(os.path.dirname(__file__),'..')) |
| 13 | |
| 14 | from PRESUBMIT_test_mocksimportMockAffectedFile |
| 15 | from PRESUBMIT_test_mocksimportMockInputApi,MockOutputApi |
| 16 | |
Andrew Grieve | 68549948 | 2022-09-09 23:14:08 | [diff] [blame] | 17 | |
| 18 | |
| 19 | def _fails_deps_check(line, filename='BUILD.gn'): |
| 20 | mock_input_api=MockInputApi() |
| 21 | mock_input_api.files=[MockAffectedFile(filename,[line])] |
| 22 | errors= PRESUBMIT.CheckNoBadDeps(mock_input_api,MockOutputApi()) |
| 23 | return bool(errors) |
| 24 | |
| 25 | |
| 26 | classCheckNoBadDepsTest(unittest.TestCase): |
| 27 | def testComments(self): |
| 28 | self.assertFalse(_fails_deps_check('no # import("//third_party/foo")')) |
| 29 | |
| 30 | def testFiles(self): |
| 31 | self.assertFalse( |
| 32 | _fails_deps_check('import("//third_party/foo")', filename='foo.txt')) |
| 33 | self.assertTrue( |
| 34 | _fails_deps_check('import("//third_party/foo")', filename='foo.gni')) |
| 35 | |
| 36 | def testPaths(self): |
| 37 | self.assertFalse(_fails_deps_check('import("//build/things.gni")')) |
| 38 | self.assertTrue(_fails_deps_check('import("//chrome/things.gni")')) |
| 39 | |
| 40 | |
| 41 | if __name__=='__main__': |
| 42 | unittest.main() |