* AUnit: access to local procedure needed when asserting exception
@ 2011-12-06 1:12 Georg Bauhaus
2011-12-06 11:00 ` Georg Bauhaus
2011-12-06 12:25 ` Simon Wright
0 siblings, 2 replies; 6+ messages in thread
From: Georg Bauhaus @ 2011-12-06 1:12 UTC (permalink / raw)
In agreement with AUnit's docs, I wanted to write a test routine
that tests for an exception being raised. To do so, I wrote
a local procedure that would become a parameter of a generic
procedure Assert_Exception. However, this generic is gone from AUnit
(the one distributed with both GNAT GPL 2010 and 2011),
and seems to have been replaced with a non-generic procedure that
takes an object of pointer-to-procedure type instead.
The pointer-to-procedure,
type Throwing_Exception_Proc is access procedure;
is defined at library level in AUnit.Assertions.
Consequently, when seeing procedure Test_Null mostly reproduced below,
the compiler diagnoses (correctly, I think)
66. AUnit.Assertions.Assert_Exception (Null_Raises'Access,
|
>>> subprogram must not be deeper than access type
procedure Test_Null (Test : in out Test_Case'Class)
is
procedure Null_Raises is
Position : Natural;
begin
Position := Find (Search_Test(Test).Buffer,
Get_Null_Pattern, 1);
end Null_Raises;
--procedure Assert_Raises is
-- new AUnit.Assertions.Assert_Exception (Null_Raises);
begin
AUnit.Assertions.Assert_Exception (Null_Raises'Access,
"null string raises Pattern_Error");
end Test_Null;
I should be able to write the tests differently, so that everything
necessary for the test routine is declared at the same level as
the pointer-to-procedure type requires. But why is the simpler
generic gone? I also imagine that the authors of AUnit have had good
reason to introduce a named type---preventing access to local procedures.
Am I missing something?
Georg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: AUnit: access to local procedure needed when asserting exception
2011-12-06 1:12 AUnit: access to local procedure needed when asserting exception Georg Bauhaus
@ 2011-12-06 11:00 ` Georg Bauhaus
2011-12-06 12:25 ` Simon Wright
1 sibling, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2011-12-06 11:00 UTC (permalink / raw)
On 06.12.11 02:12, Georg Bauhaus wrote:
> I should be able to write the tests differently, so that everything
> necessary for the test routine is declared at the same level as
> the pointer-to-procedure type requires. But why is the simpler
> generic gone? I also imagine that the authors of AUnit have had good
> reason to introduce a named type---preventing access to local procedures.
> Am I missing something?
Wild guess: Assert_Exception is written so that it can be used unchanged
with every run-time that AdaCore is currently supporting, including ZFP,
and Ada 95. The comments on Ada_Containers.AUnit_Lists seem to confirm this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: AUnit: access to local procedure needed when asserting exception
2011-12-06 1:12 AUnit: access to local procedure needed when asserting exception Georg Bauhaus
2011-12-06 11:00 ` Georg Bauhaus
@ 2011-12-06 12:25 ` Simon Wright
2011-12-06 18:16 ` Georg Bauhaus
1 sibling, 1 reply; 6+ messages in thread
From: Simon Wright @ 2011-12-06 12:25 UTC (permalink / raw)
Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:
> Consequently, when seeing procedure Test_Null mostly reproduced below,
> the compiler diagnoses (correctly, I think)
>
> 66. AUnit.Assertions.Assert_Exception (Null_Raises'Access,
> |
> >>> subprogram must not be deeper than access type
At this point I tend to just use 'Unrestricted_Access.
I've never quite understood the point of this facility, what's wrong
with
begin
-- do whatever should raise The_Exception
Assert (C, False, "should have raised The_Exception");
exception
when The_Exception => null;
end;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: AUnit: access to local procedure needed when asserting exception
2011-12-06 12:25 ` Simon Wright
@ 2011-12-06 18:16 ` Georg Bauhaus
2011-12-06 20:02 ` Simon Wright
0 siblings, 1 reply; 6+ messages in thread
From: Georg Bauhaus @ 2011-12-06 18:16 UTC (permalink / raw)
On 06.12.11 13:25, Simon Wright wrote:
> Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:
>
>> Consequently, when seeing procedure Test_Null mostly reproduced below,
>> the compiler diagnoses (correctly, I think)
>>
>> 66. AUnit.Assertions.Assert_Exception (Null_Raises'Access,
>> |
>> >>> subprogram must not be deeper than access type
>
> At this point I tend to just use 'Unrestricted_Access.
>
> I've never quite understood the point of this facility, what's wrong
> with
>
> begin
> -- do whatever should raise The_Exception
> Assert (C, False, "should have raised The_Exception");
> exception
> when The_Exception => null;
> end;
Nothing wrong. The line numbers will be one off or so.
Actually, this is very close to how it is implemented
for run-times that support exception handling.
The generic was easily added.
generic
with procedure Proc;
procedure Generic_Assert_Exception
(Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line);
-- Generic equivalent of Assert_Exception.
procedure Generic_Assert_Exception
(Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
begin
Proc;
exception
when others =>
return;
end;
-- No exception raised: register the failure message
Assert (False, Message, Source, Line);
end Generic_Assert_Exception;
OTOH, specific Assert procedures made for exceptions will create a way
to collect tests into two groups; one group for tests that
compare values and another group for testing exceptional situations,
I/O error, failures expressed as pre/post/inv, ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: AUnit: access to local procedure needed when asserting exception
2011-12-06 18:16 ` Georg Bauhaus
@ 2011-12-06 20:02 ` Simon Wright
2011-12-06 21:42 ` Georg Bauhaus
0 siblings, 1 reply; 6+ messages in thread
From: Simon Wright @ 2011-12-06 20:02 UTC (permalink / raw)
Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:
> On 06.12.11 13:25, Simon Wright wrote:
>> Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:
>> I've never quite understood the point of this facility, what's wrong
>> with
>>
>> begin
>> -- do whatever should raise The_Exception
>> Assert (C, False, "should have raised The_Exception");
>> exception
>> when The_Exception => null;
>> end;
>
> Nothing wrong. The line numbers will be one off or so.
> Actually, this is very close to how it is implemented
> for run-times that support exception handling.
>
> The generic was easily added.
>
> generic
> with procedure Proc;
> procedure Generic_Assert_Exception
> (Message : String;
> Source : String := GNAT.Source_Info.File;
> Line : Natural := GNAT.Source_Info.Line);
> -- Generic equivalent of Assert_Exception.
>
>
> procedure Generic_Assert_Exception
> (Message : String;
> Source : String := GNAT.Source_Info.File;
> Line : Natural := GNAT.Source_Info.Line) is
> begin
> begin
> Proc;
> exception
> when others =>
^^^^^^^^^^^
I quite often want to make sure that a specific exception has been
raised.
> return;
> end;
>
> -- No exception raised: register the failure message
> Assert (False, Message, Source, Line);
>
> end Generic_Assert_Exception;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: AUnit: access to local procedure needed when asserting exception
2011-12-06 20:02 ` Simon Wright
@ 2011-12-06 21:42 ` Georg Bauhaus
0 siblings, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2011-12-06 21:42 UTC (permalink / raw)
On 06.12.11 21:02, Simon Wright wrote:
>> procedure Generic_Assert_Exception
>> (Message : String;
>> Source : String := GNAT.Source_Info.File;
>> Line : Natural := GNAT.Source_Info.Line) is
>> begin
>> begin
>> Proc;
>> exception
>> when others =>
> ^^^^^^^^^^^
>
> I quite often want to make sure that a specific exception has been
> raised.
Yes, me too. However, just like AUnit has only one Assert---suggesting
that we should use Ada operators for different comparisons---I'd make
the specific exception logic part of the operation. Then I have a kind
of symmetry or mapping: I'd use operators with Assert and
procedure'access (or generic actual) with Assert_Exception.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-12-06 21:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-06 1:12 AUnit: access to local procedure needed when asserting exception Georg Bauhaus
2011-12-06 11:00 ` Georg Bauhaus
2011-12-06 12:25 ` Simon Wright
2011-12-06 18:16 ` Georg Bauhaus
2011-12-06 20:02 ` Simon Wright
2011-12-06 21:42 ` Georg Bauhaus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox