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