Conditional comments make it possible to designate portions of a script that are "commented out" (see Script Comments) in some situations and not commented out in other situations.
The syntax of conditional comments is shown in the following example:
.png)
A comment condition named incl_bench is defined.
The #ifdef statement then checks to see whether incl_bench has been defined.
Since it has, the subsequent lines of the script are NOT commented out.
The #endif statement marks the end of the lines to which the prior #ifdef condition applies.
Compare the above to the following:
.png)
Here the line that defines incl_bench has been commented out explicitly. (It could also be simply deleted.)
Now incl_bench is NOT defined, making the #ifdef condition false, therefore the subsequent lines are not included in the script (they are commented out).
In other words, #ifdef xxx means "only include the subsequent lines in the script if xxx has been defined with #define".
The following lists all the syntax supported by RealTest for conditional comments:
Item
|
Description
|
Example
|
#define
|
define a conditional comment name
|
#define xxx
|
#undef
|
remove (un-define) a conditional comment name
|
#undef xxx
|
#ifdef
|
include subsequent lines if name is defined
|
#ifdef xxx
|
#ifndef
|
include subsequent lines if name is NOT defined
|
#ifndef xxx
|
#else
|
include subsequent lines if the prior #ifdef or #ifndef excluded them
|
#else
|
#endif
|
end the current conditional comment block
|
#endif
|
In addition to any names that you define with #define, RealTest also predefines several names that may be useful:
Name
|
Description
|
standalone
|
the script is not included by another script
|
apply
|
the script is running "Apply" mode
|
test
|
the script is running in "Test" mode
|
optimize
|
the script is running in "Optimize" mode
|
import
|
the script is running in "Import" mode
|
scan
|
the script is running in "Scan" mode
|
orders
|
the script is running in "Orders" mode
|
For example, in the screenshot above, replace #ifdef incl_bench with:
•#ifdef standalone to only include the benchmark when the script is not included by another script (which might already have its own benchmark)
•#ifdef test to only include the benchmark when the script is being run as a single test, not when optimizing or generating orders
•etc.
Please note that conditional comment syntax is not suggested or auto-completed by the script editor, but is (as shown above) reflected in the automatic text coloring. This shows at a glance what impact your conditional commenting has on your script.
The one case where the text coloring may not seem correct is in a script that is included by other scripts that may or may not define the name that the included script references in #ifdef or #ifndef. In this case RealTest cannot possibly know which other script you might intend to include this script with. It therefore colors the text as if any such names are not defined.
See also Combining Scripts.
|