OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 # |
| 4 # Use of this source code is governed by a BSD-style license |
| 5 # that can be found in the LICENSE file in the root of the source |
| 6 # tree. An additional intellectual property rights grant can be found |
| 7 # in the file PATENTS. All contributing project authors may |
| 8 # be found in the AUTHORS file in the root of the source tree. |
| 9 |
| 10 import unittest |
| 11 |
| 12 import check_orphan_headers |
| 13 |
| 14 |
| 15 class GetBuildGnPathFromFilePathTest(unittest.TestCase): |
| 16 |
| 17 def testGetBuildGnFromSameDirectory(self): |
| 18 file_path = '/home/projects/webrtc/base/foo.h' |
| 19 expected_build_path = '/home/projects/webrtc/base/BUILD.gn' |
| 20 file_exists = lambda p: p == '/home/projects/webrtc/base/BUILD.gn' |
| 21 src_dir_path = '/home/projects/webrtc' |
| 22 self.assertEqual( |
| 23 expected_build_path, |
| 24 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
| 25 file_exists, |
| 26 src_dir_path)) |
| 27 |
| 28 def testGetBuildPathFromParentDirectory(self): |
| 29 file_path = '/home/projects/webrtc/base/foo.h' |
| 30 expected_build_path = '/home/projects/webrtc/BUILD.gn' |
| 31 file_exists = lambda p: p == '/home/projects/webrtc/BUILD.gn' |
| 32 src_dir_path = '/home/projects/webrtc' |
| 33 self.assertEqual( |
| 34 expected_build_path, |
| 35 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
| 36 file_exists, |
| 37 src_dir_path)) |
| 38 |
| 39 def testExceptionIfNoBuildGnFilesAreFound(self): |
| 40 with self.assertRaises(check_orphan_headers.NoBuildGnFoundError): |
| 41 file_path = '/home/projects/webrtc/base/foo.h' |
| 42 file_exists = lambda p: False |
| 43 src_dir_path = '/home/projects/webrtc' |
| 44 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
| 45 file_exists, |
| 46 src_dir_path) |
| 47 |
| 48 def testExceptionIfFilePathIsNotAnHeader(self): |
| 49 with self.assertRaises(check_orphan_headers.WrongFileTypeError): |
| 50 file_path = '/home/projects/webrtc/base/foo.cc' |
| 51 file_exists = lambda p: False |
| 52 src_dir_path = '/home/projects/webrtc' |
| 53 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
| 54 file_exists, |
| 55 src_dir_path) |
| 56 |
| 57 |
| 58 class GetHeadersInBuildGnFileSourcesTest(unittest.TestCase): |
| 59 |
| 60 def testEmptyFileReturnsEmptySet(self): |
| 61 self.assertEqual( |
| 62 set([]), |
| 63 check_orphan_headers.GetHeadersInBuildGnFileSources('', '/a/b')) |
| 64 |
| 65 def testReturnsSetOfHeadersFromFileContent(self): |
| 66 file_content = """ |
| 67 # Some comments |
| 68 if (is_android) { |
| 69 import("//a/b/c.gni") |
| 70 import("//d/e/f.gni") |
| 71 } |
| 72 source_set("foo") { |
| 73 sources = ["foo.h"] |
| 74 deps = [":bar"] |
| 75 } |
| 76 rtc_static_library("bar") { |
| 77 sources = [ |
| 78 "bar.h", |
| 79 "bar.cc", |
| 80 ] |
| 81 deps = [":bar"] |
| 82 } |
| 83 source_set("baz_foo") { |
| 84 sources = ["baz/foo.h"] |
| 85 } |
| 86 """ |
| 87 self.assertEqual( |
| 88 set(['/a/b/foo.h', '/a/b/bar.h', '/a/b/baz/foo.h']), |
| 89 check_orphan_headers.GetHeadersInBuildGnFileSources(file_content, |
| 90 '/a/b')) |
| 91 |
| 92 |
| 93 if __name__ == '__main__': |
| 94 unittest.main() |
OLD | NEW |