~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/test/regress/pg_regress_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2009, PostgreSQL Global Development Group
 
12
 * Portions Copyright (c) 1994, Regents of the University of California
 
13
 *
 
14
 * $PostgreSQL$
 
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
        /*
 
38
         * Look for files in the output dir first, consistent with a vpath
 
39
         * search.  This is mainly to create more reasonable error
 
40
         * messages if the file is not found.  It also allows local test
 
41
         * overrides when running pg_regress outside of the source tree.
 
42
         */
 
43
        snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
 
44
                         outputdir, testname);
 
45
        if (!file_exists(infile))
 
46
                snprintf(infile, sizeof(infile), "%s/sql/%s.sql",
 
47
                                 inputdir, testname);
 
48
 
 
49
        snprintf(outfile, sizeof(outfile), "%s/results/%s.out",
 
50
                         outputdir, testname);
 
51
 
 
52
        snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
 
53
                         outputdir, testname);
 
54
        if (!file_exists(expectfile))
 
55
                snprintf(expectfile, sizeof(expectfile), "%s/expected/%s.out",
 
56
                                 inputdir, testname);
 
57
 
 
58
        add_stringlist_item(resultfiles, outfile);
 
59
        add_stringlist_item(expectfiles, expectfile);
 
60
 
 
61
        snprintf(psql_cmd, sizeof(psql_cmd),
 
62
                         SYSTEMQUOTE "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1" SYSTEMQUOTE,
 
63
                         psqldir ? psqldir : "",
 
64
                         psqldir ? "/" : "",
 
65
                         dblist->str,
 
66
                         infile,
 
67
                         outfile);
 
68
 
 
69
        pid = spawn_process(psql_cmd);
 
70
 
 
71
        if (pid == INVALID_PID)
 
72
        {
 
73
                fprintf(stderr, _("could not start process for test %s\n"),
 
74
                                testname);
 
75
                exit_nicely(2);
 
76
        }
 
77
 
 
78
        return pid;
 
79
}
 
80
 
 
81
static void
 
82
psql_init(void)
 
83
{
 
84
        /* set default regression database name */
 
85
        add_stringlist_item(&dblist, "regression");
 
86
}
 
87
 
 
88
int
 
89
main(int argc, char *argv[])
 
90
{
 
91
        return regression_main(argc, argv, psql_init, psql_start_test);
 
92
}