-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Dear AUnit developers,
AUnit provides
| procedure Assert |
to compare the expected and actual values of
Strings.
I am missing similar Asserts for other types than String.
This can be solved by a generic specified as
generic
type Element_T is (<>);
procedure Generic_Assert
(Actual : Element_T;
Expected : Element_T;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line);
-- Specialized versions of Assert, they call the general version that
-- takes a Condition as a parameter
and implemented as
procedure Generic_Assert
(Actual : Element_T;
Expected : Element_T;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line)
is
begin
Assert
(Condition => Expected = Actual,
Message => Message & ASCII.CR & ASCII.LF &
"Expected : " & Element_T'Image (Expected) & ASCII.CR & ASCII.LF &
"Actual : " & Element_T'Image (Actual),
Source => Source,
Line => Line
);
end Assert;
and use it as follows
procedure Assert is new AUnit.Assertions.Generic_Assert (Count_Type);
....
Assert (Expected => Lead.Length,
Actual => Actual_Lead.Length,
Message => "Different sizes of Lead");
...
With Ada2020, the generic can even be made more general, since Image is defined on more types.
Could you consider adding this functionality to AUnit?
Since it will make my test cases shorter, clearer and easier to read.
Greetings,
Pierre
Metadata
Metadata
Assignees
Labels
No labels