Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing generic Assert #31

Open
pjljvandelaar opened this issue May 28, 2021 · 0 comments
Open

Missing generic Assert #31

pjljvandelaar opened this issue May 28, 2021 · 0 comments

Comments

@pjljvandelaar
Copy link

pjljvandelaar commented May 28, 2021

Dear AUnit developers,

AUnit provides


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant