ON ERROR

C++ Test Script Language

Syntax

ON ERROR [ { <error item> } ] <error action>;

Location

C++ Test Driver Script, TEST CLASS, TEST SUITE, TEST CASE, PROC

Description

The ON ERROR statement defines the behavior of the test driver when an error occurs.

ON ERROR applies to the current scope level, and to nested scopes, unless another ON ERROR statement has been defined. The general rule is that the most nested ON ERROR statement is applied.

Note An error can be raised by any instruction of a TEST CASE or a PROC, and by native code from a PROLOGUE or EPILOGUE.

ON ERROR does not apply to stubs. There is always an implicit ON ERROR CONTINUE behavior in stubs

<error item> may be one of the following entities:

  1. COMMENT

    PRINT

    Native statement

This block is executed when an error occurs.

<error action> is a keyword which defines the behavior of the test driver when an error occurs:

  1. CONTINUE: The execution continues just as if no error occurred. If the error comes from an unexpected exception raised by native code, the execution continues after the native code, except for an error in a PROLOGUE block. Since it is the default behavior, this on-error action should only be specified to override another on-error action.

    EXIT : The execution of the test driver stops at the error point.

    BYPASS: The execution of the rest of the current test case or procedure is skipped.

    BYPASS <test class name> | <test suite name> | <test case name> | <proc name> : The execution of the rest of the referred entity is skipped.

Example

ON ERROR CONTINUE;

TEST CLASS A {

ON ERROR EXIT;

TEST SUITE A1 {

ON ERROR BYPASS A;

TEST CASE A1a {

ON ERROR CONTINUE;

CHECK (false); // this leads to an error but execution continues

PRINT "ok"; // this instruction is executed

}

TEST CASE A1b {

CHECK (false); // this leads to an error

// execution resumes after TEST CLASS A

PRINT "ko"; // this instruction is never executed

}

}

TEST CASE A2 {

CHECK (false); // this leads to an error -- the test driver exits

PRINT "ko"; // this instruction is never executed

}

RUN { A1; A2; }

}

TEST CLASS B {

TEST CASE B1 {

ON ERROR BYPASS;

CHECK (false); // this leads to an error -- execution resumes after B1

PRINT "ko"; // this instruction is never executed

}

TEST CASE B2 {

CHECK (false); // this leads to an error but execution continues

PRINT "ok"; // this instruction is executed

}

RUN { B1; B2; B1; }

}

RUN { B; A; A.A2; }

In this example, the execution is: B1 (aborted), B2, B1 (aborted), A1a, A1b (A is aborted), A2 (exited).