Skip to content

Commit

Permalink
Expand test to ensure all invocations work
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Oct 27, 2024
1 parent 290f12e commit 48a13e6
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 62 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
path = deps/gnatcoll-slim
url = https://github.com/alire-project/gnatcoll-core.git
branch = slim
[submodule "testsuite/fixtures/crates/libhello_git"]
path = testsuite/fixtures/crates/libhello_git
url = https://github.com/alire-project/libhello.git
[submodule "deps/ansi"]
path = deps/ansi
url = https://github.com/mosteo/ansi-ada
Expand Down
1 change: 0 additions & 1 deletion src/alire/alire-spawn.adb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ package body Alire.Spawn is
"-j0" & -- Build in parallel
"-p" & -- Create missing obj, lib and exec dirs
"-P" & Project_File &
"-cargs" & "-gnatW8" &
Extra_Args,
Understands_Verbose => True);
end Gprbuild;
Expand Down
134 changes: 105 additions & 29 deletions src/alr/alr-commands-test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,103 @@ package body Alr.Commands.Test is

procedure Default_Test is

-- Used to test indexed crates
Alr_Args : constant AAA.Strings.Vector :=
Empty_Vector &
Regular_Alr_Switches &
"get" &
(if R.Origin.Kind in Alire.Origins.Binary_Archive
then Empty_Vector
else To_Vector ("--build")) &
R.Milestone.Image;

-- Used to test the local crate
Alr_Local : constant AAA.Strings.Vector :=
Empty_Vector &
Regular_Alr_Switches &
"build" &
"--release";

Alr_Default : constant AAA.Strings.Vector
:= (if Local
then "alr" & Alr_Local
else "alr" & Alr_Args);
----------------
-- Local_Test --
----------------

procedure Local_Test (Output : in out AAA.Strings.Vector;
Code : out Integer)
is
Command : constant AAA.Strings.Vector :=
"alr"
& Regular_Alr_Switches
& "build"
& "--release";
begin
-- Default test for a local crate is just an `alr build` in
-- release mode.

Output.Append_Line
("[alr test] Spawning default local test: "
& Command.Flatten);

Code := Unchecked_Spawn_And_Capture
(Command.First_Element,
Command.Tail,
Output,
Err_To_Out => True);
end Local_Test;

-----------------
-- Remote_Test --
-----------------

procedure Remote_Test (Output : in out AAA.Strings.Vector;
Code : out Integer)
is
Command : constant AAA.Strings.Vector :=
"alr"
& Regular_Alr_Switches
& "get"
& R.Milestone.Image;
begin
-- Start with a standard crate retrieval

Output.Append_Line
("[alr test] Spawning retrieval for remote crate: "
& Command.Flatten);

Code := Unchecked_Spawn_And_Capture
(Command.First_Element,
Command.Tail,
Output,
Err_To_Out => True);

-- Enter the build folder if necessary, otherwise the test
-- has ended.

if not R.Origin.Requires_Build then
return;
end if;

-- Default build for a remote crate is a release build,
-- respecting configuration of dependencies' profiles. We
-- conservatively disable warnings as errors. We must enter
-- the just retrieved crate to spawn.

declare
CD : Folder_Guard (Enter_Folder (R.Base_Folder))
with Unreferenced;

Command : constant AAA.Strings.Vector :=
"alr"
& Regular_Alr_Switches
& "build"
& "--release"
& "--"
& "-cargs:Ada"
& "-gnatwn";
begin
Output.Append_Line
("[alr test] Spawning default test for remote crate: "
& Command.Flatten);

Code := Unchecked_Spawn_And_Capture
(Command.First_Element,
Command.Tail,
Output,
Err_To_Out => True);
end;
end Remote_Test;

Exit_Code : Integer := Integer'First;

Exit_Code : Integer;
begin
Output.Append_Line ("Spawning: " & Alr_Default.Flatten);
Exit_Code := Unchecked_Spawn_And_Capture
(Alr_Default.First_Element,
Alr_Default.Tail,
Output,
Err_To_Out => True);
if Local then
Local_Test (Output, Exit_Code);
else
Remote_Test (Output, Exit_Code);
end if;

if Exit_Code /= 0 then
raise Child_Failed;
Expand Down Expand Up @@ -238,7 +305,9 @@ package body Alr.Commands.Test is
end if;
end if;

-- And run its actions in its working directory
-- And run its actions in its working directory. Note that
-- no environment is set up, the test action should do it
-- if needed (e.g. through `alr exec --`).

declare
Guard : Alire.Directories.Guard
Expand Down Expand Up @@ -309,9 +378,14 @@ package body Alr.Commands.Test is
Trace.Detail ("Skipping already tested " & R.Milestone.Image);
else
begin
Output.Append ("[alr test] Testing " & R.Milestone.Image);

-- Perform default or custom actions
Test_Action;

-- At this point the test ended successfully
Output.Append ("[alr test] Test completed SUCCESSFULLY");

Reporters.End_Test (R, Testing.Pass, Clock - Start, Output);
Trace.Detail (Output.Flatten (Newline));

Expand Down Expand Up @@ -577,6 +651,8 @@ package body Alr.Commands.Test is
else
Trace.Detail ("Testing all releases");
end if;
elsif Args.Count > 0 then
Trace.Detail ("Testing crates given as arguments");
else
if Cmd.Has_Root then
Alire.Put_Info ("Testing local crate: "
Expand Down
43 changes: 43 additions & 0 deletions testsuite/tests/test/default-remote-test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Check that the default "get & build" test for remote crates in `alr test` works
"""

import re
import os

from drivers.alr import run_alr
from drivers.asserts import assert_match, assert_in_file
from drivers.helpers import content_of
from e3.fs import rm
from glob import glob

test_args = [
["--full"], # No arguments (all crates)
["hello"], # Subset of crates
["--search", "hell"], # Subset given as substring
]

for args in test_args:

# Enter an empty folder

if os.path.exists("t"):
rm("t", recursive=True)
os.mkdir("t")
os.chdir("t")

run_alr("test", *args) # Should not err

# Check test outcome
assert_match(".*" +
re.escape("pass:hello=1.0.0") + ".*" +
re.escape("pass:hello=1.0.1") + ".*",
content_of(glob("*.txt")[0]))

# Check the build is performed in release mode
assert_in_file(os.path.join(glob("hello_1.0.1_*")[0], "config", "hello_config.gpr"),
'Build_Profile : Build_Profile_Kind := "release";')

os.chdir("..")

print('SUCCESS')
File renamed without changes.
29 changes: 0 additions & 29 deletions testsuite/tests/test/default-test/test.py

This file was deleted.

0 comments on commit 48a13e6

Please sign in to comment.