Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: tools_webrtc/presubmit_checks_lib/check_orphan_headers_test.py

Issue 2872493002: Adding PRESUBMIT check on orphan headers files. (Closed)
Patch Set: moving presubmit_checks_lib to tools_webrtc Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 unittest
10
11 import check_orphan_headers
12
13
14 class GetBuildGnPathFromFilePathTest(unittest.TestCase):
15
16 def testGetBuildGnFromSameDirectory(self):
17 file_path = '/home/projects/webrtc/base/foo.h'
18 expected_build_path = '/home/projects/webrtc/base/BUILD.gn'
19 file_exists = lambda p: p == '/home/projects/webrtc/base/BUILD.gn'
20 src_dir_path = '/home/projects/webrtc'
21 self.assertEqual(
22 expected_build_path,
23 check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
24 file_exists,
25 src_dir_path))
26
27 def testGetBuildPathFromParentDirectory(self):
28 file_path = '/home/projects/webrtc/base/foo.h'
29 expected_build_path = '/home/projects/webrtc/BUILD.gn'
30 file_exists = lambda p: p == '/home/projects/webrtc/BUILD.gn'
31 src_dir_path = '/home/projects/webrtc'
32 self.assertEqual(
33 expected_build_path,
34 check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
35 file_exists,
36 src_dir_path))
37
38 def testExceptionIfNoBuildGnFilesAreFound(self):
39 with self.assertRaises(check_orphan_headers.NoBuildGnFoundError):
40 file_path = '/home/projects/webrtc/base/foo.h'
41 file_exists = lambda p: False
42 src_dir_path = '/home/projects/webrtc'
43 check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
44 file_exists,
45 src_dir_path)
46
47 def testExceptionIfFilePathIsNotAnHeader(self):
48 with self.assertRaises(check_orphan_headers.WrongFileTypeError):
49 file_path = '/home/projects/webrtc/base/foo.cc'
50 file_exists = lambda p: False
51 src_dir_path = '/home/projects/webrtc'
52 check_orphan_headers.GetBuildGnPathFromFilePath(file_path,
53 file_exists,
54 src_dir_path)
55
56
57 class GetHeadersInBuildGnFileSourcesTest(unittest.TestCase):
58
59 def testEmptyFileReturnsEmptySet(self):
60 self.assertEqual(
61 set([]),
62 check_orphan_headers.GetHeadersInBuildGnFileSources('', '/a/b'))
63
64 def testReturnsSetOfHeadersFromFileContent(self):
65 file_content = """
66 # Some comments
67 if (is_android) {
68 import("//a/b/c.gni")
69 import("//d/e/f.gni")
70 }
71 source_set("foo") {
72 sources = ["foo.h"]
73 deps = [":bar"]
74 }
75 rtc_static_library("bar") {
76 sources = [
77 "bar.h",
78 "bar.cc",
79 ]
80 deps = [":bar"]
81 }
82 source_set("baz_foo") {
83 sources = ["baz/foo.h"]
84 }
85 """
86 self.assertEqual(
87 set(['/a/b/foo.h', '/a/b/bar.h', '/a/b/baz/foo.h']),
88 check_orphan_headers.GetHeadersInBuildGnFileSources(file_content,
89 '/a/b'))
90
91
92 if __name__ == '__main__':
93 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698