1 /*-------------------------------------------------------------------------
3 * pg_regress_main --- regression test for the main backend
5 * This is a C implementation of the previous shell script for running
6 * the regression tests, and should be mostly compatible with it.
7 * Initial author of C translation: Magnus Hagander
9 * This code is released under the terms of the PostgreSQL License.
11 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
16 *-------------------------------------------------------------------------
19 #include "pg_regress.h"
22 * start a psql test process for specified file (including redirection),
23 * and return process ID
26 psql_start_test(const char *testname
,
27 _stringlist
** resultfiles
,
28 _stringlist
** expectfiles
,
32 char infile
[MAXPGPATH
];
33 char outfile
[MAXPGPATH
];
34 char expectfile
[MAXPGPATH
];
35 char psql_cmd
[MAXPGPATH
* 3];
38 * Look for files in the output dir first, consistent with a vpath search.
39 * This is mainly to create more reasonable error messages if the file is
40 * not found. It also allows local test overrides when running pg_regress
41 * outside of the source tree.
43 snprintf(infile
, sizeof(infile
), "%s/sql/%s.sql",
45 if (!file_exists(infile
))
46 snprintf(infile
, sizeof(infile
), "%s/sql/%s.sql",
49 snprintf(outfile
, sizeof(outfile
), "%s/results/%s.out",
52 snprintf(expectfile
, sizeof(expectfile
), "%s/expected/%s.out",
54 if (!file_exists(expectfile
))
55 snprintf(expectfile
, sizeof(expectfile
), "%s/expected/%s.out",
58 add_stringlist_item(resultfiles
, outfile
);
59 add_stringlist_item(expectfiles
, expectfile
);
61 snprintf(psql_cmd
, sizeof(psql_cmd
),
62 SYSTEMQUOTE
"\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE
,
63 psqldir
? psqldir
: "",
69 pid
= spawn_process(psql_cmd
);
71 if (pid
== INVALID_PID
)
73 fprintf(stderr
, _("could not start process for test %s\n"),
84 /* set default regression database name */
85 add_stringlist_item(&dblist
, "regression");
89 main(int argc
, char *argv
[])
91 return regression_main(argc
, argv
, psql_init
, psql_start_test
);