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+
}

0 commit comments

Comments
 (0)