diff --git a/test/sequential/04-pgtle.bats b/test/sequential/04-pgtle.bats index a020729..d663f4d 100644 --- a/test/sequential/04-pgtle.bats +++ b/test/sequential/04-pgtle.bats @@ -248,6 +248,71 @@ teardown_file() { [ "$mtime2" -gt "$mtime1" ] } +@test "pgtle: make print-pgtle PGXNTOOL_PGTLE_TARGET_VERSION=X prints the matching directory's SQL exactly (issue #21)" { + # print-pgtle's own Makefile wiring must forward + # PGXNTOOL_PGTLE_TARGET_VERSION to pgtle.sh --get-dir and print that + # directory's file verbatim. get_version_dir's own decision logic (which + # directory a version maps to) is already covered by the + # call_pgtle_function unit tests below; this only proves print-pgtle + # wires the version through and prints the right content. + # --separate-stderr: pgtle.sh's own progress messages (from the 'pgtle' + # prerequisite target) go to stderr, so the default merged-output mode + # would pollute $output with them ahead of the actual SQL content. + # --no-print-directory: this test suite itself runs under an outer + # recursive `make test-all`, which makes MAKEFLAGS carry a marker that + # causes GNU Make to auto-print "Entering directory"/"Leaving directory" + # to stdout for any nested make invocation (see the dedicated regression + # test below). Required here for the same reason real callers need it. + run --separate-stderr make --no-print-directory print-pgtle PGXNTOOL_PGTLE_TARGET_VERSION=1.5.2 + assert_success + + printf '%s\n' "$output" > "$BATS_TEST_TMPDIR/print-pgtle-1.5.2.out" + run diff "$BATS_TEST_TMPDIR/print-pgtle-1.5.2.out" "pg_tle/1.5.0+/pgxntool-test.sql" + assert_success +} + +@test "pgtle: make print-pgtle with an older PGXNTOOL_PGTLE_TARGET_VERSION selects the older range directory" { + # --separate-stderr / --no-print-directory: see comment in the test above. + run --separate-stderr make --no-print-directory print-pgtle PGXNTOOL_PGTLE_TARGET_VERSION=1.4.2 + assert_success + + printf '%s\n' "$output" > "$BATS_TEST_TMPDIR/print-pgtle-1.4.2.out" + run diff "$BATS_TEST_TMPDIR/print-pgtle-1.4.2.out" "pg_tle/1.4.0-1.5.0/pgxntool-test.sql" + assert_success +} + +@test "pgtle: print-pgtle output is polluted by 'Entering/Leaving directory' without --no-print-directory when invoked recursively (issue #21)" { + # Regression test for a real footgun found while writing the tests above: + # GNU Make auto-prints "Entering directory"/"Leaving directory" to stdout + # for recursive invocations (MAKEFLAGS carrying a recursion marker, as + # happens whenever the caller is itself already inside a make recipe -- + # exactly the documented `$(MAKE) -C ../deps/cat_tools print-pgtle` use + # case). This corrupts a redirected combined SQL file with garbage lines + # unless --no-print-directory is passed. Simulate that recursive-caller + # environment directly (MAKEFLAGS="w --") rather than relying on this + # suite's own outer `make test-all` wrapper, so the test is meaningful + # even when this file runs standalone (bats invoked directly, no wrapper). + MAKEFLAGS="w --" run --separate-stderr make print-pgtle PGXNTOOL_PGTLE_TARGET_VERSION=1.5.2 + assert_success + assert_contains "$output" "Entering directory" + + MAKEFLAGS="w --" run --separate-stderr make --no-print-directory print-pgtle PGXNTOOL_PGTLE_TARGET_VERSION=1.5.2 + assert_success + ! echo "$output" | grep -q "Entering directory" +} + +@test "pgtle: env var PGTLE_VERSION does not set PGXNTOOL_PGTLE_TARGET_VERSION" { + # Mirrors the issue #78 collision test above, but for the new + # PGXNTOOL_PGTLE_TARGET_VERSION variable print-pgtle reads. A bare + # PGTLE_VERSION env var (used elsewhere for "which pg_tle to test + # against") must not leak into make's similarly-named variable. + # Uses the print-% debug target directly rather than invoking + # print-pgtle for real, since only the variable's value is at stake here. + PGTLE_VERSION=1.5.2 run make print-PGXNTOOL_PGTLE_TARGET_VERSION + assert_success + assert_not_contains "$output" "1.5.2" +} + @test "pgtle: error on missing control file" { run "$TEST_REPO/pgxntool/pgtle.sh" --extension nonexistent --pgtle-version 1.5.0+ assert_failure diff --git a/test/standard/pgtle-install.bats b/test/standard/pgtle-install.bats index 422b6aa..dde8da6 100644 --- a/test/standard/pgtle-install.bats +++ b/test/standard/pgtle-install.bats @@ -206,6 +206,58 @@ setup() { psql -X -c "DROP EXTENSION IF EXISTS \"pgxntool-test\";" >/dev/null 2>&1 || true } +@test "pgtle-install: print-pgtle falls back to the installed pg_tle version (issue #21)" { + # No PGXNTOOL_PGTLE_TARGET_VERSION set: print-pgtle's own Makefile wiring + # must fall back to pgtle.sh --get-version to detect the installed pg_tle + # version, then select and print that version's directory content. + # --get-version's/--get-dir's own decision logic is covered by + # 04-pgtle.bats's call_pgtle_function unit tests; this only proves + # print-pgtle's DB-fallback path is wired correctly end-to-end. + if ! ensure_pgtle_extension; then + skip "pg_tle extension cannot be created: $PGTLE_EXTENSION_ERROR" + fi + + local installed_version + installed_version=$(psql -X -tAc "SELECT extversion FROM pg_extension WHERE extname = 'pg_tle';" | tr -d '[:space:]') + local expected_dir + expected_dir=$("$TEST_REPO/pgxntool/pgtle.sh" --get-dir "$installed_version") + + # --separate-stderr: pgtle.sh's own progress messages (from the 'pgtle' + # prerequisite target) go to stderr, so the default merged-output mode + # would pollute $output with them ahead of the actual SQL content. + # --no-print-directory: required when make is invoked recursively (this + # suite runs under an outer `make test-all`) -- see the dedicated + # regression test in 04-pgtle.bats for why. + run --separate-stderr make --no-print-directory print-pgtle + assert_success + + printf '%s\n' "$output" > "$BATS_TEST_TMPDIR/print-pgtle-dbfallback.out" + run diff "$BATS_TEST_TMPDIR/print-pgtle-dbfallback.out" "$expected_dir/pgxntool-test.sql" + assert_success +} + +@test "pgtle-install: print-pgtle errors cleanly when pg_tle is not installed and no target version is set" { + # With pg_tle genuinely absent and PGXNTOOL_PGTLE_TARGET_VERSION unset, + # print-pgtle has no way to pick a directory. It must fail loudly (clear + # stderr message, no stdout) rather than silently printing nothing or + # picking a wrong directory. + # + # Drops the shared pg_tle extension - matches the pattern already used by + # test-pgtle-versions.bats. Placed last (before final cleanup) so no + # later test in this file depends on pg_tle staying installed; every test + # here that needs pg_tle calls ensure_pgtle_extension() itself, which + # self-heals by recreating it. + run psql -X -c "DROP EXTENSION IF EXISTS pg_tle CASCADE;" + assert_success + reset_pgtle_cache + + # --no-print-directory: see comment in the test above. + run --separate-stderr make --no-print-directory print-pgtle + assert_failure + [ -z "$output" ] + assert_contains "$stderr" "pg_tle version not specified and pg_tle is not installed" +} + @test "pgtle-install: test cleanup" { # Clean up test extension run psql -X -c "DROP EXTENSION IF EXISTS \"pgxntool-test\";"