public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tristan Partin <[email protected]>
To: pgsql-hackers <[email protected]>
Cc: Jelte Fennema-Nio <[email protected]>
Subject: Add pgindent test to check if codebase is correctly formatted
Date: Tue, 16 Jan 2024 19:22:23 -0600
Message-ID: <[email protected]> (raw)
Had some time to watch code run through an extensive test suite, so
thought I would propose this patch that is probably about 75% of the way
to the stated $subject. I had to add in a hack for Meson, and I couldn't
figure out a good hack for autotools.
I think a good solution would be to distribute pgindent and
pg_bsd_indent. At Neon, we are trying to format our extension code using
pgindent. I am sure there are other extension authors out there too that
format using pgindent. Distributing pg_bsd_indent and pgindent in the
postgresql-devel package would be a great help to those of us that
pgindent out of tree code. It would also have the added benefit of
adding the tools to $PREFIX/bin, which would make the test that I added
not need a hack to get the pg_bsd_indent executable.
--
Tristan Partin
Neon (https://neon.tech)
Attachments:
[text/x-patch] v1-0001-Allow-tests-to-register-command-line-arguments-in.patch (989B, ../[email protected]/2-v1-0001-Allow-tests-to-register-command-line-arguments-in.patch)
download | inline diff:
From 6e9ca366b6e4976ae591012150fe77729e37c503 Mon Sep 17 00:00:00 2001
From: Tristan Partin <[email protected]>
Date: Tue, 16 Jan 2024 19:00:44 -0600
Subject: [PATCH v1 1/2] Allow tests to register command line arguments in
Meson
---
meson.build | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index c317144b6b..12ba91109b 100644
--- a/meson.build
+++ b/meson.build
@@ -3284,6 +3284,8 @@ foreach test_dir : tests
'env': env,
} + t.get('test_kwargs', {})
+ test_args = t.get('args', [])
+
foreach onetap : t['tests']
# Make tap test names prettier, remove t/ and .pl
onetap_p = onetap
@@ -3302,7 +3304,7 @@ foreach test_dir : tests
'--testname', onetap_p,
'--', test_command,
test_dir['sd'] / onetap,
- ],
+ ] + test_args,
)
endforeach
install_suites += test_group
--
Tristan Partin
Neon (https://neon.tech)
[text/x-patch] v1-0002-Add-pgindent-test-to-check-if-codebase-is-correct.patch (3.0K, ../[email protected]/3-v1-0002-Add-pgindent-test-to-check-if-codebase-is-correct.patch)
download | inline diff:
From 13902328b24984ab2d18914b63c6874143715f48 Mon Sep 17 00:00:00 2001
From: Tristan Partin <[email protected]>
Date: Tue, 16 Jan 2024 19:03:42 -0600
Subject: [PATCH v1 2/2] Add pgindent test to check if codebase is correctly
formatted
Should be useful for developers and committers to test code as they
develop, commit, or prepare patches.
---
src/meson.build | 2 +-
src/tools/pgindent/Makefile | 24 ++++++++++++++++++++++++
src/tools/pgindent/meson.build | 13 +++++++++++++
src/tools/pgindent/t/001_pgindent.pl | 19 +++++++++++++++++++
4 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 src/tools/pgindent/Makefile
create mode 100644 src/tools/pgindent/meson.build
create mode 100644 src/tools/pgindent/t/001_pgindent.pl
diff --git a/src/meson.build b/src/meson.build
index 65c7d17d08..0345d2fa79 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -14,7 +14,7 @@ subdir('pl')
subdir('interfaces')
subdir('tools/pg_bsd_indent')
-
+subdir('tools/pgindent')
### Generate a Makefile.global that's complete enough for PGXS to work.
#
diff --git a/src/tools/pgindent/Makefile b/src/tools/pgindent/Makefile
new file mode 100644
index 0000000000..45d6b71a12
--- /dev/null
+++ b/src/tools/pgindent/Makefile
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------
+#
+# src/tools/pgindent/Makefile
+#
+# Copyright (c) 2024, PostgreSQL Global Development Group
+#
+#-------------------------------------------------------------------------
+
+subdir = src/tools/pgindent
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+clean distclean:
+ rm -rf log/ tmp_check/
+
+# Provide this alternate test name to allow testing pgindent without building
+# all of the surrounding Postgres installation.
+.PHONY: test
+
+pg_bsd_indent:
+ $(MAKE) -C ../pg_bsd_indent pg_bsd_indent
+
+test: pg_bsd_indent
+ $(prove_installcheck)
diff --git a/src/tools/pgindent/meson.build b/src/tools/pgindent/meson.build
new file mode 100644
index 0000000000..d31ade11ce
--- /dev/null
+++ b/src/tools/pgindent/meson.build
@@ -0,0 +1,13 @@
+tests += {
+ 'name': 'pgindent',
+ 'sd': meson.current_source_dir(),
+ 'bd': meson.current_build_dir(),
+ 'tap': {
+ 'args': [
+ pg_bsd_indent.path(),
+ ],
+ 'tests': [
+ 't/001_pgindent.pl',
+ ],
+ },
+}
diff --git a/src/tools/pgindent/t/001_pgindent.pl b/src/tools/pgindent/t/001_pgindent.pl
new file mode 100644
index 0000000000..8ee93f4789
--- /dev/null
+++ b/src/tools/pgindent/t/001_pgindent.pl
@@ -0,0 +1,19 @@
+# Copyright (c) 2024, PostgreSQL Global Development Group
+#
+# Check that all C code is formatted with pgindent
+#
+
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+use PostgreSQL::Test::Utils qw(command_ok);
+
+if (!$ENV{PG_TEST_EXTRA} || $ENV{PG_TEST_EXTRA} !~ /\bpgindent\b/)
+{
+ plan skip_all => "test pgindent not enabled in PG_TEST_EXTRA";
+}
+
+my $pg_bsd_indent = $ARGV[0];
+command_ok(["./pgindent", "--indent=$pg_bsd_indent", "--check", "--diff"]);
+
+done_testing();
--
Tristan Partin
Neon (https://neon.tech)
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Add pgindent test to check if codebase is correctly formatted
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox