From 5d43113a78f40984e784181024438a6a792b057a Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Wed, 16 Sep 2026 16:27:44 -0500 Subject: [PATCH 1/4] Add test coverage for order-sensitive ON_ERROR_STOP check Add tests/updates for pgxntool commit https://github.com/Postgres-Extensions/pgxntool/pull/122 (order-sensitive ON_ERROR_STOP detection in check-test-install-error-stop.sh): - Bare substring grep passed a file that only ever turned ON_ERROR_STOP off; the script now requires an explicit on-value seen in file order. Extend the existing script-logic bats file with the two new cases that distinguish this from the old bare-substring behavior: - on-then-off still passes (a later off doesn't undo an earlier on) - off-only (never explicitly on) fails Co-Authored-By: Claude Sonnet 5 --- .../check-test-install-error-stop-script.bats | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/standard/check-test-install-error-stop-script.bats b/test/standard/check-test-install-error-stop-script.bats index be5f8a9..4f1a22b 100644 --- a/test/standard/check-test-install-error-stop-script.bats +++ b/test/standard/check-test-install-error-stop-script.bats @@ -42,6 +42,22 @@ setup() { assert_success } +@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is explicitly turned on then off" { + printf '\\set ON_ERROR_STOP on\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP off\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_success +} + +@test "check-test-install-error-stop.sh: fails when ON_ERROR_STOP is only ever turned off" { + printf '\\set ON_ERROR_STOP off\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_failure_with_status 1 + assert_contains "$output" "foo.sql" + assert_contains "$output" "ON_ERROR_STOP" +} + @test "check-test-install-error-stop.sh: fails when a file has neither" { printf 'CREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" From 6cd3308dd841f19e3ae21d9b0a44bcdef2055fc2 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Sun, 4 Oct 2026 14:54:34 -0500 Subject: [PATCH 2/4] Cover psql.sql-plus-turn-off failure in ON_ERROR_STOP check tests Add tests/updates for pgxntool commit ff766b3 (https://github.com/Postgres-Extensions/pgxntool/pull/122): an explicit `\set ON_ERROR_STOP on` excuses a later turn-off, but including psql.sql does not. - psql.sql plus `\set ON_ERROR_STOP off` fails - psql.sql plus `\unset ON_ERROR_STOP` fails Co-Authored-By: Claude Opus 5.5 --- .../check-test-install-error-stop-script.bats | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/standard/check-test-install-error-stop-script.bats b/test/standard/check-test-install-error-stop-script.bats index 4f1a22b..073821b 100644 --- a/test/standard/check-test-install-error-stop-script.bats +++ b/test/standard/check-test-install-error-stop-script.bats @@ -4,8 +4,10 @@ # # These tests exercise test/bin/check-test-install-error-stop.sh directly # against a bare scratch directory -- no foundation environment, no `make`, -# no PostgreSQL. They cover the script's own pass/fail logic: direct -# ON_ERROR_STOP, sourcing test/pgxntool/psql.sql, and files with neither. +# no PostgreSQL. They cover each branch of the script's pass/fail rule: an +# explicit `\set ON_ERROR_STOP on` passes even with a later turn-off; +# sourcing test/pgxntool/psql.sql passes only with no turn-off anywhere +# (`\set ... off` or `\unset`); anything else fails. # # Tests that need real Make integration (TEST_DEPS wiring, # PGXNTOOL_ENABLE_TEST_INSTALL_ERROR_STOP_CHECK=no skipping the target) stay @@ -49,6 +51,22 @@ setup() { assert_success } +@test "check-test-install-error-stop.sh: fails when a file sources psql.sql and also turns ON_ERROR_STOP off" { + printf '\\i test/pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP off\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_failure_with_status 1 + assert_contains "$output" "foo.sql: includes psql.sql but also disables ON_ERROR_STOP" +} + +@test "check-test-install-error-stop.sh: fails when a file sources psql.sql and also unsets ON_ERROR_STOP" { + printf '\\i test/pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\unset ON_ERROR_STOP\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_failure_with_status 1 + assert_contains "$output" "foo.sql: includes psql.sql but also disables ON_ERROR_STOP" +} + @test "check-test-install-error-stop.sh: fails when ON_ERROR_STOP is only ever turned off" { printf '\\set ON_ERROR_STOP off\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" From 4c99c476af8f1deb093748980996ac076e7e7f96 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Tue, 6 Oct 2026 14:12:44 -0500 Subject: [PATCH 3/4] Match check-test-install-error-stop tests to the any-mention rule Paired pgxntool commit: 1c54ae1884cf22fd2a2ce84ad8f2a752e1262bc3 A test/install/*.sql file now fails only if it neither includes test/pgxntool/psql.sql nor has any `\set`/`\unset ON_ERROR_STOP` command. Turn the old turn-off failure cases into passes, and add off-then-on, unset-only, no-trailing-newline and comment-only cases. Co-Authored-By: Claude Opus 5.5 --- .../check-test-install-error-stop-script.bats | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/test/standard/check-test-install-error-stop-script.bats b/test/standard/check-test-install-error-stop-script.bats index 073821b..a583b4a 100644 --- a/test/standard/check-test-install-error-stop-script.bats +++ b/test/standard/check-test-install-error-stop-script.bats @@ -4,10 +4,9 @@ # # These tests exercise test/bin/check-test-install-error-stop.sh directly # against a bare scratch directory -- no foundation environment, no `make`, -# no PostgreSQL. They cover each branch of the script's pass/fail rule: an -# explicit `\set ON_ERROR_STOP on` passes even with a later turn-off; -# sourcing test/pgxntool/psql.sql passes only with no turn-off anywhere -# (`\set ... off` or `\unset`); anything else fails. +# no PostgreSQL. The rule: a file fails only if it neither includes +# test/pgxntool/psql.sql nor has any `\set`/`\unset ON_ERROR_STOP` command, +# whatever the value or order. # # Tests that need real Make integration (TEST_DEPS wiring, # PGXNTOOL_ENABLE_TEST_INSTALL_ERROR_STOP_CHECK=no skipping the target) stay @@ -44,45 +43,69 @@ setup() { assert_success } -@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is explicitly turned on then off" { +@test "check-test-install-error-stop.sh: passes when a file sources psql.sql and turns ON_ERROR_STOP off" { + printf '\\i test/pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP OFF\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_success +} + +@test "check-test-install-error-stop.sh: passes when a file sources psql.sql via \\ir and unsets ON_ERROR_STOP" { + printf '\\ir ../pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\unset ON_ERROR_STOP\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_success +} + +@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is only ever turned off" { + printf '\\set ON_ERROR_STOP 0\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_success +} + +@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is only ever unset" { + printf '\\unset ON_ERROR_STOP\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" + + run "$SCRIPT" "$TESTDIR" + assert_success +} + +@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is turned on then off" { printf '\\set ON_ERROR_STOP on\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP off\n' > "$TESTDIR/install/foo.sql" run "$SCRIPT" "$TESTDIR" assert_success } -@test "check-test-install-error-stop.sh: fails when a file sources psql.sql and also turns ON_ERROR_STOP off" { - printf '\\i test/pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP off\n' > "$TESTDIR/install/foo.sql" +@test "check-test-install-error-stop.sh: passes when ON_ERROR_STOP is turned off then on" { + printf '\\set ON_ERROR_STOP off\nCREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP on\n' > "$TESTDIR/install/foo.sql" run "$SCRIPT" "$TESTDIR" - assert_failure_with_status 1 - assert_contains "$output" "foo.sql: includes psql.sql but also disables ON_ERROR_STOP" + assert_success } -@test "check-test-install-error-stop.sh: fails when a file sources psql.sql and also unsets ON_ERROR_STOP" { - printf '\\i test/pgxntool/psql.sql\nCREATE TABLE foo AS SELECT 1;\n\\unset ON_ERROR_STOP\n' > "$TESTDIR/install/foo.sql" +@test "check-test-install-error-stop.sh: passes when the \\set is the last line with no trailing newline" { + printf 'CREATE TABLE foo AS SELECT 1;\n\\set ON_ERROR_STOP on' > "$TESTDIR/install/foo.sql" run "$SCRIPT" "$TESTDIR" - assert_failure_with_status 1 - assert_contains "$output" "foo.sql: includes psql.sql but also disables ON_ERROR_STOP" + assert_success } -@test "check-test-install-error-stop.sh: fails when ON_ERROR_STOP is only ever turned off" { - printf '\\set ON_ERROR_STOP off\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" +@test "check-test-install-error-stop.sh: fails when a file never mentions ON_ERROR_STOP" { + printf 'CREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" run "$SCRIPT" "$TESTDIR" assert_failure_with_status 1 - assert_contains "$output" "foo.sql" - assert_contains "$output" "ON_ERROR_STOP" + assert_contains "$output" "foo.sql: never sets ON_ERROR_STOP" } -@test "check-test-install-error-stop.sh: fails when a file has neither" { - printf 'CREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" +@test "check-test-install-error-stop.sh: fails when ON_ERROR_STOP appears only in a comment" { + printf -- '-- ON_ERROR_STOP is set by the caller\nCREATE TABLE foo AS SELECT 1;\n' > "$TESTDIR/install/foo.sql" run "$SCRIPT" "$TESTDIR" assert_failure_with_status 1 - assert_contains "$output" "foo.sql" - assert_contains "$output" "ON_ERROR_STOP" + assert_contains "$output" "foo.sql: never sets ON_ERROR_STOP" } @test "check-test-install-error-stop.sh: reports every offending file, not just the first" { From 38a1fe844031b3e0302721c7c88a5618504a3eb1 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Tue, 6 Oct 2026 14:38:41 -0500 Subject: [PATCH 4/4] Test that psql.sql actually makes psql stop on error check-test-install-error-stop.sh accepts files that include psql.sql on the assumption that it sets ON_ERROR_STOP; verify that with a real psql. Co-Authored-By: Claude Sonnet 5.5 --- .../check-test-install-error-stop-script.bats | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/standard/check-test-install-error-stop-script.bats b/test/standard/check-test-install-error-stop-script.bats index a583b4a..b6d80e8 100644 --- a/test/standard/check-test-install-error-stop-script.bats +++ b/test/standard/check-test-install-error-stop-script.bats @@ -4,7 +4,7 @@ # # These tests exercise test/bin/check-test-install-error-stop.sh directly # against a bare scratch directory -- no foundation environment, no `make`, -# no PostgreSQL. The rule: a file fails only if it neither includes +# and no PostgreSQL except the one psql.sql test at the end. The rule: a file fails only if it neither includes # test/pgxntool/psql.sql nor has any `\set`/`\unset ON_ERROR_STOP` command, # whatever the value or order. # @@ -131,3 +131,13 @@ setup() { run "$SCRIPT" "$TESTDIR" extra assert_failure } + +# Guards the assumption check-test-install-error-stop.sh makes when it accepts +# files that include psql.sql. -X keeps ~/.psqlrc from masking a regression. +@test "test/pgxntool/psql.sql makes psql stop on error" { + skip_if_no_postgres + + run psql -X -f "$PGXNREPO/test/pgxntool/psql.sql" -c 'SELECT 1/0' -c '\echo SENTINEL' + assert_failure + [[ "$output" != *SENTINEL* ]] +}