From 8c520b34f399ab6d45febd426e7ab01fc440bfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Tue, 16 Jul 2024 11:24:52 +0200 Subject: [PATCH] nameres: return error code when unexpected name resolution failures occur --- testsuite/ada/nameres.adb | 18 +++++++++++++++++- testsuite/drivers/name_resolution_driver.py | 8 +++++++- .../case_stmt_alt_fail/test.yaml | 1 + .../name_resolution/if_stmt_alt_fail/test.yaml | 1 + .../name_resolution/late_use_clause/test.yaml | 1 + .../name_resolution/test_expect_fail/test.yaml | 1 + .../use_bool_derived_type/test.yaml | 1 + 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/testsuite/ada/nameres.adb b/testsuite/ada/nameres.adb index 58a060d65..1aed83238 100644 --- a/testsuite/ada/nameres.adb +++ b/testsuite/ada/nameres.adb @@ -155,6 +155,11 @@ procedure Nameres is Help => "Only output failures on stdout. Note that this triggers" & " failures logging even when --quiet is passed."); + package No_Abort_On_Failures is new Parse_Flag + (App.Args.Parser, Long => "--no-abort-on-failures", + Help => "Expected name resolution failures: do not call Abort_App" + & " if some name resolution failed"); + package Imprecise_Fallback is new Parse_Flag (App.Args.Parser, Long => "--imprecise-fallback", Help => "Activate fallback mechanism for name resolution"); @@ -1447,7 +1452,8 @@ procedure Nameres is is pragma Unreferenced (Context); - Watermark : GNATCOLL.Memory.Watermark_Info; + Watermark : GNATCOLL.Memory.Watermark_Info; + App_Failed : Boolean := False; begin -- Measure time and memory before post-processing @@ -1469,8 +1475,18 @@ procedure Nameres is end; end if; + for Job of Jobs loop + for File_Stats of Job_Data (Job.ID).Stats.File_Stats loop + App_Failed := App_Failed or File_Stats.Nb_Fails > 0; + end loop; + end loop; + Free (Job_Data); + if App_Failed and then not Args.No_Abort_On_Failures.Get then + Abort_App ("Name resolution failed."); + end if; + Put_Line ("Done."); end App_Post_Process; diff --git a/testsuite/drivers/name_resolution_driver.py b/testsuite/drivers/name_resolution_driver.py index 3077450d2..fc93f5d70 100644 --- a/testsuite/drivers/name_resolution_driver.py +++ b/testsuite/drivers/name_resolution_driver.py @@ -55,6 +55,9 @@ class NameResolutionDriver(BaseDriver): * ``runtime_name``: Name of the runtime to use when loading the project (``--RTS`` nameres switch). + + * ``expect_fail``: Do not abort the nameres application if failures are + expected during resolution. """ perf_supported = True @@ -128,7 +131,7 @@ def run(self): # just on nameres-specific pragmas) and display only error messages, # not traceback (for test output stability). if self.test_env.get("batch"): - args += ["--all", "--no-traceback"] + args += ["--all", "--no-traceback", "--no-abort-on-failures"] # In perf mode, we need nameres not to print anything if not self.perf_mode: @@ -147,6 +150,9 @@ def run(self): if runtime_name: args.append(f"--RTS={runtime_name}") + if self.test_env.get("expect_fail"): + args.append("--no-abort-on-failures") + # Add optional explicit list of sources to process args += input_sources diff --git a/testsuite/tests/name_resolution/case_stmt_alt_fail/test.yaml b/testsuite/tests/name_resolution/case_stmt_alt_fail/test.yaml index 173e325ff..929bbc6b8 100644 --- a/testsuite/tests/name_resolution/case_stmt_alt_fail/test.yaml +++ b/testsuite/tests/name_resolution/case_stmt_alt_fail/test.yaml @@ -1,2 +1,3 @@ driver: name-resolution input_sources: [test.adb] +expect_fail: true diff --git a/testsuite/tests/name_resolution/if_stmt_alt_fail/test.yaml b/testsuite/tests/name_resolution/if_stmt_alt_fail/test.yaml index 173e325ff..929bbc6b8 100644 --- a/testsuite/tests/name_resolution/if_stmt_alt_fail/test.yaml +++ b/testsuite/tests/name_resolution/if_stmt_alt_fail/test.yaml @@ -1,2 +1,3 @@ driver: name-resolution input_sources: [test.adb] +expect_fail: true diff --git a/testsuite/tests/name_resolution/late_use_clause/test.yaml b/testsuite/tests/name_resolution/late_use_clause/test.yaml index d2e2d085b..afc5167c5 100644 --- a/testsuite/tests/name_resolution/late_use_clause/test.yaml +++ b/testsuite/tests/name_resolution/late_use_clause/test.yaml @@ -1,2 +1,3 @@ driver: name-resolution input_sources: [testuse.adb] +expect_fail: true diff --git a/testsuite/tests/name_resolution/test_expect_fail/test.yaml b/testsuite/tests/name_resolution/test_expect_fail/test.yaml index 173e325ff..929bbc6b8 100644 --- a/testsuite/tests/name_resolution/test_expect_fail/test.yaml +++ b/testsuite/tests/name_resolution/test_expect_fail/test.yaml @@ -1,2 +1,3 @@ driver: name-resolution input_sources: [test.adb] +expect_fail: true diff --git a/testsuite/tests/name_resolution/use_bool_derived_type/test.yaml b/testsuite/tests/name_resolution/use_bool_derived_type/test.yaml index e164dadba..669ec4067 100644 --- a/testsuite/tests/name_resolution/use_bool_derived_type/test.yaml +++ b/testsuite/tests/name_resolution/use_bool_derived_type/test.yaml @@ -1,2 +1,3 @@ driver: name-resolution input_sources: [test_valid.adb, test_invalid.adb, test_task.adb] +expect_fail: true