From 48a13e64231935e8bec5c465c24e2d44a1ad5676 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Sun, 27 Oct 2024 19:14:46 +0100 Subject: [PATCH] Expand test to ensure all invocations work --- .gitmodules | 3 - src/alire/alire-spawn.adb | 1 - src/alr/alr-commands-test.adb | 134 ++++++++++++++---- .../tests/test/default-remote-test/test.py | 43 ++++++ .../test.yaml | 0 testsuite/tests/test/default-test/test.py | 29 ---- 6 files changed, 148 insertions(+), 62 deletions(-) create mode 100644 testsuite/tests/test/default-remote-test/test.py rename testsuite/tests/test/{default-test => default-remote-test}/test.yaml (100%) delete mode 100644 testsuite/tests/test/default-test/test.py diff --git a/.gitmodules b/.gitmodules index 3054b0373..a75b444a3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/src/alire/alire-spawn.adb b/src/alire/alire-spawn.adb index 618947a16..fb5369e2b 100644 --- a/src/alire/alire-spawn.adb +++ b/src/alire/alire-spawn.adb @@ -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; diff --git a/src/alr/alr-commands-test.adb b/src/alr/alr-commands-test.adb index f44290111..4036bc0f1 100644 --- a/src/alr/alr-commands-test.adb +++ b/src/alr/alr-commands-test.adb @@ -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; @@ -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 @@ -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)); @@ -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: " diff --git a/testsuite/tests/test/default-remote-test/test.py b/testsuite/tests/test/default-remote-test/test.py new file mode 100644 index 000000000..f7ed70d48 --- /dev/null +++ b/testsuite/tests/test/default-remote-test/test.py @@ -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') diff --git a/testsuite/tests/test/default-test/test.yaml b/testsuite/tests/test/default-remote-test/test.yaml similarity index 100% rename from testsuite/tests/test/default-test/test.yaml rename to testsuite/tests/test/default-remote-test/test.yaml diff --git a/testsuite/tests/test/default-test/test.py b/testsuite/tests/test/default-test/test.py deleted file mode 100644 index 69f196898..000000000 --- a/testsuite/tests/test/default-test/test.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Check that the default "get & build" test for `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 glob import glob - -# Enter an empty folder -os.mkdir("t") -os.chdir("t") - -run_alr("test", "hello") # 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";') - -print('SUCCESS')