Skip to content

Commit

Permalink
alr test: Allow binary releases to not contain project files (#1159)
Browse files Browse the repository at this point in the history
* Allow binary releases to not contain project files

* Fix logic and output to test log instead of stdout
  • Loading branch information
mosteo authored and actions-user committed Aug 26, 2022
1 parent 02e8375 commit 4f9191a
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions src/alr/alr-commands-test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ with Alire.Dependencies;
with Alire.Directories;
with Alire.Index;
with Alire.Milestones;
with Alire.Origins;
with Alire.OS_Lib.Subprocess;
with Alire.Platforms.Current;
with Alire.Properties.Actions.Executor;
Expand Down Expand Up @@ -42,30 +43,51 @@ package body Alr.Commands.Test is
-- Check_Files --
-----------------

function Check_Files (R : Alire.Index.Release) return Boolean is
function Check_Files (Output : in out AAA.Strings.Vector;
R : Alire.Index.Release) return Boolean
is
use AAA.Strings;
use Ada.Directories;
begin
-- Declared GPR files in include paths
declare
Guard : Folder_Guard (Enter_Folder (R.Base_Folder))
with Unreferenced;
begin

-- Check project files. We allow a binary release to not contain
-- project files, but if it declares a non-standard one (why?) it
-- should be there.

for Gpr of R.Project_Files (Platform.Properties, With_Path => True)
loop
if not OS_Lib.Is_Regular_File (Gpr) then
Trace.Error ("Declared project file not found: " & Gpr);
if OS_Lib.Is_Regular_File (Gpr) then
Output.Append_Line ("Found declared GPR file: " & Gpr);
elsif R.Origin.Kind in Alire.Origins.Binary_Archive and then
To_Lower_Case (Base_Name (Gpr)) = R.Name_Str
then
Output.Append_Line
("Warning: Binary release does not contain default "
& "project file: " & Simple_Name (Gpr));
else
Output.Append_Line
("FAIL: Declared project file not found: " & Gpr
& " while at " & Ada.Directories.Current_Directory);
return False;
end if;
end loop;
end;

-- Generated executables

for Exe of R.Executables (Platform.Properties) loop
if Files.Locate_File_Under (Folder => R.Base_Folder,
Name => Exe,
Max_Depth => Natural'Last).Is_Empty
then
Trace.Error
("Declared executable not found after compilation: " & Exe);
Output.Append_Line
("FAIL: Declared executable not found after compilation: "
& Exe);
return False;
end if;
end loop;
Expand Down Expand Up @@ -152,7 +174,9 @@ package body Alr.Commands.Test is
"-d" &
"-n" &
"get" &
"--build" &
(if R.Origin.Kind in Alire.Origins.Binary_Archive
then Empty_Vector
else To_Vector ("--build")) &
R.Milestone.Image;

Docker_Default : constant AAA.Strings.Vector :=
Expand Down Expand Up @@ -183,7 +207,9 @@ package body Alr.Commands.Test is
end if;

-- Check declared gpr/executables in place
if not R.Origin.Is_System and then not Check_Files (R) then
if not R.Origin.Is_System and then
not Check_Files (Output, R)
then
raise Child_Failed with "Declared executable(s) missing";
end if;
end Default_Test;
Expand Down Expand Up @@ -338,9 +364,24 @@ package body Alr.Commands.Test is
Reporters.Start_Run ("alr_test_" & Timestamp,
Natural (Releases.Length));

for R of Releases loop
Test_Release (R);
end loop;
declare
Old_Level : constant Simple_Logging.Levels := Alire.Log_Level;
begin

-- While we test the releases we do not want any info level output to
-- interfere. So, if the level is set at the default, we temporarily
-- silence it.

if Old_Level = Info then
Alire.Log_Level := Simple_Logging.Warning;
end if;

for R of Releases loop
Test_Release (R);
end loop;

Alire.Log_Level := Old_Level;
end;

Reporters.End_Run;

Expand Down

0 comments on commit 4f9191a

Please sign in to comment.