On 2025/03/01 19:45, Ryo Kanbayashi wrote:
+program_help_ok('ecpg');
+program_version_ok('ecpg');
+program_options_handling_ok('ecpg');
+command_fails(['ecpg'], 'ecpg without arguments fails');

These checks seem unnecessary in 002 since they're already covered in 001.

I reflected above.

Thanks for updating the patch!

I've made some minor fixes and cosmetic adjustments.
The updated patch is attached.

Unless there are any objections, I'll commit it.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 3d06f586d1f9f4760f8259bc10c11f2152c3266f Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Mon, 3 Mar 2025 09:24:02 +0900
Subject: [PATCH v6] ecpg: Add TAP test for the ecpg command.

This commit adds a TAP test to verify that the ecpg command correctly
detects unsupported or disallowed statements in input files and reports
the appropriate error or warning messages.

This test helps catch bugs like the one introduced in commit 3d009e45bd,
which broke ecpg's handling of unsupported COPY FROM STDIN statements,
later fixed by commit 94b914f601b.

Author: Ryo Kanbayashi <kanbayashi....@gmail.com>
Reviewed-by: Fujii Masao <masao.fu...@gmail.com>
Discussion: 
https://postgr.es/m/canon0ezomyxa1m-quds1uequq6fnki6+ggigucgr9tm2r78...@mail.gmail.com
---
 src/interfaces/ecpg/preproc/Makefile          |  3 ++
 src/interfaces/ecpg/preproc/meson.build       | 13 ++++++
 .../ecpg/preproc/t/001_ecpg_err_warn_msg.pl   | 40 ++++++++++++++++++
 .../t/002_ecpg_err_warn_msg_informix.pl       | 22 ++++++++++
 .../ecpg/preproc/t/err_warn_msg.pgc           | 42 +++++++++++++++++++
 .../ecpg/preproc/t/err_warn_msg_informix.pgc  | 18 ++++++++
 6 files changed, 138 insertions(+)
 create mode 100644 src/interfaces/ecpg/preproc/t/001_ecpg_err_warn_msg.pl
 create mode 100644 
src/interfaces/ecpg/preproc/t/002_ecpg_err_warn_msg_informix.pl
 create mode 100644 src/interfaces/ecpg/preproc/t/err_warn_msg.pgc
 create mode 100644 src/interfaces/ecpg/preproc/t/err_warn_msg_informix.pgc

diff --git a/src/interfaces/ecpg/preproc/Makefile 
b/src/interfaces/ecpg/preproc/Makefile
index 84199a9a5d0..d0e3852a878 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -81,6 +81,9 @@ ecpg_keywords.o: ecpg_kwlist_d.h
 c_keywords.o: c_kwlist_d.h
 keywords.o: $(top_srcdir)/src/include/parser/kwlist.h
 
+check:
+       $(prove_check)
+
 install: all installdirs
        $(INSTALL_PROGRAM) ecpg$(X) '$(DESTDIR)$(bindir)'
 
diff --git a/src/interfaces/ecpg/preproc/meson.build 
b/src/interfaces/ecpg/preproc/meson.build
index bfd0ed2efb4..01f2ac671ec 100644
--- a/src/interfaces/ecpg/preproc/meson.build
+++ b/src/interfaces/ecpg/preproc/meson.build
@@ -86,3 +86,16 @@ ecpg_exe = executable('ecpg',
 ecpg_targets += ecpg_exe
 
 subdir('po', if_found: libintl)
+
+tests += {
+  'name': 'ecpg',
+  'sd': meson.current_source_dir(),
+  'bd': meson.current_build_dir(),
+  'tap': {
+    'tests': [
+      't/001_ecpg_err_warn_msg.pl',
+      't/002_ecpg_err_warn_msg_informix.pl',
+    ],
+    'deps': ecpg_exe,
+  },
+}
\ No newline at end of file
diff --git a/src/interfaces/ecpg/preproc/t/001_ecpg_err_warn_msg.pl 
b/src/interfaces/ecpg/preproc/t/001_ecpg_err_warn_msg.pl
new file mode 100644
index 00000000000..a18e09e6ee8
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/001_ecpg_err_warn_msg.pl
@@ -0,0 +1,40 @@
+
+# Copyright (c) 2021-2025, PostgreSQL Global Development Group
+
+use strict;
+use warnings FATAL => 'all';
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+program_help_ok('ecpg');
+program_version_ok('ecpg');
+program_options_handling_ok('ecpg');
+command_fails(['ecpg'], 'ecpg without arguments fails');
+
+# Test that the ecpg command correctly detects unsupported or disallowed
+# statements in the input file and reports the appropriate error or
+# warning messages.
+command_checks_all(
+       [ 'ecpg', 't/err_warn_msg.pgc' ],
+       3,
+       [qr//],
+       [
+               qr/ERROR: AT option not allowed in CONNECT statement/,
+               qr/ERROR: AT option not allowed in DISCONNECT statement/,
+               qr/ERROR: AT option not allowed in SET CONNECTION statement/,
+               qr/ERROR: AT option not allowed in TYPE statement/,
+               qr/ERROR: AT option not allowed in WHENEVER statement/,
+               qr/ERROR: AT option not allowed in VAR statement/,
+               qr/WARNING: COPY FROM STDIN is not implemented/,
+               qr/ERROR: using variable "cursor_var" in different declare 
statements is not supported/,
+               qr/ERROR: cursor "duplicate_cursor" is already defined/,
+               qr/ERROR: SHOW ALL is not implemented/,
+               qr/WARNING: no longer supported LIMIT/,
+               qr/WARNING: cursor "duplicate_cursor" has been declared but not 
opened/,
+               qr/WARNING: cursor "duplicate_cursor" has been declared but not 
opened/,
+               qr/WARNING: cursor ":cursor_var" has been declared but not 
opened/,
+               qr/WARNING: cursor ":cursor_var" has been declared but not 
opened/
+       ],
+       'ecpg with errors and warnings');
+
+done_testing();
diff --git a/src/interfaces/ecpg/preproc/t/002_ecpg_err_warn_msg_informix.pl 
b/src/interfaces/ecpg/preproc/t/002_ecpg_err_warn_msg_informix.pl
new file mode 100644
index 00000000000..cb0502dfc2b
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/002_ecpg_err_warn_msg_informix.pl
@@ -0,0 +1,22 @@
+
+# Copyright (c) 2021-2025, PostgreSQL Global Development Group
+
+use strict;
+use warnings FATAL => 'all';
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+# Test that the ecpg command in INFORMIX mode correctly detects
+# unsupported or disallowed statements in the input file and reports
+# the appropriate error or warning messages.
+command_checks_all(
+       [ 'ecpg', '-C', 'INFORMIX', 't/err_warn_msg_informix.pgc' ],
+       3,
+       [qr//],
+       [
+               qr/ERROR: AT option not allowed in CLOSE DATABASE statement/,
+               qr/ERROR: "database" cannot be used as cursor name in INFORMIX 
mode/
+       ],
+       'ecpg in INFORMIX mode with errors and warnings');
+
+done_testing();
diff --git a/src/interfaces/ecpg/preproc/t/err_warn_msg.pgc 
b/src/interfaces/ecpg/preproc/t/err_warn_msg.pgc
new file mode 100644
index 00000000000..5ab0a761866
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/err_warn_msg.pgc
@@ -0,0 +1,42 @@
+/* Test ECPG warning/error messages */
+
+#include <stdlib.h>
+
+int
+main(void)
+{
+       EXEC SQL BEGIN DECLARE SECTION;
+       char *cursor_var = "mycursor";
+       short a;
+       EXEC SQL END DECLARE SECTION;
+
+       /* For consistency with other tests */
+       EXEC SQL CONNECT TO testdb AS con1;
+
+       /* Test AT option errors */
+       EXEC SQL AT con1 CONNECT TO testdb2;
+       EXEC SQL AT con1 DISCONNECT;
+       EXEC SQL AT con1 SET CONNECTION TO testdb2;
+       EXEC SQL AT con1 TYPE string IS char[11];
+       EXEC SQL AT con1 WHENEVER NOT FOUND CONTINUE;
+       EXEC SQL AT con1 VAR a IS int;
+
+       /* Test COPY FROM STDIN warning */
+       EXEC SQL COPY test FROM stdin;
+
+       /* Test same variable in multi declare statement */
+       EXEC SQL DECLARE :cursor_var CURSOR FOR SELECT * FROM test;
+       EXEC SQL DECLARE :cursor_var CURSOR FOR SELECT * FROM test;
+
+       /* Test duplicate cursor declarations */
+       EXEC SQL DECLARE duplicate_cursor CURSOR FOR SELECT * FROM test;
+       EXEC SQL DECLARE duplicate_cursor CURSOR FOR SELECT * FROM test;
+
+       /* Test SHOW ALL error */
+       EXEC SQL SHOW ALL;
+
+       /* Test deprecated LIMIT syntax warning */
+       EXEC SQL SELECT * FROM test LIMIT 10, 5;
+
+       return 0;
+}
diff --git a/src/interfaces/ecpg/preproc/t/err_warn_msg_informix.pgc 
b/src/interfaces/ecpg/preproc/t/err_warn_msg_informix.pgc
new file mode 100644
index 00000000000..e8db65eefa1
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/err_warn_msg_informix.pgc
@@ -0,0 +1,18 @@
+/* Test ECPG warning/error messages in INFORMIX mode */
+
+#include <stdlib.h>
+
+int
+main(void)
+{
+    /* For consistency with other tests */
+    $CONNECT TO testdb AS con1;
+
+    /* Test AT option usage at CLOSE DATABASE statement in INFORMIX mode */
+    $AT con1 CLOSE DATABASE;
+
+    /* Test cursor name errors in INFORMIX mode */
+    $DECLARE database CURSOR FOR SELECT * FROM test;
+
+    return 0;
+}
-- 
2.48.1

Reply via email to