On 2025/02/06 8:57, Ryo Kanbayashi wrote:
On Wed, Feb 5, 2025 at 9:31 PM Ryo Kanbayashi <kanbayashi....@gmail.com> wrote:

Hi hackers,

When I wrote patch of ecpg command notice bug, I recognized needs of
regression tests for ecpg command notices and I say that I write the
tests.

Thanks for working on this!


I explain about implementation of this patch.

What is this patch
- add regression tests which test ecpg command notices such as warning
and errors
- test notices implemented in ecpg.addons file

Basic policy on implementation
- do in a way that matches the method using the existing pg_regress
command as much as possible
- avoid methods that increase the scope of influence

Next, I list answers to points that are likely to be pointed out in
advance below :)
- shell scripts and bat files is used due to ...
     avoid non zero exit code of ecpg command makes tests failure
     avoid increasing C code for executing binary which cares cross platform
- python code is used because I couldn't write meson.build
appropriately describe dependency about materials which is used on
tests without it. please help me...
- as you said, kick this kind of tests by pg_regress accompanied with
needless PG server process execution. but pg_regress doesn't execute
test without it and making pg_regress require modification which has
not small scope of influence

Wouldn't it be simpler to use the existing TAP test mechanism,
as shown in the attached patch? Please note that this patch is very WIP,
so there would be many places that need further implementation and refinement.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/src/interfaces/ecpg/preproc/Makefile 
b/src/interfaces/ecpg/preproc/Makefile
index 84199a9a5d..d0e3852a87 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/t/001_ecpg.pl 
b/src/interfaces/ecpg/preproc/t/001_ecpg.pl
new file mode 100644
index 0000000000..bc52d19a7f
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/001_ecpg.pl
@@ -0,0 +1,37 @@
+
+# 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');
+
+command_checks_all(
+       [ 'ecpg', 't/notice.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 warnings');
+
+done_testing();
diff --git a/src/interfaces/ecpg/preproc/t/notice.pgc 
b/src/interfaces/ecpg/preproc/t/notice.pgc
new file mode 100644
index 0000000000..7e54627fcb
--- /dev/null
+++ b/src/interfaces/ecpg/preproc/t/notice.pgc
@@ -0,0 +1,42 @@
+/* Test ECPG notice/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;
+}

Reply via email to