Skip to content

Commit 23c08f0

Browse files
committed
Add tests for --prune option
Signed-off-by: John Pennycook <[email protected]>
1 parent 406a92c commit 23c08f0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/files/test_filetree.py

+43
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,49 @@ def test_levels(self):
165165

166166
tmp.cleanup()
167167

168+
def test_prune(self):
169+
"""Check report --prune flag works correctly"""
170+
# Set up subdirectories for this test
171+
tmp = tempfile.TemporaryDirectory()
172+
path = Path(tmp.name)
173+
with open(path / "foo.cpp", mode="w") as f:
174+
f.write("void foo();")
175+
open(path / "unused.cpp", mode="w").close()
176+
177+
codebase = CodeBase(path)
178+
configuration = {
179+
"X": [
180+
{
181+
"file": str(path / "foo.cpp"),
182+
"defines": [],
183+
"include_paths": [],
184+
"include_files": [],
185+
},
186+
],
187+
}
188+
state = finder.find(
189+
path,
190+
codebase,
191+
configuration,
192+
show_progress=False,
193+
)
194+
195+
# By default, we should see both used and unused files.
196+
stream = io.StringIO()
197+
report.files(codebase, state, stream=stream)
198+
output = stream.getvalue()
199+
self.assertTrue("foo.cpp" in output)
200+
self.assertTrue("unused.cpp" in output)
201+
202+
# With prune, we should only see the used files.
203+
stream = io.StringIO()
204+
report.files(codebase, state, stream=stream, prune=True)
205+
output = stream.getvalue()
206+
self.assertTrue("foo.cpp" in output)
207+
self.assertFalse("unused.cpp" in output)
208+
209+
tmp.cleanup()
210+
168211

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

0 commit comments

Comments
 (0)