Skip to content

Commit

Permalink
fix: make test actions run only once (#1792)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AldanTanneo authored Nov 18, 2024
1 parent 15addad commit bf498b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
31 changes: 13 additions & 18 deletions src/alr/alr-commands-test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:");
Expand Down
9 changes: 7 additions & 2 deletions testsuite/tests/test/action-test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from drivers.alr import run_alr
from drivers.helpers import check_line_in
from drivers.helpers import content_of

from glob import glob

Expand All @@ -16,7 +16,12 @@
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')

0 comments on commit bf498b7

Please sign in to comment.