Missing generic Assert
Nobody has claimed this yet.
- Dominant language
- Ada
- Stars
- 13
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Dear AUnit developers,
AUnit provides
https://github.com/AdaCore/aunit/blob/552a2404ce283f74c9f7082730703cf52e5d7004/include/aunit/framework/aunit-assertions.adb#L99
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with include/aunit/framework/aunit-assertions.adb around line 99, where the existing String assertion is defined. Compare the proposed Generic_Assert signature and implementation with the surrounding assertion API. Done means AUnit offers the requested generic assertion for comparable non-String types, while preserving the expected message, source, and line information.
Written by the indexing model from the issue text.
Assessment
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100