Skip to content

Commit f71128d

Browse files
committed
Merge branch 'topic/gnatcheck/fix_xml_report' into 'master'
Fix GNATcheck XML report regarding coding standard Closes #563 See merge request eng/libadalang/langkit-query-language!553
2 parents 50fbe70 + b4e9077 commit f71128d

File tree

8 files changed

+191
-0
lines changed

8 files changed

+191
-0
lines changed

lkql_checker/src/gnatcheck-rules.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ package body Gnatcheck.Rules is
576576
Set_Unbounded_String (Buffer, "");
577577
end if;
578578
end loop;
579+
580+
XML_Report
581+
(XML_Param (Prefix & To_String (Buffer) & Suffix), Indent_Level);
579582
end Print_XML_Params;
580583

581584
------------------------

testsuite/drivers/gnatcheck_driver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ def parsers(cls):
203203
"xml": cls._parse_xml,
204204
}
205205

206+
@classmethod
207+
def replace_xml_tag_content(
208+
cls,
209+
xml_buffer: str,
210+
tag_name: str,
211+
new_content: str
212+
) -> str:
213+
"""
214+
Match all tags with the provided name and replace their content by the
215+
provided new content, returning the result.
216+
"""
217+
return re.sub(
218+
f"<{tag_name}>.*</{tag_name}>",
219+
f"<{tag_name}>{new_content}</{tag_name}>",
220+
xml_buffer
221+
)
222+
206223
@property
207224
def default_process_timeout(self):
208225
return self.test_env.get("timeout", 300)
@@ -466,6 +483,15 @@ def run_one_test(test_data: dict[str, any]) -> None:
466483
with open(output_file_name) as f:
467484
if output_format in ["short", "xml"]:
468485
report_file_content = f.read()
486+
if output_format == "xml":
487+
# Remove changing parts of the GNATcheck XML report
488+
for (tag_name, new_content) in [
489+
("date", "DATE"),
490+
("version", "VERSION"),
491+
("command-line", "COMMAND_LINE"),
492+
("runtime", "RUNTIME"),
493+
]:
494+
report_file_content = self.replace_xml_tag_content(report_file_content, tag_name, new_content)
469495
else:
470496
# Strip the 10 first lines of the report, which contain
471497
# run-specific information that we don't want to
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My_Exclusion
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My_Header
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Main is -- FLAG(2)
2+
begin
3+
null;
4+
end Main;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
val rules = @{
2+
Deep_Inheritance_Hierarchies: {
3+
N: 1,
4+
instance_name: "My_Name"
5+
},
6+
Goto_Statements: {
7+
Only_Unconditional: true
8+
},
9+
Headers: {
10+
Header: "header.txt"
11+
},
12+
Numeric_Literals: {
13+
N: 2,
14+
Statements_Only: true
15+
},
16+
Identifier_Prefixes: {
17+
Type: "T_",
18+
Concurrent: "Conc_",
19+
Access: "Acc_",
20+
Class_Access: "Cls_Acc",
21+
Subprogram_Access: "Subp_Acc",
22+
Derived: ["A_:B_", "C_:D_"],
23+
Constant: "Cst_",
24+
Enum: "Enum_",
25+
Exception: "Exc_",
26+
Exclusive: true
27+
},
28+
Identifier_Suffixes: {
29+
Type_Suffix: "_T",
30+
Access_Suffix: "_Acc",
31+
Class_Access_Suffix: "_Cls_Acc",
32+
Class_Subtype_Suffix: "_Sub_Cls_Acc",
33+
Constant_Suffix: "_Cst",
34+
Renaming_Suffix: "_Rename",
35+
Access_Obj_Suffix: "_Acc_Obj",
36+
Interrupt_Suffix: "_Inter"
37+
},
38+
Identifier_Casing: {
39+
Type: "Upper",
40+
Enum: "Lower",
41+
Constant: "Mixed",
42+
Exception: "Upper",
43+
Others: "Lower",
44+
Exclude: "exclude.txt"
45+
},
46+
Forbidden_Attributes: {
47+
Forbidden: ["One", "Two"],
48+
Allowed: ["Test"],
49+
All: false
50+
},
51+
Silent_Exception_Handlers: {
52+
Subprograms: ["My_Package.P1", "My_Package.P2"]
53+
},
54+
Duplicate_Branches: {
55+
Min_Stmt: 3,
56+
Min_Size: 4
57+
}
58+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0"?>
2+
<gnatcheck-report>
3+
<date>DATE</date>
4+
<version>VERSION</version>
5+
<command-line>COMMAND_LINE</command-line>
6+
<runtime>RUNTIME</runtime>
7+
<coding-standard from-file="gnatcheck-rule-list.out">
8+
<rule id="identifier_casing">
9+
<parameter>Type=upper</parameter>
10+
<parameter>Enum=lower</parameter>
11+
<parameter>Constant=mixed</parameter>
12+
<parameter>Exception=upper</parameter>
13+
<parameter>Others=lower</parameter>
14+
<parameter>Exclude=My_Exclusion</parameter>
15+
</rule>
16+
<rule id="silent_exception_handlers">
17+
<parameter>my_package.p1</parameter>
18+
<parameter>my_package.p2</parameter>
19+
</rule>
20+
<rule id="duplicate_branches">
21+
<parameter>min_size=4</parameter>
22+
<parameter>min_stmt=3</parameter>
23+
</rule>
24+
<rule id="goto_statements">
25+
<parameter>only_unconditional</parameter>
26+
</rule>
27+
<rule id="headers">
28+
<parameter>My_Header</parameter>
29+
</rule>
30+
<rule alias="My_Name" of="deep_inheritance_hierarchies">
31+
<parameter>1</parameter>
32+
</rule>
33+
<rule id="numeric_literals">
34+
<parameter>2</parameter>
35+
<parameter>statements_only</parameter>
36+
</rule>
37+
<rule id="identifier_suffixes">
38+
<parameter>Type_Suffix=_T</parameter>
39+
<parameter>Access_Suffix=_Acc</parameter>
40+
<parameter>Class_Subtype_Suffix=_Sub_Cls_Acc</parameter>
41+
<parameter>Class_Access_Suffix=_Cls_Acc</parameter>
42+
<parameter>Constant_Suffix=_Cst</parameter>
43+
<parameter>Renaming_Suffix=_Rename</parameter>
44+
<parameter>Access_Obj_Suffix=_Acc_Obj</parameter>
45+
<parameter>Interrupt_Suffix=_Inter</parameter>
46+
</rule>
47+
<rule id="forbidden_attributes">
48+
<parameter>one</parameter>
49+
<parameter>two</parameter>
50+
<parameter>-test</parameter>
51+
</rule>
52+
<rule id="identifier_prefixes">
53+
<parameter>Type=T_</parameter>
54+
<parameter>Concurrent=Conc_</parameter>
55+
<parameter>Access=Acc_</parameter>
56+
<parameter>Class_Access=Cls_Acc</parameter>
57+
<parameter>Subprogram_Access=Subp_Acc</parameter>
58+
<parameter>Constant=Cst_</parameter>
59+
<parameter>Exception=Exc_</parameter>
60+
<parameter>Enum=Enum_</parameter>
61+
<parameter>Derived=a_:B_,c_:D_</parameter>
62+
<parameter>Exclusive</parameter>
63+
</rule>
64+
</coding-standard>
65+
<sources from-file="gnatcheck-source-list.out">
66+
<source><working-dir>/main.adb</source>
67+
</sources>
68+
<summary>
69+
<fully-compliant-sources>0</fully-compliant-sources>
70+
<sources-with-exempted-violations-only>0</sources-with-exempted-violations-only>
71+
<sources-with-non-exempted-violations>1</sources-with-non-exempted-violations>
72+
<unverified-sources>0</unverified-sources>
73+
<total-sources>1</total-sources>
74+
<non-exempted-violations>2</non-exempted-violations>
75+
<rule-exemption-warnings>0</rule-exemption-warnings>
76+
<compilation-errors>0</compilation-errors>
77+
<exempted-violations>0</exempted-violations>
78+
<gnatcheck-errors>0</gnatcheck-errors>
79+
</summary>
80+
<violations>
81+
no exempted violations detected
82+
<violation file="main.adb" line="1" column="1" rule-id="headers">
83+
<message>compilation unit does not start with header</message>
84+
</violation>
85+
<violation file="main.adb" line="1" column="11" rule-id="identifier_casing">
86+
<message>Main does not have casing specified (lower)</message>
87+
</violation>
88+
no rule exemption problems detected
89+
no language violations detected
90+
no internal error detected
91+
</violations>
92+
</gnatcheck-report>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
driver: gnatcheck
2+
description: Test the GNATcheck XML output
3+
format: xml
4+
input_sources:
5+
- main.adb
6+
lkql_rule_file: rules.lkql

0 commit comments

Comments
 (0)