Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/alr/alr-commands-test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ package body Alr.Commands.Test is
end if;
end Execute_Legacy;

--------------------------
-- Find_Root_With_Tests --
--------------------------

function Find_Root_With_Tests
(Cmd : in out Command) return Alire.Roots.Optional.Root
is
use Alire;

Res : Roots.Optional.Root := Cmd.Optional_Root;
begin
while Res.Is_Valid
and then
Res.Value.Release.On_Platform_Properties
(Res.Value.Environment, Properties.Tests.Settings'Tag)
.Is_Empty
loop
Res := Roots.Optional.Search_Root (Dirs.Parent (Res.Value.Path));
end loop;
return Res;
exception
when E : Dirs.Adirs.Use_Error =>
pragma Unreferenced (E);
-- return failure if there is no parent directory left to search
return
Roots.Optional.Outcome_Failure
(Res.Value.Path & " has no parent directory",
Comment on lines +79 to +82
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message "has no parent directory" is misleading. Use_Error is raised when the OS doesn't support directory manipulation, not when reaching the root directory. The normal case of reaching the filesystem root is handled by the loop condition (when Search_Root returns an invalid root). Consider either removing this exception handler (since Use_Error is very rare on modern systems) or updating the message to accurately describe the OS-level failure.

Suggested change
-- return failure if there is no parent directory left to search
return
Roots.Optional.Outcome_Failure
(Res.Value.Path & " has no parent directory",
-- Return failure if an operating system error prevents further
-- directory manipulation while searching for a test root.
return
Roots.Optional.Outcome_Failure
("failed to search parent directories of '"
& Res.Value.Path
& "' due to an operating system error (directory operations "
& "not supported)",

Copilot uses AI. Check for mistakes.
Roots.Optional.Outside,
Report => False);
end Find_Root_With_Tests;
Comment on lines +56 to +85
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This user-facing change (alr test searching parent directories for test runners, and the new --legacy flag) should be documented in doc/user-changes.md according to the pull request checklist. The PR description indicates this is a significant behavioral change that users should be aware of.

Copilot generated this review using guidance from repository custom instructions.

-------------
-- Execute --
-------------
Expand All @@ -68,13 +99,27 @@ package body Alr.Commands.Test is
begin
Cmd.Requires_Workspace;

if Cmd.Legacy then
Execute_Legacy (Cmd.Root);
return;
end if;

declare
Test_Root : Alire.Roots.Optional.Root := Cmd.Find_Root_With_Tests;
begin
if Test_Root.Is_Valid then
Cmd.Set (Test_Root.Value);
end if;
end;

All_Settings :=
Cmd.Root.Release.On_Platform_Properties
(Cmd.Root.Environment, Settings'Tag);

if All_Settings.Is_Empty then
Trace.Warning ("no test runner defined, running legacy actions");
Execute_Legacy (Cmd.Root);
return;
end if;

-- id selection logic
Expand Down Expand Up @@ -240,6 +285,15 @@ package body Alr.Commands.Test is
"--id=",
"Select a specific test runner by id",
Argument => "<id>");

Define_Switch
(Config,
Cmd.Legacy'Access,
"",
"--legacy",
CLIC.TTY.Error ("Deprecated")
& ". Force executing the legacy test actions",
Comment on lines +294 to +295
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text marks the flag itself as deprecated with error coloring, but it's the legacy test actions that are deprecated, not the --legacy flag itself. The flag is newly introduced to allow opting into the deprecated legacy behavior and to prevent parent directory search. Consider rephrasing to make this clearer, such as: "Force executing legacy test actions (prevents parent directory search)"

Suggested change
CLIC.TTY.Error ("Deprecated")
& ". Force executing the legacy test actions",
"Force executing legacy test actions (prevents parent directory"
& " search)",

Copilot uses AI. Check for mistakes.
Value => True);
end Setup_Switches;

end Alr.Commands.Test;
1 change: 1 addition & 0 deletions src/alr/alr-commands-test.ads
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private
type Command is new Commands.Command with record
Jobs : aliased Integer := 0;
By_Id : aliased GNAT.Strings.String_Access;
Legacy : aliased Boolean := False;
end record;

end Alr.Commands.Test;
14 changes: 12 additions & 2 deletions testsuite/tests/test/from-subdir/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Test that running `alr test` from a subdirectory other than the root and the
`tests` directory works as expected.
Test that running `alr test` from a subdirectory works as expected.
"""

from drivers.alr import init_local_crate, run_alr
Expand All @@ -20,4 +19,15 @@
p = run_alr("test")
assert_substring("[ PASS ]", p.out)

# create a subcrate two levels down without a `test` section
init_local_crate("yyy", with_test=False)
p = run_alr("test")
assert_substring("[ PASS ]", p.out)

# check that using `--legacy` does not run the testsuite from
# the toplevel crate
p = run_alr("test", "--legacy", quiet=False)
assert "[ PASS ]" not in p.out
assert_substring("Successful actions run", p.out)

print("SUCCESS")
Loading