The output of tg is the Ada source code of a single main program,
the test driver. You compile it, link it to the test item, and
execute the resulting program in order to perform the test.
You can have a look at the source code of the driver if you wish, to see
how tg assembled your various code pieces, but there is no need
for you to deal with this source code by any means. It is not intended
to be human-readable. If you need to change something, you should
modify the test script from which tg generated the driver.
There are, however, a few internal functions and workings, of which you might want to make use in your test scripts. These are described below.
A test driver generated by tg has the following structure:
-- header comment
with ...; use ...; -- from the context clause
procedure <name_of_script> is
package Driver_Internals is
-- ...
end Driver_Internals;
-- ...
-- global define part here
-- ...
package body Driver_Internals is
-- ...
end Driver_Internals;
begin
-- ...
-- code of the test cases here
-- ...
exception
-- default exception handlers
end <name_of_script>;
The nested package Driver_Internals contains various status
variables and routines to access them. They are listed and explained in
the next section.
The package Driver_Internals, which is contained in the
declarative region of the test driver program, exports the following
declarations:
function Passed return Boolean; function Failed return Boolean;
These functions indicate the result of the current test case. You may
use them in the cleanup part, or in a subsequent code section, to
take different action depending on the result.
function Taken_Path return String;
The path that the program took after the last test call. The value is
either "=>", if no exception was raised, or the name of the exception.
function Path_Was (Path : in String) return Boolean;
Function for comparing the Taken_Path (see above) with a given
value.
Program_Terminate : exception;
This exception is being propagated by all handlers, and caught at the
top level to perform a graceful exit. You may raise it yourself if you
wish.
The other functions declared in package Driver_Internals are
intended for use by the generated code only.
tg translates the test case description
***** X = 3 define Result : Positive; test Result := Subject(3); pass exception Another_Error
into the following code (slightly reformatted make it more readable):
-- Test Case (3) X = 3
declare
Result : Positive;
begin -- test case
begin -- test part
Result := Subject(3);
Driver_Internals.Set_Path ("=>");
exception
when Another_Error =>
Driver_Internals.Set_Path ("Another_Error");
when E: others =>
Driver_Internals.Set_Path (Ada.Exceptions.Exception_Name (E));
end; -- test part
begin -- result part
if Driver_Internals.Path_Was ("Another_Error") then
Driver_Internals.Test_Case_Passed := True;
Put_Line ("(3) pass.");
else
Driver_Internals.Test_Case_Passed := False;
Driver_Internals.Fail_Result := True;
Put_Line ("(3) X = 3");
Put_Line (" ...FAIL.");
Put_Line (" (" & "path `" & Driver_Internals.Taken_Path & "' when `Another_Error' was expected" & ")");
end if;
exception
when Driver_Internals.Program_Terminate =>
raise;
when E: others =>
Driver_Internals.Unexpected_Error := True;
Put_Line ("ERROR: exception " & Ada.Exceptions.Exception_Name (E) & " raised in result part of test case 3.");
end; -- result part
end; -- test case
Go to the first, previous, next, last section, table of contents.