1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14import unittest 15 16from finder import confirm 17from finder import is_git_repo 18from cuj import src 19 20 21class UtilTest(unittest.TestCase): 22 def test_is_git_repo(self): 23 self.assertFalse(is_git_repo(src("."))) 24 self.assertTrue(is_git_repo(src("build/soong"))) 25 26 def test_any_match(self): 27 with self.subTest("required"): 28 with self.subTest("literal"): 29 confirm(src("build/soong"), "root.bp") 30 with self.subTest("wildcarded"): 31 confirm(src("build"), "*/root.bp") 32 33 with self.subTest("disallowed"): 34 with self.subTest("literal"): 35 confirm(src("build/bazel"), "!Android.bp", "!BUILD") 36 with self.subTest("wildcarded"): 37 confirm(src("bionic"), "!*.bazel", "*") 38 39 with self.subTest("disallowed and required"): 40 with self.subTest("literal"): 41 confirm( 42 src("build/bazel/scripts/incremental_build"), 43 "BUILD.bazel", 44 "!BUILD", 45 ) 46 with self.subTest("wildcarded"): 47 confirm(src("bionic/libm"), "!**/BUILD", "**/*.cpp") 48 49 50 51if __name__ == "__main__": 52 unittest.main() 53