Skip to content

Commit 7dbabc9

Browse files
committed
Merge branch 'topic/210-subp-name' into 'master'
Test: Add option to display the tested subprogram in the test runner log Closes #210 See merge request eng/ide/libadalang-tools!306
2 parents 1db1e96 + 706932a commit 7dbabc9

File tree

14 files changed

+104
-1
lines changed

14 files changed

+104
-1
lines changed

src/test-actions.adb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ package body Test.Actions is
577577
Test.Common.Show_Test_Duration := Arg (Cmd, Test_Duration);
578578
Test.Common.Relocatable_Harness := Arg (Cmd, Relocatable_Harness);
579579
Test.Common.Test_Filtering := Arg (Cmd, Test_Filtering);
580+
Test.Common.Include_Subp_Name := Arg (Cmd, Include_Subp_Name);
580581

581582
Test.Common.Strict_Execution := Arg (Cmd, Strict)
582583
or else (Ada.Environment_Variables.Exists ("GNATTEST_STRICT")
@@ -1321,6 +1322,7 @@ package body Test.Actions is
13211322
Put (" --exit-status=(on|off) - Default usage of the exit status\n");
13221323
Put (" --omit-sloc - Don't record subprogram sloc in test package\n");
13231324
Put (" --no-command-line - Don't add command line support to test driver\n");
1325+
Put (" --include-subp-name - Include the tested subprogram's name in the output\n");
13241326
Put (" --test-duration - Show timing for each test\n");
13251327
Put (" --test-filtering - Add test filtering option to generated driver\n");
13261328
Put (" --no-test-filtering - Suppress test filtering in generated driver\n");

src/test-command_lines.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ package Test.Command_Lines is
5353
Dump_Test_Inputs,
5454
Unparse,
5555
Enum_Strat,
56-
Minimize);
56+
Minimize,
57+
Include_Subp_Name);
5758

5859
package Test_Boolean_Switches is new Boolean_Switches
5960
(Descriptor,

src/test-common.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ package Test.Common is
120120
-- if Subp is a subprigram declaration it will return subprogram's name;
121121
-- if Subp is an overloaded operator - it's text name
122122

123+
function Get_Subp_FQN (Node : Basic_Decl'Class) return String is
124+
(Image (Node.As_Basic_Decl.P_Fully_Qualified_Name));
125+
-- Return the fully qualified name of Node
126+
123127
function Enclosing_Unit_Name (Node : Ada_Node'Class) return String is
124128
(Node_Image (P_Top_Level_Decl (Node, Node.Unit).P_Defining_Name));
125129
-- Returns name of the compilation unit enclosing given node
@@ -325,6 +329,10 @@ package Test.Common is
325329

326330
Reporter_Name : GNAT.OS_Lib.String_Access := new String'("gnattest");
327331

332+
Include_Subp_Name : Boolean := False;
333+
-- Whether the AUnit testcases' names should include the name of the
334+
-- subprogram. Default is False for backwards compatibility reasons.
335+
328336
No_Command_Line : Boolean := False;
329337

330338
Harness_Only : Boolean := False;

src/test-skeleton.adb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ package body Test.Skeleton is
536536
-- Returns the list of possible setters for all subprograms called from
537537
-- the body of given subprogram.
538538

539+
function Get_TR_Name_Suffix (Subp : Basic_Decl'Class) return String is
540+
(if Include_Subp_Name then " (" & Get_Subp_FQN (Subp) & ")" else "");
541+
-- Return the string that either contains the name of the tested subprogram
542+
-- in Subp in parenthesis, or the empty string, based on whether
543+
-- --include-subp-name was passed on the command line.
544+
539545
---------
540546
-- "<" --
541547
---------
@@ -1553,6 +1559,7 @@ package body Test.Skeleton is
15531559
& Trim (Subp_Span.Start_Line'Img, Both)
15541560
& ":"
15551561
& Trim (Subp_Span.Start_Column'Img, Both)
1562+
& Get_TR_Name_Suffix (Subp.Subp_Declaration.As_Basic_Decl)
15561563
& " instance at "
15571564
& Instance_Sloc.all);
15581565
else
@@ -1562,6 +1569,7 @@ package body Test.Skeleton is
15621569
& Trim (Subp_Span.Start_Line'Img, Both)
15631570
& ":"
15641571
& Trim (Subp_Span.Start_Column'Img, Both)
1572+
& Get_TR_Name_Suffix (Subp.Subp_Declaration.As_Basic_Decl)
15651573
& ":");
15661574
end if;
15671575
end;
@@ -2049,6 +2057,7 @@ package body Test.Skeleton is
20492057
& ":"
20502058
& Trim
20512059
(First_Column_Number (ISub)'Img, Both)
2060+
& Get_TR_Name_Suffix (ISub)
20522061
& ": inherited at "
20532062
& Base_Name (Type_Dec.Unit.Get_Filename)
20542063
& ":"
@@ -2200,6 +2209,7 @@ package body Test.Skeleton is
22002209
& Trim
22012210
(First_Column_Number (OSub)'Img,
22022211
Both)
2212+
& Get_TR_Name_Suffix (OSub)
22032213
& ": overridden at "
22042214
& Base_Name
22052215
(TR_W.Original_Type.Unit.Get_Filename)
@@ -3595,6 +3605,7 @@ package body Test.Skeleton is
35953605
& Trim (First_Line_Number (TC.Elem)'Img, Both)
35963606
& ":"
35973607
& Trim (First_Column_Number (TC.Elem)'Img, Both)
3608+
& (if Include_Subp_Name then " (" & TC.Name.all & ")" else "")
35983609
& ":");
35993610
else
36003611
TR_Info_Add.TR_Info.Tested_Sloc := new String'
@@ -3603,6 +3614,7 @@ package body Test.Skeleton is
36033614
& Trim (First_Line_Number (TC.Elem)'Img, Both)
36043615
& ":"
36053616
& Trim (First_Column_Number (TC.Elem)'Img, Both)
3617+
& (if Include_Subp_Name then " (" & TC.Name.all & ")" else "")
36063618
& " instance at "
36073619
& Instance_Sloc);
36083620
end if;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package body Gen is
2+
3+
procedure Gen (X : T) is
4+
begin
5+
null;
6+
end Gen;
7+
8+
end Gen;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
generic
2+
type T is private;
3+
package Gen is
4+
procedure Gen (X : T);
5+
end Gen;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package body Pkg is
2+
3+
procedure Simple (X : Integer) is null;
4+
procedure With_TC (X : Integer) is null;
5+
6+
procedure Inherited_Prim (X : Pkg_T) is null;
7+
procedure Overridden_Prim (X : Pkg_T) is null;
8+
9+
procedure Generic_Proc (X : T) is null;
10+
11+
end Pkg;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Pkg is
2+
3+
procedure Simple (X : Integer);
4+
procedure With_TC (X : Integer);
5+
6+
type Pkg_T is tagged null record;
7+
8+
procedure Inherited_Prim (X : Pkg_T);
9+
procedure Overridden_Prim (X : Pkg_T);
10+
11+
generic
12+
type T is private;
13+
procedure Generic_Proc (X : T);
14+
15+
end Pkg;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project Prj is
2+
3+
for Object_Dir use "obj";
4+
5+
end Prj;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pkg.ads:8:4 (Pkg.Inherited_Prim): info: corresponding test PASSED
2+
pkg.ads:9:4 (Pkg.Overridden_Prim): info: corresponding test PASSED
3+
pkg.ads:3:4 (Pkg.Simple): info: corresponding test PASSED
4+
pkg.ads:4:4 (Pkg.With_TC): info: corresponding test PASSED
5+
gen.ads:4:4 (Gen.Gen) instance at user.ads:11:4: info: corresponding test PASSED
6+
user.ads:7:4 (User.Overridden_Prim): info: corresponding test PASSED
7+
pkg.ads:8:4 (Pkg.Inherited_Prim): inherited at user.ads:6:4: info: corresponding test PASSED
8+
pkg.ads:9:4 (Pkg.Overridden_Prim): overridden at user.ads:7:4: info: corresponding test PASSED
9+
8 tests run: 8 passed; 0 failed; 0 crashed.

0 commit comments

Comments
 (0)