Skip to content

Commit 70c37a5

Browse files
committed
Add tests for unrecognized compiler configurations
Signed-off-by: John Pennycook <[email protected]>
1 parent fa3721e commit 70c37a5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/compilers/test_compilers.py

+37
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,43 @@ def test_user_overrides(self):
373373

374374
tmp.cleanup()
375375

376+
def test_unrecognized(self):
377+
"""Check that we report unrecognized compilers, modes and passes."""
378+
tmp = tempfile.TemporaryDirectory()
379+
path = Path(tmp.name)
380+
os.chdir(tmp.name)
381+
os.mkdir(".cbi")
382+
with open(path / ".cbi" / "config", mode="w") as f:
383+
f.write("[[compiler.foo.parser]]\n")
384+
f.write('flags = ["-pass"]\n')
385+
f.write('action = "append_const"\n')
386+
f.write('dest = "passes"\n')
387+
f.write('const = "unrecognized-pass"\n')
388+
f.write("[[compiler.foo.parser]]\n")
389+
f.write('flags = ["-mode"]\n')
390+
f.write('action = "append_const"\n')
391+
f.write('dest = "modes"\n')
392+
f.write('const = "unrecognized-mode"\n')
393+
config._load_compilers()
394+
395+
logging.disable(logging.NOTSET)
396+
with self.assertLogs("codebasin", level=logging.WARNING) as cm:
397+
_ = ArgumentParser("foo").parse_args(
398+
["-pass", "-mode", "-unrecognized"],
399+
)
400+
logging.disable()
401+
402+
self.assertCountEqual(
403+
cm.output,
404+
[
405+
"WARNING:codebasin.config:Unrecognized arguments: '-unrecognized'",
406+
"ERROR:codebasin.config:Unrecognized compiler pass: unrecognized-pass",
407+
"ERROR:codebasin.config:Unrecognized compiler mode: unrecognized-mode",
408+
],
409+
)
410+
411+
tmp.cleanup()
412+
376413

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

0 commit comments

Comments
 (0)