setup { <SQL> }
The given SQL block is executed once, in one session only, before running
- the test. Create any test tables or other required objects here. This
- part is optional.
+ the test. Create any test tables or other required objects here. This
+ part is optional. Multiple setup blocks are allowed if needed; each is
+ run separately, in the given order. (The reason for allowing multiple
+ setup blocks is that each block is run as a single PQexec submission,
+ and some statements such as VACUUM cannot be combined with others in such
+ a block.)
teardown { <SQL> }
printf("\n");
/* Perform setup */
- if (testspec->setupsql)
+ for (i = 0; i < testspec->nsetupsqls; i++)
{
- res = PQexec(conns[0], testspec->setupsql);
+ res = PQexec(conns[0], testspec->setupsqls[i]);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));
} ptr_list;
}
+%type <ptr_list> setup_list
%type <str> opt_setup opt_teardown
+%type <str> setup
%type <ptr_list> step_list session_list permutation_list opt_permutation_list
%type <ptr_list> string_list
%type <session> session
%%
TestSpec:
- opt_setup
+ setup_list
opt_teardown
session_list
opt_permutation_list
{
- parseresult.setupsql = $1;
+ parseresult.setupsqls = (char **) $1.elements;
+ parseresult.nsetupsqls = $1.nelements;
parseresult.teardownsql = $2;
parseresult.sessions = (Session **) $3.elements;
parseresult.nsessions = $3.nelements;
}
;
+setup_list:
+ /* EMPTY */
+ {
+ $$.elements = NULL;
+ $$.nelements = 0;
+ }
+ | setup_list setup
+ {
+ $$.elements = realloc($1.elements,
+ ($1.nelements + 1) * sizeof(void *));
+ $$.elements[$1.nelements] = $2;
+ $$.nelements = $1.nelements + 1;
+ }
+ ;
+
opt_setup:
/* EMPTY */ { $$ = NULL; }
- | SETUP sqlblock { $$ = $2; }
+ | setup { $$ = $1; }
+ ;
+
+setup:
+ SETUP sqlblock { $$ = $2; }
;
opt_teardown: