Skip to content

Commit 4e8e56f

Browse files
committed
cpplint: Fix unittests when the styleguide directory is named otherwise
Don't hardcode the 'styleguide' directory in unit tests, instead get it from the ../.. basename.
1 parent e8ffd7c commit 4e8e56f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cpplint/cpplint_unittest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,12 +4280,14 @@ def testBuildHeaderGuardWithRoot(self):
42804280
# (note that CPPLINT.cfg root=setting is always made absolute)
42814281
this_files_path = os.path.dirname(os.path.abspath(__file__))
42824282
(styleguide_path, this_files_dir) = os.path.split(this_files_path)
4283-
(styleguide_parent_path, _) = os.path.split(styleguide_path)
4283+
(styleguide_parent_path, styleguide_dir_name) = os.path.split(styleguide_path)
42844284
# parent dir of styleguide
42854285
cpplint._root = styleguide_parent_path
42864286
self.assertIsNotNone(styleguide_parent_path)
4287+
# do not hardcode the 'styleguide' repository name, it could be anything.
4288+
expected_prefix = re.sub(r'[^a-zA-Z0-9]', '_', styleguide_dir_name).upper() + '_'
42874289
# do not have 'styleguide' repo in '/'
4288-
self.assertEquals('STYLEGUIDE_CPPLINT_CPPLINT_TEST_HEADER_H_',
4290+
self.assertEquals('%sCPPLINT_CPPLINT_TEST_HEADER_H_' %(expected_prefix),
42894291
cpplint.GetHeaderGuardCPPVariable(file_path))
42904292

42914293
# To run the 'relative path' tests, we must be in the directory of this test file.
@@ -4302,7 +4304,7 @@ def testBuildHeaderGuardWithRoot(self):
43024304
styleguide_rel_path = os.path.relpath(styleguide_parent_path,
43034305
this_files_path) # '../..'
43044306
cpplint._root = styleguide_rel_path
4305-
self.assertEquals('STYLEGUIDE_CPPLINT_CPPLINT_TEST_HEADER_H_',
4307+
self.assertEquals('%sCPPLINT_CPPLINT_TEST_HEADER_H_' %(expected_prefix),
43064308
cpplint.GetHeaderGuardCPPVariable(file_path))
43074309

43084310
cpplint._root = None

0 commit comments

Comments
 (0)