Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
| 2 # | |
| 3 # Use of this source code is governed by a BSD-style license | |
| 4 # that can be found in the LICENSE file in the root of the source | |
| 5 # tree. An additional intellectual property rights grant can be found | |
| 6 # in the file PATENTS. All contributing project authors may | |
| 7 # be found in the AUTHORS file in the root of the source tree. | |
| 8 | |
| 9 import textwrap | |
| 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 = textwrap.dedent(""" | |
| 67 # Some comments | |
|
kjellander_webrtc
2017/05/08 18:52:00
indenting this much looks kind of weird to me. Let
mbonadei
2017/05/09 07:31:20
Done.
| |
| 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"] | |
|
kjellander_webrtc
2017/05/08 18:52:00
Can you add another header with the same name in a
mbonadei
2017/05/09 07:31:19
Done.
| |
| 74 deps = [":bar"] | |
| 75 } | |
| 76 rtc_static_library("bar") { | |
| 77 sources = [ | |
| 78 "bar.h", | |
| 79 "bar.cc", | |
| 80 ] | |
| 81 deps = [":bar"] | |
| 82 } | |
| 83 """) | |
| 84 self.assertEqual( | |
| 85 set(['/a/b/foo.h', '/a/b/bar.h']), | |
| 86 check_orphan_headers.GetHeadersInBuildGnFileSources(file_content, | |
| 87 '/a/b')) | |
|
kjellander_webrtc
2017/05/08 18:52:00
alight with previous line's parenthesis (-1 space)
mbonadei
2017/05/09 07:31:19
Done.
| |
| 88 | |
|
kjellander_webrtc
2017/05/08 18:52:00
+1 blank line
mbonadei
2017/05/09 07:31:19
Done.
| |
| 89 if __name__ == '__main__': | |
| 90 unittest.main() | |
| OLD | NEW |