Skip to content

Commit 56a629e

Browse files
committed
add a --list flag to alr test
1 parent e4e2b89 commit 56a629e

File tree

5 files changed

+120
-30
lines changed

5 files changed

+120
-30
lines changed

src/alire/alire-test_runner.adb

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -486,28 +486,17 @@ package body Alire.Test_Runner is
486486
end loop;
487487
end Run_All_Tests;
488488

489-
---------
490-
-- Run --
491-
---------
489+
-------------------
490+
-- Get_File_List --
491+
-------------------
492492

493-
function Run
494-
(Root : in out Roots.Root;
495-
Filter : AAA.Strings.Vector := AAA.Strings.Empty_Vector;
496-
Jobs : Natural := 0) return Integer
493+
function Get_File_List
494+
(Root : Roots.Root; Filter : AAA.Strings.Vector)
495+
return Portable_Path_Vector
497496
is
498-
use all type AAA.Strings.Vector;
499-
500-
Job_Count : constant Positive :=
501-
(if Jobs = 0
502-
then Positive (System.Multiprocessors.Number_Of_CPUs)
503-
else Jobs);
504-
Path : constant Absolute_Path := Root.Path;
505-
506-
Crate_Prefix : constant String := Root_Prefix (Root);
507-
Original_Switch_Q : constant Boolean := Alire_Early_Elaboration.Switch_Q;
497+
Crate_Prefix : constant String := Root_Prefix (Root);
508498

509499
Test_List : Portable_Path_Vector;
510-
511500
--------------------
512501
-- Matches_Filter --
513502
--------------------
@@ -551,10 +540,30 @@ package body Alire.Test_Runner is
551540
Test_List.Append (Name);
552541
end if;
553542
end Append;
554-
555543
begin
556-
Den.Walk.Find (This => Path / "src", Action => Append'Access);
544+
Den.Walk.Find (This => Root.Path / "src", Action => Append'Access);
545+
return Test_List;
546+
end Get_File_List;
557547

548+
---------
549+
-- Run --
550+
---------
551+
552+
function Run
553+
(Root : in out Roots.Root;
554+
Filter : AAA.Strings.Vector := AAA.Strings.Empty_Vector;
555+
Jobs : Natural := 0) return Integer
556+
is
557+
Job_Count : constant Positive :=
558+
(if Jobs = 0
559+
then Positive (System.Multiprocessors.Number_Of_CPUs)
560+
else Jobs);
561+
562+
Original_Switch_Q : constant Boolean := Alire_Early_Elaboration.Switch_Q;
563+
564+
Test_List : constant Portable_Path_Vector :=
565+
Get_File_List (Root, Filter);
566+
begin
558567
Create_Gpr_List (Root, Test_List);
559568

560569
-- Ensure a void solution on first test run
@@ -584,4 +593,52 @@ package body Alire.Test_Runner is
584593
return 1;
585594
end if;
586595
end Run;
596+
597+
---------------
598+
-- Show_List --
599+
---------------
600+
601+
procedure Show_List
602+
(Root : Roots.Root;
603+
Filter : AAA.Strings.Vector := AAA.Strings.Empty_Vector)
604+
is
605+
Crate_Prefix : constant String := Root_Prefix (Root);
606+
Path : constant Absolute_Path := Root.Path;
607+
Test_List : constant Portable_Path_Vector :=
608+
Get_File_List (Root, Filter);
609+
begin
610+
if Tables.Structured_Output then
611+
declare
612+
Builder : LML.Output.Builder'Class :=
613+
LML.Output.Factory.Get (Tables.Structured_Output_Format);
614+
begin
615+
Builder.Begin_Map;
616+
Builder.Insert (LML.Decode (TOML_Keys.Test_Report_Cases));
617+
Builder.Begin_Map;
618+
for Test of Test_List loop
619+
Builder.Insert (LML.Decode (Display_Name (Test, Crate_Prefix)));
620+
Builder.Begin_Map;
621+
Builder.Insert (LML.Decode (TOML_Keys.Test_Report_Path));
622+
Builder.Append
623+
(LML.Scalars.New_Text
624+
(LML.Decode (Path / "src" / String (Test))));
625+
Builder.End_Map;
626+
end loop;
627+
Builder.End_Map;
628+
Builder.End_Map;
629+
630+
Trace.Always (LML.Encode (Builder.To_Text));
631+
end;
632+
else
633+
Put_Info ("Matching tests:");
634+
for Test of Test_List loop
635+
Trace.Info
636+
(" "
637+
& Display_Name (Test, Crate_Prefix)
638+
& (if Alire_Early_Elaboration.Switch_V
639+
then " (" & (Path / "src" / String (Test)) & ")"
640+
else ""));
641+
end loop;
642+
end if;
643+
end Show_List;
587644
end Alire.Test_Runner;

src/alire/alire-test_runner.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ package Alire.Test_Runner is
1111
-- Run all .adb files in the `src` folder of the given root as
1212
-- separate tests. Return the number of failing tests.
1313

14+
procedure Show_List
15+
(Root : Roots.Root;
16+
Filter : AAA.Strings.Vector := AAA.Strings.Empty_Vector);
17+
-- Print a list of matching tests without running them. Respects structured
18+
-- output.
19+
1420
end Alire.Test_Runner;

src/alire/alire-toml_keys.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ package Alire.TOML_Keys with Preelaborate is
6868
Test_Report_Reason : constant String := "reason";
6969
Test_Report_Output : constant String := "output";
7070
Test_Report_Duration : constant String := "duration";
71+
Test_Report_Path : constant String := "path";
7172
Test_Report_Summary : constant String := "summary";
7273
Test_Report_Total : constant String := "total";
7374
Test_Report_Failures : constant String := "failures";

src/alr/alr-commands-test.adb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ package body Alr.Commands.Test is
2929
(Root.Environment,
3030
(Alire.Properties.Actions.Test => True, others => False))
3131
.Is_Empty
32-
and then not Alire.Roots.Build
33-
(Root,
34-
AAA.Strings.Empty_Vector,
35-
Saved_Profiles => False)
32+
and then
33+
not Alire.Roots.Build
34+
(Root, AAA.Strings.Empty_Vector, Saved_Profiles => False)
3635
then
3736
Success := 1;
3837
else
@@ -100,6 +99,8 @@ package body Alr.Commands.Test is
10099
Cmd.Requires_Workspace;
101100

102101
if Cmd.Legacy then
102+
Cmd.Forbids_Structured_Output
103+
("Cannot use structured output with legacy actions");
103104
Execute_Legacy (Cmd.Root);
104105
return;
105106
end if;
@@ -118,6 +119,8 @@ package body Alr.Commands.Test is
118119

119120
if All_Settings.Is_Empty then
120121
Trace.Warning ("no test runner defined, running legacy actions");
122+
Cmd.Forbids_Structured_Output
123+
("Cannot use structured output with legacy actions");
121124
Execute_Legacy (Cmd.Root);
122125
return;
123126
end if;
@@ -158,10 +161,18 @@ package body Alr.Commands.Test is
158161
and then Settings (All_Settings.First_Element).Runner.Kind = External
159162
and then Cmd.Jobs >= 0
160163
then
161-
Trace.Warning
162-
("the --jobs flag is not forwarded to external commands. If you "
163-
& "intended to pass it to an external test runner, put it after "
164-
& """--"" in the command line.");
164+
if Cmd.Jobs >= 0 then
165+
Trace.Warning
166+
("the --jobs flag is not forwarded to external commands. If you "
167+
& "intended to pass it to an external test runner, put it after"
168+
& " ""--"" in the command line.");
169+
end if;
170+
if Cmd.List then
171+
Trace.Warning
172+
("the --list flag is not forwarded to external commands. If you "
173+
& "intended to pass it to an external test runner, put it after"
174+
& " ""--"" in the command line.");
175+
end if;
165176
end if;
166177

167178
for Test_Setting of All_Settings loop
@@ -200,6 +211,12 @@ package body Alr.Commands.Test is
200211
& ")");
201212
end if;
202213

214+
if Cmd.List then
215+
Alire.Test_Runner.Show_List
216+
(Test_Root.Value, Get_Args);
217+
OS_Lib.Bailout;
218+
end if;
219+
203220
Failures :=
204221
Alire.Test_Runner.Run
205222
(Test_Root.Value,
@@ -294,6 +311,14 @@ package body Alr.Commands.Test is
294311
CLIC.TTY.Error ("Deprecated")
295312
& ". Force executing the legacy test actions",
296313
Value => True);
314+
315+
Define_Switch
316+
(Config,
317+
Cmd.List'Access,
318+
"",
319+
"--list",
320+
"Show a list of matching tests without running them",
321+
Value => True);
297322
end Setup_Switches;
298323

299324
end Alr.Commands.Test;

src/alr/alr-commands-test.ads

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ package Alr.Commands.Test is
3535
private
3636

3737
type Command is new Commands.Command with record
38-
Jobs : aliased Integer := 0;
39-
By_Id : aliased GNAT.Strings.String_Access;
38+
Jobs : aliased Integer := 0;
39+
By_Id : aliased GNAT.Strings.String_Access;
4040
Legacy : aliased Boolean := False;
41+
List : aliased Boolean := False;
4142
end record;
4243

4344
end Alr.Commands.Test;

0 commit comments

Comments
 (0)