Skip to content

Commit 81c0bf4

Browse files
committed
Test for warning with empty compilation databases
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>
1 parent ee1d464 commit 81c0bf4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/build-dir/test_build_dir.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestBuildDirectories(unittest.TestCase):
1818

1919
def setUp(self):
2020
self.rootdir = str(Path(__file__).parent)
21-
logging.getLogger("codebasin").disabled = True
21+
logging.getLogger("codebasin").disabled = False
2222

2323
def test_absolute_paths(self):
2424
"""
@@ -74,6 +74,37 @@ def test_absolute_paths(self):
7474
setmap = mapper.walk(state)
7575
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")
7676

77+
def test_empty_platform(self):
78+
"""
79+
Check that we warn if all files from a platform are excluded.
80+
This may be a sign that the compilation database has incorrect paths.
81+
"""
82+
83+
source = str(Path(__file__).parent.joinpath("foo.cpp"))
84+
85+
# CBI only understands how to load compilation databases from file.
86+
# For now, create temporary files every time we test.
87+
build = str(Path(__file__).parent.joinpath("build/"))
88+
tmp = tempfile.NamedTemporaryFile()
89+
obj = [
90+
{
91+
"command": f"/usr/bin/c++ -o foo.cpp.o -c {source}",
92+
"directory": f"{build}",
93+
"file": "foo.cpp",
94+
},
95+
]
96+
with open(tmp.name, "w") as f:
97+
json.dump(obj, f)
98+
99+
with self.assertLogs("codebasin", level="WARNING") as log:
100+
config.load_database(tmp.name, self.rootdir)
101+
102+
found_expected_warning = False
103+
for msg in log.output:
104+
if msg.find("No files found in compilation database"):
105+
found_expected_warning = True
106+
self.assertTrue(found_expected_warning)
107+
77108

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

0 commit comments

Comments
 (0)