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

Side by Side Diff: mojo/PRESUBMIT_test.py

Issue 886453002: Add checks on services' public BUILD.gn files to //mojo/PRESUBMIT.py (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix indentation Created 5 years, 10 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
« no previous file with comments | « mojo/PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 import PRESUBMIT 10 import PRESUBMIT
11 11
12 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 12 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13 from PRESUBMIT_test_mocks import MockFile 13 from PRESUBMIT_test_mocks import MockFile
14 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi 14 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi
15 15
16 _SDK_BUILD_FILE = 'mojo/public/some/path/BUILD.gn' 16 _SDK_BUILD_FILE = 'mojo/public/some/path/BUILD.gn'
17 _EDK_BUILD_FILE = 'mojo/edk/some/path/BUILD.gn' 17 _EDK_BUILD_FILE = 'mojo/edk/some/path/BUILD.gn'
18 _SERVICE_BUILD_FILE = 'mojo/services/some_service/public/BUILD.gn'
18 _IRRELEVANT_BUILD_FILE = 'mojo/foo/some/path/BUILD.gn' 19 _IRRELEVANT_BUILD_FILE = 'mojo/foo/some/path/BUILD.gn'
19 20
20 _PACKAGE_BUILDFILES = { 21 _PACKAGE_BUILDFILES = {
21 'SDK' : _SDK_BUILD_FILE, 22 'SDK' : _SDK_BUILD_FILE,
22 'EDK' : _EDK_BUILD_FILE, 23 'EDK' : _EDK_BUILD_FILE,
24 'services' : _SERVICE_BUILD_FILE
23 } 25 }
24 26
25 class AbsoluteReferencesInBuildFilesTest(unittest.TestCase): 27 class AbsoluteReferencesInBuildFilesTest(unittest.TestCase):
26 """Tests the checking for illegal absolute paths within SDK/EDK buildfiles. 28 """Tests the checking for illegal absolute paths within SDK/EDK buildfiles.
27 """ 29 """
28 def setUp(self): 30 def setUp(self):
29 self.sdk_absolute_path = '//mojo/public/some/absolute/path' 31 self.sdk_absolute_path = '//mojo/public/some/absolute/path'
30 self.sdk_relative_path = 'mojo/public/some/relative/path' 32 self.sdk_relative_path = 'mojo/public/some/relative/path'
31 self.edk_absolute_path = '//mojo/edk/some/absolute/path' 33 self.edk_absolute_path = '//mojo/edk/some/absolute/path'
32 self.edk_relative_path = 'mojo/edk/some/relative/path' 34 self.edk_relative_path = 'mojo/edk/some/relative/path'
35 self.service_absolute_path = '//mojo/services/some/service'
36 self.service_relative_path = '../../../some/service'
33 self.whitelisted_external_path = '//testing/gtest' 37 self.whitelisted_external_path = '//testing/gtest'
34 self.non_whitelisted_external_path = '//base' 38 self.non_whitelisted_external_path = '//base'
35 39
36 def inputApiContainingFileWithPaths(self, filename, paths): 40 def inputApiContainingFileWithPaths(self, filename, paths):
37 """Returns a MockInputApi object with a single file having |filename| as 41 """Returns a MockInputApi object with a single file having |filename| as
38 its name and |paths| as its contents, with each path being wrapped in a 42 its name and |paths| as its contents, with each path being wrapped in a
39 pair of double-quotes to match the syntax for strings within BUILD.gn 43 pair of double-quotes to match the syntax for strings within BUILD.gn
40 files.""" 44 files."""
41 contents = [ '"%s"' % path for path in paths ] 45 contents = [ '"%s"' % path for path in paths ]
42 mock_file = MockFile(filename, contents) 46 mock_file = MockFile(filename, contents)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 self.checkWarningWithSingleItem(warnings[0], 155 self.checkWarningWithSingleItem(warnings[0],
152 expected_message, 156 expected_message,
153 _EDK_BUILD_FILE, 157 _EDK_BUILD_FILE,
154 1, 158 1,
155 self.edk_absolute_path) 159 self.edk_absolute_path)
156 160
157 def testExternalReferenceInEDKBuildFile(self): 161 def testExternalReferenceInEDKBuildFile(self):
158 """Tests that an external path in an EDK buildfile is not flagged.""" 162 """Tests that an external path in an EDK buildfile is not flagged."""
159 self._testExternalReferenceInPackage('EDK') 163 self._testExternalReferenceInPackage('EDK')
160 164
165 def testAbsoluteSDKReferenceInServiceBuildFile(self):
166 """Tests that an absolute SDK path within a service's public buildfile is
167 flagged."""
168 self._testAbsoluteSDKReferenceInPackage("services")
169
170 def testAbsoluteServiceReferenceInServiceBuildFile(self):
171 """Tests that an absolute path to a service within a service's public
172 buildfile is flagged."""
173 mock_input_api = self.inputApiContainingFileWithPaths(
174 _SERVICE_BUILD_FILE,
175 [ self.service_relative_path, self.service_absolute_path ])
176 warnings = PRESUBMIT._BuildFileChecks(mock_input_api, MockOutputApi())
177
178 self.assertEqual(1, len(warnings))
179 expected_message = \
180 PRESUBMIT._ILLEGAL_SERVICES_ABSOLUTE_PATH_WARNING_MESSAGE
181 self.checkWarningWithSingleItem(warnings[0],
182 expected_message,
183 _SERVICE_BUILD_FILE,
184 2,
185 self.service_absolute_path)
186
187 def testExternalReferenceInServiceBuildFile(self):
188 """Tests that an illegal external path in a service's buildfile is flagged
189 ."""
190 self._testExternalReferenceInPackage("services")
191
161 def testIrrelevantBuildFile(self): 192 def testIrrelevantBuildFile(self):
162 """Tests that nothing is flagged in a non SDK/EDK buildfile.""" 193 """Tests that nothing is flagged in a non SDK/EDK buildfile."""
163 mock_input_api = self.inputApiContainingFileWithPaths( 194 mock_input_api = self.inputApiContainingFileWithPaths(
164 _IRRELEVANT_BUILD_FILE, 195 _IRRELEVANT_BUILD_FILE,
165 [ self.sdk_absolute_path, 196 [ self.sdk_absolute_path,
166 self.sdk_relative_path, 197 self.sdk_relative_path,
167 self.edk_absolute_path, 198 self.edk_absolute_path,
168 self.edk_relative_path, 199 self.edk_relative_path,
169 self.non_whitelisted_external_path, 200 self.non_whitelisted_external_path,
170 self.whitelisted_external_path ]) 201 self.whitelisted_external_path ])
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 self._testWrongTypeOfWrapperSourceSetInPackage('SDK') 281 self._testWrongTypeOfWrapperSourceSetInPackage('SDK')
251 282
252 def testNakedSourceSetInEDKBuildFile(self): 283 def testNakedSourceSetInEDKBuildFile(self):
253 """Tests that a source_set within the EDK is flagged.""" 284 """Tests that a source_set within the EDK is flagged."""
254 self._testNakedSourceSetInPackage('EDK') 285 self._testNakedSourceSetInPackage('EDK')
255 286
256 def testSDKSourceSetInEDKBuildFile(self): 287 def testSDKSourceSetInEDKBuildFile(self):
257 """Tests that a mojo_sdk_source_set within an EDK buildfile is flagged.""" 288 """Tests that a mojo_sdk_source_set within an EDK buildfile is flagged."""
258 self._testWrongTypeOfWrapperSourceSetInPackage('EDK') 289 self._testWrongTypeOfWrapperSourceSetInPackage('EDK')
259 290
291 def testNakedSourceSetInServiceBuildFile(self):
292 """Tests that a source_set within a service's public buildfile is flagged.
293 """
294 self._testNakedSourceSetInPackage("services")
295
296 def testEDKSourceSetInServiceBuildFile(self):
297 """Tests that a mojo_edk_source_set within a service's public buildfile is
298 flagged."""
299 self._testWrongTypeOfWrapperSourceSetInPackage("services")
300
260 def testIrrelevantBuildFile(self): 301 def testIrrelevantBuildFile(self):
261 """Tests that a source_set in a non-SDK/EDK buildfile isn't flagged.""" 302 """Tests that a source_set in a non-SDK/EDK buildfile isn't flagged."""
262 mock_input_api = self.inputApiContainingFileWithSourceSets( 303 mock_input_api = self.inputApiContainingFileWithSourceSets(
263 _IRRELEVANT_BUILD_FILE, 304 _IRRELEVANT_BUILD_FILE,
264 [ 'source_set(' ]) 305 [ 'source_set(' ])
265 warnings = PRESUBMIT._BuildFileChecks(mock_input_api, MockOutputApi()) 306 warnings = PRESUBMIT._BuildFileChecks(mock_input_api, MockOutputApi())
266 self.assertEqual(0, len(warnings)) 307 self.assertEqual(0, len(warnings))
267 308
268 if __name__ == '__main__': 309 if __name__ == '__main__':
269 unittest.main() 310 unittest.main()
OLDNEW
« no previous file with comments | « mojo/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698