diff --git a/include/aunit/framework/aunit-test_filters.adb b/include/aunit/framework/aunit-test_filters.adb index ade6152..79a7817 100644 --- a/include/aunit/framework/aunit-test_filters.adb +++ b/include/aunit/framework/aunit-test_filters.adb @@ -58,6 +58,16 @@ package body AUnit.Test_Filters is Filter.Name := Format (Name); end Set_Name; + --------------------- + -- Set_Exact_Match -- + --------------------- + + procedure Set_Exact_Match (Filter : in out Name_Filter; + Exact_Match : Boolean) is + begin + Filter.Exact_Match := Exact_Match; + end Set_Exact_Match; + --------------- -- Is_Active -- --------------- @@ -80,15 +90,28 @@ package body AUnit.Test_Filters is end if; if Routine_Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)) = null then - return Starts_With - (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, - Filter.Name.all); + if Filter.Exact_Match then + return Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all + = Filter.Name.all; + else + return Starts_With + (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, + Filter.Name.all); + end if; else - return Starts_With - (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all - & " : " - & Routine_Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, - Filter.Name.all); + if Filter.Exact_Match then + return Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all + & " : " + & Routine_Name + (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all + = Filter.Name.all; + else + return Starts_With + (Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all + & " : " + & Routine_Name (AUnit.Simple_Test_Cases.Test_Case'Class (T)).all, + Filter.Name.all); + end if; end if; end Is_Active; diff --git a/include/aunit/framework/aunit-test_filters.ads b/include/aunit/framework/aunit-test_filters.ads index c8a1c60..3156b42 100644 --- a/include/aunit/framework/aunit-test_filters.ads +++ b/include/aunit/framework/aunit-test_filters.ads @@ -51,6 +51,7 @@ package AUnit.Test_Filters is procedure Set_Name (Filter : in out Name_Filter; Name : String); -- Set the name of the test(s) to run. + -- If Exact_Match is set to True, only test with given name will be run. -- The name can take several forms: -- * Either the fully qualified name of the test (including routine). -- For instance, if you have an instance of @@ -61,6 +62,10 @@ package AUnit.Test_Filters is -- all routines for instance -- If the name is the empty string, all tests will be run + procedure Set_Exact_Match (Filter : in out Name_Filter; + Exact_Match : Boolean); + -- Enables/disables exact name matching + function Is_Active (Filter : Name_Filter; T : AUnit.Tests.Test'Class) return Boolean; @@ -70,7 +75,8 @@ private type Test_Filter is abstract tagged limited null record; type Name_Filter is new Test_Filter with record - Name : Message_String; + Name : Message_String; + Exact_Match : Boolean := False; end record; end AUnit.Test_Filters; diff --git a/test/src/aunit_harness.adb b/test/src/aunit_harness.adb index 9e3ad2f..c480dce 100644 --- a/test/src/aunit_harness.adb +++ b/test/src/aunit_harness.adb @@ -14,9 +14,10 @@ procedure AUnit_Harness is procedure Harness is new AUnit.Run.Test_Runner (Suite); -- The full test harness - Reporter : AUnit.Reporter.Text.Text_Reporter; - Filter : aliased AUnit.Test_Filters.Name_Filter; - Options : AUnit.Options.AUnit_Options := + Reporter : AUnit.Reporter.Text.Text_Reporter; + Filter : aliased AUnit.Test_Filters.Name_Filter; + Exact_Filter : aliased AUnit.Test_Filters.Name_Filter; + Options : AUnit.Options.AUnit_Options := (Global_Timer => False, Test_Case_Timer => True, Report_Successes => True, @@ -29,9 +30,14 @@ begin -- This filter should be initialized from the command line arguments. In -- this example, we don't do it to support limited runtimes with no support -- for Ada.Command_Line - Options.Filter := Filter'Unchecked_Access; - Set_Name (Filter, "(test_case) Test routines registration"); + Set_Name (Filter, "(suite)"); + Harness (Reporter, Options); + + -- Test exact match option of the filter + Options.Filter := Exact_Filter'Unchecked_Access; + Set_Name (Exact_Filter, "(test_case) Test routines registration"); + Set_Exact_Match (Exact_Filter, False); Harness (Reporter, Options); end AUnit_Harness;