Remove dynamic translation of regression test scripts, step 2.

"git mv" all the input/*.source and output/*.source files into
the corresponding sql/ and expected/ directories.  Then remove
the pg_regress and Makefile infrastructure associated with
dynamic translation.

Discussion: https://postgr.es/m/1655733.1639871614@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2021-12-20 14:15:52 -05:00
parent d1029bb5a2
commit dc9c3b0ff2
38 changed files with 8 additions and 197 deletions

View File

@ -13,7 +13,6 @@ PGFILEDESC = "dblink - connect to other PostgreSQL databases"
REGRESS = paths dblink
REGRESS_OPTS = --dlpath=$(top_builddir)/src/test/regress
EXTRA_CLEAN = sql/paths.sql expected/paths.out
ifdef USE_PGXS
PG_CONFIG = pg_config

View File

@ -1 +0,0 @@
/paths.out

View File

@ -1 +0,0 @@
/paths.sql

View File

@ -8,8 +8,6 @@ PGFILEDESC = "file_fdw - foreign data wrapper for files"
REGRESS = file_fdw
EXTRA_CLEAN = sql/file_fdw.sql expected/file_fdw.out
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)

View File

@ -1 +0,0 @@
/file_fdw.out

View File

@ -1 +0,0 @@
/file_fdw.sql

View File

@ -166,9 +166,14 @@ ecpg_start_test(const char *testname,
snprintf(inprg, sizeof(inprg), "%s/%s", inputdir, testname);
snprintf(insource, sizeof(insource), "%s.c", testname);
/* make a version of the test name that has dashes in place of slashes */
initStringInfo(&testname_dash);
appendStringInfoString(&testname_dash, testname);
replace_string(&testname_dash, "/", "-");
for (char *c = testname_dash.data; *c != '\0'; c++)
{
if (*c == '/')
*c = '-';
}
snprintf(expectfile_stdout, sizeof(expectfile_stdout),
"%s/expected/%s.stdout",

View File

@ -41,11 +41,6 @@ TOOLSDIR = $(top_srcdir)/src/tools
GEN_KEYWORDLIST = $(PERL) -I $(TOOLSDIR) $(TOOLSDIR)/gen_keywordlist.pl
GEN_KEYWORDLIST_DEPS = $(TOOLSDIR)/gen_keywordlist.pl $(TOOLSDIR)/PerfectHash.pm
# Test input and expected files. These are created by pg_regress itself, so we
# don't have a rule to create them. We do need rules to clean them however.
input_files = $(patsubst $(srcdir)/input/%.source,sql/%.sql, $(wildcard $(srcdir)/input/*.source))
output_files := $(patsubst $(srcdir)/output/%.source,expected/%.out, $(wildcard $(srcdir)/output/*.source))
all: all-lib
# Shared library stuff
@ -116,7 +111,6 @@ distprep: pl_gram.h pl_gram.c plerrcodes.h pl_reserved_kwlist_d.h pl_unreserved_
# are not cleaned here.
clean distclean: clean-lib
rm -f $(OBJS)
rm -f $(output_files) $(input_files)
rm -rf $(pg_regress_clean_files)
maintainer-clean: distclean

View File

@ -1 +0,0 @@
/plpgsql_copy.out

View File

@ -1 +0,0 @@
/plpgsql_copy.sql

View File

@ -69,19 +69,12 @@ all: all-lib
# Ensure parallel safety if a build is started in this directory
$(OBJS): | submake-libpgport submake-generated-headers
# Test input and expected files. These are created by pg_regress itself, so we
# don't have a rule to create them. We do need rules to clean them however.
input_files = $(patsubst $(srcdir)/input/%.source,sql/%.sql, $(wildcard $(srcdir)/input/*.source))
output_files := $(patsubst $(srcdir)/output/%.source,expected/%.out, $(wildcard $(srcdir)/output/*.source))
# not installed by default
regress_data_files = \
$(filter-out $(addprefix $(srcdir)/,$(output_files)),$(wildcard $(srcdir)/expected/*.out)) \
$(wildcard $(srcdir)/input/*.source) \
$(wildcard $(srcdir)/output/*.source) \
$(filter-out $(addprefix $(srcdir)/,$(input_files)),$(wildcard $(srcdir)/sql/*.sql)) \
$(wildcard $(srcdir)/sql/*.sql) \
$(wildcard $(srcdir)/expected/*.out) \
$(wildcard $(srcdir)/data/*.data) \
$(srcdir)/parallel_schedule $(srcdir)/resultmap
@ -162,6 +155,5 @@ clean distclean maintainer-clean: clean-lib
rm -f $(OBJS) refint$(DLSUFFIX) autoinc$(DLSUFFIX)
rm -f pg_regress_main.o pg_regress.o pg_regress$(X)
# things created by various check targets
rm -f $(output_files) $(input_files)
rm -rf testtablespace
rm -rf $(pg_regress_clean_files)

View File

@ -1,10 +0,0 @@
/constraints.out
/copy.out
/create_function_0.out
/create_function_1.out
/create_function_2.out
/largeobject.out
/largeobject_1.out
/misc.out
/security_label.out
/tablespace.out

View File

@ -438,155 +438,6 @@ string_matches_pattern(const char *str, const char *pattern)
return false;
}
/*
* Replace all occurrences of "replace" in "string" with "replacement".
* The StringInfo will be suitably enlarged if necessary.
*
* Note: this is optimized on the assumption that most calls will find
* no more than one occurrence of "replace", and quite likely none.
*/
void
replace_string(StringInfo string, const char *replace, const char *replacement)
{
int pos = 0;
char *ptr;
while ((ptr = strstr(string->data + pos, replace)) != NULL)
{
/* Must copy the remainder of the string out of the StringInfo */
char *suffix = pg_strdup(ptr + strlen(replace));
/* Truncate StringInfo at start of found string ... */
string->len = ptr - string->data;
/* ... and append the replacement (this restores the trailing '\0') */
appendStringInfoString(string, replacement);
/* Next search should start after the replacement */
pos = string->len;
/* Put back the remainder of the string */
appendStringInfoString(string, suffix);
free(suffix);
}
}
/*
* Convert *.source found in the "source" directory, replacing certain tokens
* in the file contents with their intended values, and put the resulting files
* in the "dest" directory, replacing the ".source" prefix in their names with
* the given suffix.
*/
static void
convert_sourcefiles_in(const char *source_subdir, const char *dest_dir, const char *dest_subdir, const char *suffix)
{
char testtablespace[MAXPGPATH];
char indir[MAXPGPATH];
char outdir_sub[MAXPGPATH];
char **name;
char **names;
int count = 0;
snprintf(indir, MAXPGPATH, "%s/%s", inputdir, source_subdir);
/* Check that indir actually exists and is a directory */
if (!directory_exists(indir))
{
/*
* No warning, to avoid noise in tests that do not have these
* directories; for example, ecpg, contrib and src/pl.
*/
return;
}
names = pgfnames(indir);
if (!names)
/* Error logged in pgfnames */
exit(2);
/* Create the "dest" subdirectory if not present */
snprintf(outdir_sub, MAXPGPATH, "%s/%s", dest_dir, dest_subdir);
if (!directory_exists(outdir_sub))
make_directory(outdir_sub);
/* We might need to replace @testtablespace@ */
snprintf(testtablespace, MAXPGPATH, "%s/testtablespace", outputdir);
/* finally loop on each file and do the replacement */
for (name = names; *name; name++)
{
char srcfile[MAXPGPATH];
char destfile[MAXPGPATH];
char prefix[MAXPGPATH];
FILE *infile,
*outfile;
StringInfoData line;
/* reject filenames not finishing in ".source" */
if (strlen(*name) < 8)
continue;
if (strcmp(*name + strlen(*name) - 7, ".source") != 0)
continue;
count++;
/* build the full actual paths to open */
snprintf(prefix, strlen(*name) - 6, "%s", *name);
snprintf(srcfile, MAXPGPATH, "%s/%s", indir, *name);
snprintf(destfile, MAXPGPATH, "%s/%s/%s.%s", dest_dir, dest_subdir,
prefix, suffix);
infile = fopen(srcfile, "r");
if (!infile)
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
progname, srcfile, strerror(errno));
exit(2);
}
outfile = fopen(destfile, "w");
if (!outfile)
{
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
progname, destfile, strerror(errno));
exit(2);
}
initStringInfo(&line);
while (pg_get_line_buf(infile, &line))
{
replace_string(&line, "@abs_srcdir@", inputdir);
replace_string(&line, "@abs_builddir@", outputdir);
replace_string(&line, "@testtablespace@", testtablespace);
replace_string(&line, "@libdir@", dlpath);
replace_string(&line, "@DLSUFFIX@", DLSUFFIX);
fputs(line.data, outfile);
}
pfree(line.data);
fclose(infile);
fclose(outfile);
}
/*
* If we didn't process any files, complain because it probably means
* somebody neglected to pass the needed --inputdir argument.
*/
if (count <= 0)
{
fprintf(stderr, _("%s: no *.source files found in \"%s\"\n"),
progname, indir);
exit(2);
}
pgfnames_cleanup(names);
}
/* Create the .sql and .out files from the .source files, if any */
static void
convert_sourcefiles(void)
{
convert_sourcefiles_in("input", outputdir, "sql", "sql");
convert_sourcefiles_in("output", outputdir, "expected", "out");
}
/*
* Clean out the test tablespace dir, or create it if it doesn't exist.
*
@ -936,7 +787,6 @@ initialize_environment(void)
printf(_("(using postmaster on Unix socket, default port)\n"));
}
convert_sourcefiles();
load_resultmap();
}

View File

@ -65,6 +65,4 @@ int regression_main(int argc, char *argv[],
void add_stringlist_item(_stringlist **listhead, const char *str);
PID_TYPE spawn_process(const char *cmdline);
void replace_string(struct StringInfoData *string,
const char *replace, const char *replacement);
bool file_exists(const char *file);

View File

@ -1,9 +0,0 @@
/constraints.sql
/copy.sql
/create_function_0.sql
/create_function_1.sql
/create_function_2.sql
/largeobject.sql
/misc.sql
/security_label.sql
/tablespace.sql