From bf498b768e2b8ac11cb28febd37c90a378d58525 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9sar=20Sagaert?= Date: Mon, 18 Nov 2024 10:07:58 +0100 Subject: [PATCH] fix: make test actions run only once (#1792) Test actions would run once per test action defined, so this problem only became noticeable with more than one test action defined. * fix: make test actions run once * feat: log error message on test action fail * test: ensure actions are run only once --- src/alr/alr-commands-test.adb | 31 ++++++++++-------------- testsuite/tests/test/action-test/test.py | 9 +++++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/alr/alr-commands-test.adb b/src/alr/alr-commands-test.adb index 6fafb985..d98838d9 100644 --- a/src/alr/alr-commands-test.adb +++ b/src/alr/alr-commands-test.adb @@ -317,24 +317,18 @@ package body Alr.Commands.Test is else R.Base_Folder)) with Unreferenced; begin - for Action of R.On_Platform_Actions - (Platform.Properties, - (Alire.Properties.Actions.Test => True, - others => False)) - loop - Alire.Properties.Actions.Executor.Execute_Actions - (Release => R, - Env => Platform.Properties, - Moment => Alire.Properties.Actions.Test, - Capture => True, - Err_To_Out => True, - Code => Exit_Code, - Output => Output); - - if Exit_Code /= 0 then - raise Child_Failed; - end if; - end loop; + Alire.Properties.Actions.Executor.Execute_Actions + (Release => R, + Env => Platform.Properties, + Moment => Alire.Properties.Actions.Test, + Capture => True, + Err_To_Out => True, + Code => Exit_Code, + Output => Output); + + if Exit_Code /= 0 then + raise Child_Failed; + end if; end; end Custom_Test; @@ -393,6 +387,7 @@ package body Alr.Commands.Test is when E : Alire.Checked_Error => Reporters.End_Test (R, Testing.Fail, Clock - Start, Output); Trace.Detail (Output.Flatten (Newline)); + Alire.Errors.Pretty_Print (Alire.Errors.Get (E)); Some_Failed := True; Output.Append ("****** Checked Error raised during test:"); diff --git a/testsuite/tests/test/action-test/test.py b/testsuite/tests/test/action-test/test.py index d49665b2..6eb63b9b 100644 --- a/testsuite/tests/test/action-test/test.py +++ b/testsuite/tests/test/action-test/test.py @@ -3,7 +3,7 @@ Test custom actions for `alr test` """ from drivers.alr import run_alr -from drivers.helpers import check_line_in +from drivers.helpers import content_of from glob import glob @@ -16,7 +16,12 @@ chdir(glob('hello*')[0]) chdir('alire') # Check the magic string in the test output log -check_line_in(glob('*.log')[0], 'ABRACADABRA') +log_contents = content_of(glob('*.log')[0]) +magic_string_count = log_contents.count("ABRACADABRA") +if magic_string_count == 0: + assert False, 'action not run' +elif magic_string_count > 1: + assert False, 'action ran more than once' print('SUCCESS') -- 2.39.5