*
* This code is released under the terms of the PostgreSQL License.
*
- * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/test/regress/pg_regress_main.c,v 1.1 2007/06/12 11:07:34 mha Exp $
+ * src/test/regress/pg_regress_main.c
*
*-------------------------------------------------------------------------
*/
+#include "postgres_fe.h"
+
#include "pg_regress.h"
/*
char outfile[MAXPGPATH];
char expectfile[MAXPGPATH];
char psql_cmd[MAXPGPATH * 3];
+ size_t offset = 0;
+ char *appnameenv;
+ /*
+ * Look for files in the output dir first, consistent with a vpath search.
+ * This is mainly to create more reasonable error messages if the file is
+ * not found. It also allows local test overrides when running pg_regress
+ * outside of the source tree.
+ */
snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
- inputdir, testname);
+ outputdir, testname);
+ if (!file_exists(infile))
+ snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
+ inputdir, testname);
+
snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
outputdir, testname);
+
snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
- inputdir, testname);
+ outputdir, testname);
+ if (!file_exists(expectfile))
+ snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
+ inputdir, testname);
add_stringlist_item(resultfiles, outfile);
add_stringlist_item(expectfiles, expectfile);
- snprintf(psql_cmd, sizeof(psql_cmd),
- SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
- psqldir ? psqldir : "",
- psqldir ? "/" : "",
- dblist->str,
- infile,
- outfile);
+ if (launcher)
+ {
+ offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
+ "%s ", launcher);
+ if (offset >= sizeof(psql_cmd))
+ {
+ fprintf(stderr, _("command too long\n"));
+ exit(2);
+ }
+ }
+
+ /*
+ * Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
+ * against different AMs without unnecessary differences.
+ */
+ offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
+ "\"%s%spsql\" -X -a -q -d \"%s\" -v %s < \"%s\" > \"%s\" 2>&1",
+ bindir ? bindir : "",
+ bindir ? "/" : "",
+ dblist->str,
+ "HIDE_TABLEAM=\"on\"",
+ infile,
+ outfile);
+ if (offset >= sizeof(psql_cmd))
+ {
+ fprintf(stderr, _("command too long\n"));
+ exit(2);
+ }
+
+ appnameenv = psprintf("PGAPPNAME=pg_regress/%s", testname);
+ putenv(appnameenv);
pid = spawn_process(psql_cmd);
{
fprintf(stderr, _("could not start process for test %s\n"),
testname);
- exit_nicely(2);
+ exit(2);
}
+ unsetenv("PGAPPNAME");
+ free(appnameenv);
+
return pid;
}
static void
-psql_init(void)
+psql_init(int argc, char **argv)
{
/* set default regression database name */
add_stringlist_item(&dblist, "regression");