Skip to content

Commit

Permalink
Test for warning with empty compilation databases
Browse files Browse the repository at this point in the history
If a compilation database specifies files relative to a build directory
(or otherwise points to paths that do not exist) then the resulting platform
definition will be empty. We should ensure that we issue a warning in this
case.

Signed-off-by: John Pennycook <john.pennycook@intel.com>
  • Loading branch information
Pennycook committed Mar 7, 2024
1 parent ee1d464 commit 81c0bf4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/build-dir/test_build_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestBuildDirectories(unittest.TestCase):

def setUp(self):
self.rootdir = str(Path(__file__).parent)
logging.getLogger("codebasin").disabled = True
logging.getLogger("codebasin").disabled = False

def test_absolute_paths(self):
"""
Expand Down Expand Up @@ -74,6 +74,37 @@ def test_absolute_paths(self):
setmap = mapper.walk(state)
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")

def test_empty_platform(self):
"""
Check that we warn if all files from a platform are excluded.
This may be a sign that the compilation database has incorrect paths.
"""

source = str(Path(__file__).parent.joinpath("foo.cpp"))

# CBI only understands how to load compilation databases from file.
# For now, create temporary files every time we test.
build = str(Path(__file__).parent.joinpath("build/"))
tmp = tempfile.NamedTemporaryFile()
obj = [
{
"command": f"/usr/bin/c++ -o foo.cpp.o -c {source}",
"directory": f"{build}",
"file": "foo.cpp",
},
]
with open(tmp.name, "w") as f:
json.dump(obj, f)

with self.assertLogs("codebasin", level="WARNING") as log:
config.load_database(tmp.name, self.rootdir)

found_expected_warning = False
for msg in log.output:
if msg.find("No files found in compilation database"):
found_expected_warning = True
self.assertTrue(found_expected_warning)


if __name__ == "__main__":
unittest.main()

0 comments on commit 81c0bf4

Please sign in to comment.