OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 # | 3 # |
4 # Use of this source code is governed by a BSD-style license | 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 | 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 | 6 # tree. An additional intellectual property rights grant can be found |
7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
9 | 9 |
| 10 import os |
| 11 import sys |
10 import unittest | 12 import unittest |
11 | 13 |
12 import check_orphan_headers | 14 import check_orphan_headers |
13 | 15 |
14 | 16 |
| 17 def _GetRootBasedOnPlatform(): |
| 18 if sys.platform.startswith('win'): |
| 19 return 'C:\\' |
| 20 else: |
| 21 return '/' |
| 22 |
| 23 |
| 24 def _GetPath(*path_chunks): |
| 25 return os.path.join(_GetRootBasedOnPlatform(), |
| 26 *path_chunks) |
| 27 |
| 28 |
15 class GetBuildGnPathFromFilePathTest(unittest.TestCase): | 29 class GetBuildGnPathFromFilePathTest(unittest.TestCase): |
16 | 30 |
17 def testGetBuildGnFromSameDirectory(self): | 31 def testGetBuildGnFromSameDirectory(self): |
18 file_path = '/home/projects/webrtc/base/foo.h' | 32 file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h') |
19 expected_build_path = '/home/projects/webrtc/base/BUILD.gn' | 33 expected_build_path = _GetPath('home', 'projects', 'webrtc', 'base', |
20 file_exists = lambda p: p == '/home/projects/webrtc/base/BUILD.gn' | 34 'BUILD.gn') |
21 src_dir_path = '/home/projects/webrtc' | 35 file_exists = lambda p: p == _GetPath('home', 'projects', 'webrtc', |
| 36 'base', 'BUILD.gn') |
| 37 src_dir_path = _GetPath('home', 'projects', 'webrtc') |
22 self.assertEqual( | 38 self.assertEqual( |
23 expected_build_path, | 39 expected_build_path, |
24 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, | 40 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
25 file_exists, | 41 file_exists, |
26 src_dir_path)) | 42 src_dir_path)) |
27 | 43 |
28 def testGetBuildPathFromParentDirectory(self): | 44 def testGetBuildPathFromParentDirectory(self): |
29 file_path = '/home/projects/webrtc/base/foo.h' | 45 file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h') |
30 expected_build_path = '/home/projects/webrtc/BUILD.gn' | 46 expected_build_path = _GetPath('home', 'projects', 'webrtc', |
31 file_exists = lambda p: p == '/home/projects/webrtc/BUILD.gn' | 47 'BUILD.gn') |
32 src_dir_path = '/home/projects/webrtc' | 48 file_exists = lambda p: p == _GetPath('home', 'projects', 'webrtc', |
| 49 'BUILD.gn') |
| 50 src_dir_path = _GetPath('home', 'projects', 'webrtc') |
33 self.assertEqual( | 51 self.assertEqual( |
34 expected_build_path, | 52 expected_build_path, |
35 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, | 53 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
36 file_exists, | 54 file_exists, |
37 src_dir_path)) | 55 src_dir_path)) |
38 | 56 |
39 def testExceptionIfNoBuildGnFilesAreFound(self): | 57 def testExceptionIfNoBuildGnFilesAreFound(self): |
40 with self.assertRaises(check_orphan_headers.NoBuildGnFoundError): | 58 with self.assertRaises(check_orphan_headers.NoBuildGnFoundError): |
41 file_path = '/home/projects/webrtc/base/foo.h' | 59 file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.h') |
42 file_exists = lambda p: False | 60 file_exists = lambda p: False |
43 src_dir_path = '/home/projects/webrtc' | 61 src_dir_path = _GetPath('home', 'projects', 'webrtc') |
44 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, | 62 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
45 file_exists, | 63 file_exists, |
46 src_dir_path) | 64 src_dir_path) |
47 | 65 |
48 def testExceptionIfFilePathIsNotAnHeader(self): | 66 def testExceptionIfFilePathIsNotAnHeader(self): |
49 with self.assertRaises(check_orphan_headers.WrongFileTypeError): | 67 with self.assertRaises(check_orphan_headers.WrongFileTypeError): |
50 file_path = '/home/projects/webrtc/base/foo.cc' | 68 file_path = _GetPath('home', 'projects', 'webrtc', 'base', 'foo.cc') |
51 file_exists = lambda p: False | 69 file_exists = lambda p: False |
52 src_dir_path = '/home/projects/webrtc' | 70 src_dir_path = _GetPath('home', 'projects', 'webrtc') |
53 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, | 71 check_orphan_headers.GetBuildGnPathFromFilePath(file_path, |
54 file_exists, | 72 file_exists, |
55 src_dir_path) | 73 src_dir_path) |
56 | 74 |
57 | 75 |
58 class GetHeadersInBuildGnFileSourcesTest(unittest.TestCase): | 76 class GetHeadersInBuildGnFileSourcesTest(unittest.TestCase): |
59 | 77 |
60 def testEmptyFileReturnsEmptySet(self): | 78 def testEmptyFileReturnsEmptySet(self): |
61 self.assertEqual( | 79 self.assertEqual( |
62 set([]), | 80 set([]), |
(...skipping 14 matching lines...) Expand all Loading... |
77 sources = [ | 95 sources = [ |
78 "bar.h", | 96 "bar.h", |
79 "bar.cc", | 97 "bar.cc", |
80 ] | 98 ] |
81 deps = [":bar"] | 99 deps = [":bar"] |
82 } | 100 } |
83 source_set("baz_foo") { | 101 source_set("baz_foo") { |
84 sources = ["baz/foo.h"] | 102 sources = ["baz/foo.h"] |
85 } | 103 } |
86 """ | 104 """ |
| 105 target_abs_path = _GetPath('a', 'b') |
87 self.assertEqual( | 106 self.assertEqual( |
88 set(['/a/b/foo.h', '/a/b/bar.h', '/a/b/baz/foo.h']), | 107 set([ |
| 108 _GetPath('a', 'b', 'foo.h'), |
| 109 _GetPath('a', 'b', 'bar.h'), |
| 110 _GetPath('a', 'b', 'baz', 'foo.h'), |
| 111 ]), |
89 check_orphan_headers.GetHeadersInBuildGnFileSources(file_content, | 112 check_orphan_headers.GetHeadersInBuildGnFileSources(file_content, |
90 '/a/b')) | 113 target_abs_path)) |
91 | 114 |
92 | 115 |
93 if __name__ == '__main__': | 116 if __name__ == '__main__': |
94 unittest.main() | 117 unittest.main() |
OLD | NEW |