Skip to content

Commit d316835

Browse files
committed
Add tests for --prune option
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent ee3c3e9 commit d316835

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/files/test_filetree.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,49 @@ def test_levels(self):
218218

219219
tmp.cleanup()
220220

221+
def test_prune(self):
222+
"""Check report --prune flag works correctly"""
223+
# Set up subdirectories for this test
224+
tmp = tempfile.TemporaryDirectory()
225+
path = Path(tmp.name)
226+
with open(path / "foo.cpp", mode="w") as f:
227+
f.write("void foo();")
228+
open(path / "unused.cpp", mode="w").close()
229+
230+
codebase = CodeBase(path)
231+
configuration = {
232+
"X": [
233+
{
234+
"file": str(path / "foo.cpp"),
235+
"defines": [],
236+
"include_paths": [],
237+
"include_files": [],
238+
},
239+
],
240+
}
241+
state = finder.find(
242+
path,
243+
codebase,
244+
configuration,
245+
show_progress=False,
246+
)
247+
248+
# By default, we should see both used and unused files.
249+
stream = io.StringIO()
250+
report.files(codebase, state, stream=stream)
251+
output = stream.getvalue()
252+
self.assertTrue("foo.cpp" in output)
253+
self.assertTrue("unused.cpp" in output)
254+
255+
# With prune, we should only see the used files.
256+
stream = io.StringIO()
257+
report.files(codebase, state, stream=stream, prune=True)
258+
output = stream.getvalue()
259+
self.assertTrue("foo.cpp" in output)
260+
self.assertFalse("unused.cpp" in output)
261+
262+
tmp.cleanup()
263+
221264

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

0 commit comments

Comments
 (0)