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


A Complete Example

We want to test a single Ada function Subject, contained in the package Under_Test.

package Under_Test is

  Strange_Error, 
  Another_Error, 
  Illegal_Parameter : exception;

  function Subject (X : in Positive) return Positive;

end Under_Test;

Subject is required to return one if X is one, and raise exceptions Strange_Error, Another_Error, or Illegal_Parameter if X is two, three, or greater than three, respectively.

The following script describes an appropriate test:

-- FILE: example.ts

context with Text_IO;    use Text_IO;
        with Under_Test; use Under_Test;

exceptions Strange_Error, Another_Error, Illegal_Parameter;

***** X = 1
define Result : Positive;
test   Result := Subject(1);
pass   Result = 1

***** X = 2
define Result : Positive;
test   Result := Subject(2);
pass   exception Strange_Error

***** X = 3
define Result : Positive;
test   Result := Subject(3);
pass   exception Another_Error

***** X = 4
define Result : Positive;
test   Result := Subject(4);
pass   exception Illegal_Parameter

***** X = Positive'Last
define Result : Positive;
test   Result := Subject(Positive'Last);
pass   exception Illegal_Parameter

You can translate example.ts by issuing the command

tg example.ts

This produces example.adb, the source code of the driver. You have to compile it and link it with package Under_Test. Executing the resulting program then produces the following output

(1) pass.
(2) pass.
(3) pass.
(4) pass.
(5) pass.

Total test result: pass.

Now suppose that in test case (3), Subject raised exception Illegal_Parameter by mistake. Then the output would be

(1) pass.
(2) pass.
(3) X = 3
     ...FAIL.
        (path `Illegal_Parameter' when `Another_Error' was expected)
(4) pass.
(5) pass.

Total test result: FAIL.


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