]> granicus.if.org Git - postgresql/blob - src/test/regress/pg_regress_main.c
Update copyrights in source tree to 2008.
[postgresql] / src / test / regress / pg_regress_main.c
1 /*-------------------------------------------------------------------------
2  *
3  * pg_regress_main --- regression test for the main backend
4  *
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
8  *
9  * This code is released under the terms of the PostgreSQL License.
10  *
11  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
12  * Portions Copyright (c) 1994, Regents of the University of California
13  *
14  * $PostgreSQL: pgsql/src/test/regress/pg_regress_main.c,v 1.3 2008/01/01 19:46:00 momjian Exp $
15  *
16  *-------------------------------------------------------------------------
17  */
18
19 #include "pg_regress.h"
20
21 /*
22  * start a psql test process for specified file (including redirection),
23  * and return process ID
24  */
25 static PID_TYPE
26 psql_start_test(const char *testname,
27                                 _stringlist ** resultfiles,
28                                 _stringlist ** expectfiles,
29                                 _stringlist ** tags)
30 {
31         PID_TYPE        pid;
32         char            infile[MAXPGPATH];
33         char            outfile[MAXPGPATH];
34         char            expectfile[MAXPGPATH];
35         char            psql_cmd[MAXPGPATH * 3];
36
37         snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
38                          inputdir, testname);
39         snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
40                          outputdir, testname);
41         snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
42                          inputdir, testname);
43
44         add_stringlist_item(resultfiles, outfile);
45         add_stringlist_item(expectfiles, expectfile);
46
47         snprintf(psql_cmd, sizeof(psql_cmd),
48                          SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
49                          psqldir ? psqldir : "",
50                          psqldir ? "/" : "",
51                          dblist->str,
52                          infile,
53                          outfile);
54
55         pid = spawn_process(psql_cmd);
56
57         if (pid == INVALID_PID)
58         {
59                 fprintf(stderr, _("could not start process for test %s\n"),
60                                 testname);
61                 exit_nicely(2);
62         }
63
64         return pid;
65 }
66
67 static void
68 psql_init(void)
69 {
70         /* set default regression database name */
71         add_stringlist_item(&dblist, "regression");
72 }
73
74 int
75 main(int argc, char *argv[])
76 {
77         return regression_main(argc, argv, psql_init, psql_start_test);
78 }