Go to the first, previous, next, last section, table of contents.


Drivers

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.

Structure

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.

Status Information

The package Driver_Internals, which is contained in the declarative region of the test driver program, exports the following declarations:

The other functions declared in package Driver_Internals are intended for use by the generated code only.

Example

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.