MCPcopy Index your code
hub / github.com/cpplint/cpplint / doTestBuildHeaderGuardWithRoot

Method doTestBuildHeaderGuardWithRoot

cpplint_unittest.py:5457–5543  ·  view source on GitHub ↗
(self, header_directory)

Source from the content-addressed store, hash-verified

5455 shutil.rmtree(temp_directory)
5456
5457 def doTestBuildHeaderGuardWithRoot(self, header_directory):
5458 # note: Tested file paths must be real, otherwise
5459 # the repository name lookup will fail.
5460 file_path = os.path.join(header_directory, "cpplint_test_header.h")
5461 open(file_path, "a").close()
5462 file_info = cpplint.FileInfo(file_path)
5463 if file_info.FullName() == file_info.RepositoryName():
5464 # When FileInfo cannot deduce the root directory of the repository,
5465 # FileInfo.RepositoryName returns the same value as FileInfo.FullName.
5466 # This can happen when this source file was obtained without .svn or
5467 # .git directory. (e.g. using 'svn export' or 'git archive').
5468 # Skip this test in such a case because --root flag makes sense only
5469 # when the root directory of the repository is properly deduced.
5470 return
5471
5472 assert cpplint.GetHeaderGuardCPPVariable(file_path) == "CPPLINT_CPPLINT_TEST_HEADER_H_"
5473 #
5474 # test --root flags:
5475 # this changes the cpp header guard prefix
5476 #
5477
5478 # left-strip the header guard by using a root dir inside of the repo dir.
5479 # relative directory
5480 cpplint._root = "cpplint"
5481 assert cpplint.GetHeaderGuardCPPVariable(file_path) == "CPPLINT_TEST_HEADER_H_"
5482
5483 nested_header_directory = os.path.join(header_directory, "nested")
5484 nested_file_path = os.path.join(nested_header_directory, "cpplint_test_header.h")
5485 os.makedirs(nested_header_directory)
5486 open(nested_file_path, "a").close()
5487
5488 cpplint._root = os.path.join("cpplint", "nested")
5489 actual = cpplint.GetHeaderGuardCPPVariable(nested_file_path)
5490 assert actual == "CPPLINT_TEST_HEADER_H_"
5491
5492 # absolute directory
5493 # (note that CPPLINT.cfg root=setting is always made absolute)
5494 cpplint._root = header_directory
5495 assert cpplint.GetHeaderGuardCPPVariable(file_path) == "CPPLINT_TEST_HEADER_H_"
5496
5497 cpplint._root = nested_header_directory
5498 assert cpplint.GetHeaderGuardCPPVariable(nested_file_path) == "CPPLINT_TEST_HEADER_H_"
5499
5500 # --root flag is ignored if an non-existent directory is specified.
5501 cpplint._root = "NON_EXISTENT_DIR"
5502 assert cpplint.GetHeaderGuardCPPVariable(file_path) == "CPPLINT_CPPLINT_TEST_HEADER_H_"
5503
5504 # prepend to the header guard by using a root dir that is more outer
5505 # than the repo dir
5506
5507 # (using absolute paths)
5508 # (note that CPPLINT.cfg root=setting is always made absolute)
5509 this_files_path = os.path.dirname(os.path.abspath(file_path))
5510 (styleguide_path, this_files_dir) = os.path.split(this_files_path)
5511 (styleguide_parent_path, styleguide_dir_name) = os.path.split(styleguide_path)
5512 # parent dir of styleguide
5513 cpplint._root = styleguide_parent_path
5514 assert styleguide_parent_path is not None

Callers 1

Calls 2

FullNameMethod · 0.95
RepositoryNameMethod · 0.95

Tested by

no test coverage detected