On Mon, Feb 23, 2015 at 12:00 AM, Peter Eisentraut <pete...@gmx.net> wrote:
> On 2/22/15 5:41 AM, Michael Paquier wrote:
>>> You could argue that these .gitignore files don't actually belong there,
>>> but your patch doesn't change or move those files, and even modules that
>>> have non-empty sql/ or expected/ directories have .gitignore files
>>> there, so it is considered the appropriate location.
>>
>> This is up to the maintainer of each extension to manage their code
>> tree. However I can imagine that some people would be grateful if we
>> allow them to not need sql/ and expected/ containing only one single
>> .gitignore file ignoring everything with "*", making the code tree of
>> their extensions cleaner.
>
> I would like to have an extension in tree that also does this, so we
> have a regression test of this functionality.

Sure. Here is one in the patch attached added as a test module. The
name of the module is regress_dynamic. Perhaps the name could be
better..
-- 
Michael
From 0b89d35f9605f866b45943d842898e30923476c3 Mon Sep 17 00:00:00 2001
From: Michael Paquier <mich...@otacoo.com>
Date: Mon, 23 Feb 2015 15:02:14 +0900
Subject: [PATCH 1/2] Enforce creation of input and output paths in pg_regress

This is particularly useful for extensions that have only regression tests
in input/ and output/ dynamically generated when running the tests to keep
the code tree of such extensions clean without empty folders containing as
only content a .gitignore ignoring everything else other than its own
existence.
---
 src/test/regress/pg_regress.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 3af0e57..a7aa580 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -496,6 +496,7 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 {
 	char		testtablespace[MAXPGPATH];
 	char		indir[MAXPGPATH];
+	char		result_dir[MAXPGPATH];
 	struct stat st;
 	int			ret;
 	char	  **name;
@@ -520,6 +521,14 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 		/* Error logged in pgfnames */
 		exit(2);
 
+	/*
+	 * Enforce creation of destination directory if it does not exist yet.
+	 * This is useful for tests using only source files.
+	 */
+	snprintf(result_dir, MAXPGPATH, "%s/%s", dest_dir, dest_subdir);
+	if (!directory_exists(result_dir))
+		make_directory(result_dir);
+
 	snprintf(testtablespace, MAXPGPATH, "%s/testtablespace", outputdir);
 
 #ifdef WIN32
@@ -565,7 +574,7 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 		/* 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,
+		snprintf(destfile, MAXPGPATH, "%s/%s.%s", result_dir,
 				 prefix, suffix);
 
 		infile = fopen(srcfile, "r");
-- 
2.3.0

From c5e58c85e743c3c7b133234588e2010612166f8f Mon Sep 17 00:00:00 2001
From: Michael Paquier <mich...@otacoo.com>
Date: Mon, 23 Feb 2015 15:23:44 +0900
Subject: [PATCH 2/2] Add regress_dynamic as a test module

This simple extension has the characteristic to only contain non-static
regression test content, and is aimed to test if pg_regress is able to
generate appropriately input and output directories when they do not
exist.
---
 src/test/modules/regress_dynamic/.gitignore              |  8 ++++++++
 src/test/modules/regress_dynamic/Makefile                | 16 ++++++++++++++++
 src/test/modules/regress_dynamic/README                  |  6 ++++++
 src/test/modules/regress_dynamic/input/basic.source      |  9 +++++++++
 src/test/modules/regress_dynamic/output/basic.source     | 11 +++++++++++
 .../modules/regress_dynamic/regress_dynamic--1.0.sql     |  8 ++++++++
 src/test/modules/regress_dynamic/regress_dynamic.control |  5 +++++
 7 files changed, 63 insertions(+)
 create mode 100644 src/test/modules/regress_dynamic/.gitignore
 create mode 100644 src/test/modules/regress_dynamic/Makefile
 create mode 100644 src/test/modules/regress_dynamic/README
 create mode 100644 src/test/modules/regress_dynamic/input/basic.source
 create mode 100644 src/test/modules/regress_dynamic/output/basic.source
 create mode 100644 src/test/modules/regress_dynamic/regress_dynamic--1.0.sql
 create mode 100644 src/test/modules/regress_dynamic/regress_dynamic.control

diff --git a/src/test/modules/regress_dynamic/.gitignore b/src/test/modules/regress_dynamic/.gitignore
new file mode 100644
index 0000000..122ede3
--- /dev/null
+++ b/src/test/modules/regress_dynamic/.gitignore
@@ -0,0 +1,8 @@
+# Generated sub-directories
+/log/
+/results/
+/tmp_check/
+
+# Input and output directories of regression tests
+/expected/
+/sql/
diff --git a/src/test/modules/regress_dynamic/Makefile b/src/test/modules/regress_dynamic/Makefile
new file mode 100644
index 0000000..2cab345
--- /dev/null
+++ b/src/test/modules/regress_dynamic/Makefile
@@ -0,0 +1,16 @@
+EXTENSION = regress_dynamic
+DATA = regress_dynamic--1.0.sql
+PGFILEDESC = "regress_dynamic - extension with only non-static regression tests"
+
+REGRESS = basic
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/test/modules/regress_dynamic
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/src/test/modules/regress_dynamic/README b/src/test/modules/regress_dynamic/README
new file mode 100644
index 0000000..b039e5e
--- /dev/null
+++ b/src/test/modules/regress_dynamic/README
@@ -0,0 +1,6 @@
+regress_dynamic
+===============
+
+regress_dynamic is an extension used to test that pg_regress correctly
+creates input and output paths when regression test suite of an extension
+only contain non-static content with empty sql/ and expected/ folders.
diff --git a/src/test/modules/regress_dynamic/input/basic.source b/src/test/modules/regress_dynamic/input/basic.source
new file mode 100644
index 0000000..1d7031d
--- /dev/null
+++ b/src/test/modules/regress_dynamic/input/basic.source
@@ -0,0 +1,9 @@
+--
+-- regress_dynamic
+--
+
+-- Initialization
+CREATE EXTENSION regress_dynamic;
+
+-- Simple test
+SELECT * FROM dummy_tab;
diff --git a/src/test/modules/regress_dynamic/output/basic.source b/src/test/modules/regress_dynamic/output/basic.source
new file mode 100644
index 0000000..f666627
--- /dev/null
+++ b/src/test/modules/regress_dynamic/output/basic.source
@@ -0,0 +1,11 @@
+--
+-- regress_dynamic
+--
+-- Initialization
+CREATE EXTENSION regress_dynamic;
+-- Simple test
+SELECT * FROM dummy_tab;
+ id 
+----
+(0 rows)
+
diff --git a/src/test/modules/regress_dynamic/regress_dynamic--1.0.sql b/src/test/modules/regress_dynamic/regress_dynamic--1.0.sql
new file mode 100644
index 0000000..c7a19c9
--- /dev/null
+++ b/src/test/modules/regress_dynamic/regress_dynamic--1.0.sql
@@ -0,0 +1,8 @@
+/* regress_dynamic/regress_dynamic--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION regress_dynamic" to load this file. \quit
+
+CREATE TABLE dummy_tab (
+	id int
+);
diff --git a/src/test/modules/regress_dynamic/regress_dynamic.control b/src/test/modules/regress_dynamic/regress_dynamic.control
new file mode 100644
index 0000000..643b946
--- /dev/null
+++ b/src/test/modules/regress_dynamic/regress_dynamic.control
@@ -0,0 +1,5 @@
+# regress_dynamic extension
+comment = 'regress_dynamic - extension with only non-static regression tests'
+default_version = '1.0'
+module_pathname = '$libdir/regress_dynamic'
+relocatable = true
-- 
2.3.0

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to