Skip to content

Commit 397c07e

Browse files
committed
Create first tests for the 'composable rule files' feature
1 parent da53bca commit 397c07e

File tree

14 files changed

+132
-2
lines changed

14 files changed

+132
-2
lines changed

testsuite/drivers/gnatcheck_driver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class GnatcheckDriver(BaseDriver):
128128
True.
129129
- ``in_tty`` (bool): Whether to run GNATcheck in a pseudo TTY using the
130130
``pty`` Python module.
131+
- ``lkql_path`` (list[str]): A list of directories forwarded to the
132+
`LKQL_PATH` environment variable when the test is run.
131133
132134
- ``jobs`` (int): The number of jobs to forward to the GNATcheck command.
133135
- ``project`` (str): GPR build file to use (if any).
@@ -289,6 +291,8 @@ def run_one_test(test_data: dict[str, any]) -> None:
289291
f"{exe}.{'xml' if output_format == 'xml' else 'out'}"
290292
)
291293
)
294+
test_env = dict(gnatcheck_env)
295+
292296

293297
pre_python = test_data.get('pre_python', None)
294298
post_python = test_data.get('post_python', None)
@@ -298,6 +302,13 @@ def run_one_test(test_data: dict[str, any]) -> None:
298302
if pre_python:
299303
capture_exec_python(pre_python)
300304

305+
# If required, add provided directories to the LKQL_PATH variable
306+
for d in test_data.get('lkql_path', []):
307+
test_env['LKQL_PATH'] = os.pathsep.join([
308+
self.working_dir(d),
309+
test_env.get('LKQL_PATH', ""),
310+
])
311+
301312
# Set the target if one has been provided
302313
if test_data.get('target'):
303314
args.append(f"--target={test_data['target']}")
@@ -420,9 +431,9 @@ def run_one_test(test_data: dict[str, any]) -> None:
420431
exec_output = ""
421432
status_code = 0
422433
if test_data.get("in_tty"):
423-
exec_output, status_code = self.run_in_tty(args, env=gnatcheck_env)
434+
exec_output, status_code = self.run_in_tty(args, env=test_env)
424435
else:
425-
p = self.shell(args, env=gnatcheck_env, catch_error=False, analyze_output=False)
436+
p = self.shell(args, env=test_env, catch_error=False, analyze_output=False)
426437
exec_output = p.out
427438
status_code = p.status
428439

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import null_stmt
2+
3+
val rules = null_stmt.rules & @{
4+
Goto_Statements
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import part_one
2+
3+
val rules = part_one.rules & @{
4+
Goto_Statements
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import null_stmt
2+
3+
val rules = null_stmt.rules @{}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
procedure Main is
2+
begin
3+
null;
4+
goto First; -- FLAG
5+
6+
<<First>>
7+
8+
if C then
9+
goto Second; -- FLAG
10+
end if;
11+
12+
<<Second>>
13+
end Main;

testsuite/tests/gnatcheck/lkql_rules_config/combine_rule_files/other_rule_configs/null_stmt.lkql

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import part_two
2+
3+
val rules = part_two.rules & @{
4+
Redundant_Null_Statements
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import part_one
2+
3+
val rules = part_one.rules & @{
4+
Blocks
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val rules = @{
2+
Redundant_Null_Statements
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val rules = @{
2+
Goto_Statements: {Only_Unconditional: true, instance_name: "unconditional_goto"}
3+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Without key overlapping
2+
=======================
3+
4+
main.adb:3:04: rule violation: redundant null statement [redundant_null_statements]
5+
main.adb:4:04: rule violation: goto statement [goto_statements]
6+
main.adb:9:07: rule violation: goto statement [goto_statements]
7+
8+
With key overlapping
9+
====================
10+
11+
main.adb:4:04: rule violation: goto statement [goto_statements]
12+
main.adb:4:04: rule violation: goto statement [unconditional_goto|goto_statements]
13+
main.adb:9:07: rule violation: goto statement [goto_statements]
14+
15+
Rule file with an invalid importation
16+
=====================================
17+
18+
gnatcheck: error: invalid_import.lkql:1:01: Cannot import, module not found "null_stmt" (invalid_import.lkql)
19+
gnatcheck: error: no rule to check specified
20+
try "gnatcheck --help" for more information.
21+
>>>program returned status code 2
22+
23+
Rule file with circular importation
24+
===================================
25+
26+
gnatcheck: error: part_two.lkql:1:01: Circular dependency in LKQL modules (circular_import.lkql -> part_one.lkql -> part_two.lkql -> part_one.lkql) (circular_import.lkql)
27+
gnatcheck: error: no rule to check specified
28+
try "gnatcheck --help" for more information.
29+
>>>program returned status code 2
30+
31+
Rule file with ambiguous importation
32+
====================================
33+
34+
gnatcheck: error: ambiguous_import.lkql:1:01: Ambiguous importation, multiple "null_stmt" modules found (<working-dir>/other_rule_configs/null_stmt.lkql & <working-dir>/rule_configs/null_stmt.lkql) (ambiguous_import.lkql)
35+
gnatcheck: error: no rule to check specified
36+
try "gnatcheck --help" for more information.
37+
>>>program returned status code 2
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
driver: gnatcheck
2+
format: brief
3+
input_sources:
4+
- main.adb
5+
show_rule: True
6+
check_flags: False
7+
8+
tests:
9+
# Valid configurations testing
10+
- label: Without key overlapping
11+
lkql_rule_file: without_overlapping.lkql
12+
lkql_path:
13+
- rule_configs
14+
- label: With key overlapping
15+
lkql_rule_file: with_overlapping.lkql
16+
lkql_path:
17+
- rule_configs
18+
19+
# Error testing
20+
- label: Rule file with an invalid importation
21+
lkql_rule_file: invalid_import.lkql
22+
- label: Rule file with circular importation
23+
lkql_rule_file: circular_import.lkql
24+
lkql_path:
25+
- other_rule_configs
26+
- label: Rule file with ambiguous importation
27+
lkql_rule_file: ambiguous_import.lkql
28+
lkql_path:
29+
- rule_configs
30+
- other_rule_configs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import uncond_goto_stmt
2+
3+
val rules = uncond_goto_stmt.rules & @{
4+
Goto_Statements
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import null_stmt
2+
3+
val rules = null_stmt.rules & @{
4+
Goto_Statements
5+
}

0 commit comments

Comments
 (0)