Merge pull request #12975 from bernt-matthias/topic/lint-expect-num-outputs

linter: warn if expect_num_outputs is missing
This commit is contained in:
John Chilton
2022-12-08 18:04:25 +01:00
committed by GitHub
2 changed files with 28 additions and 1 deletions
+6 -1
View File
@@ -38,11 +38,16 @@ def lint_tests(tool_xml, lint_ctx):
if len(assertions) == 0:
continue
if len(assertions) > 1:
lint_ctx.error(f"Test {test_idx}: More than one {ta} found. Only the first is considered.")
lint_ctx.error(f"Test {test_idx}: More than one {ta} found. Only the first is considered.", node=test)
has_test = True
_check_asserts(test_idx, assertions, lint_ctx)
_check_asserts(test_idx, test.findall(".//assert_contents"), lint_ctx)
# check if expect_num_outputs is set if there are outputs with filters
filter = tool_xml.findall("./outputs//filter")
if len(filter) > 0 and "expect_num_outputs" not in test.attrib:
lint_ctx.warn("Test should specify 'expect_num_outputs' if outputs have filters", node=test)
# really simple test that test parameters are also present in the inputs
for param in test.findall("param"):
name = param.attrib.get("name", None)
+22
View File
@@ -749,6 +749,20 @@ TESTS_DISCOVER_OUTPUTS = """
</tool>
"""
TESTS_EXPECT_NUM_OUTPUTS_FILTER = """
<tool>
<outputs>
<data>
<filter/>
</data>
</outputs>
<tests>
<test expect_failure="false">
</test>
</tests>
</tool>
"""
# tool xml for xml_order linter
XML_ORDER = """
<tool>
@@ -1586,6 +1600,14 @@ def test_tests_discover_outputs(lint_ctx):
assert len(lint_ctx.error_messages) == 4
def test_tests_expect_num_outputs_filter(lint_ctx):
tool_source = get_xml_tool_source(TESTS_EXPECT_NUM_OUTPUTS_FILTER)
run_lint(lint_ctx, tests.lint_tsts, tool_source)
assert "Test should specify 'expect_num_outputs' if outputs have filters" in lint_ctx.warn_messages
assert len(lint_ctx.warn_messages) == 1
assert len(lint_ctx.error_messages) == 0
def test_xml_order(lint_ctx):
tool_source = get_xml_tool_source(XML_ORDER)
run_lint(lint_ctx, xml_order.lint_xml_order, tool_source)