-
Notifications
You must be signed in to change notification settings - Fork 1
Gate the main test suite on test-build; add build-results; require ON_ERROR_STOP in test/install #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Gate the main test suite on test-build; add build-results; require ON_ERROR_STOP in test/install #109
Changes from all commits
4916368
c9adf33
ec46fba
e444b08
184e8c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,13 @@ This will build any .html files that can be created. See <<_Document_Handling>>. | |
| === test | ||
| Runs your extension's test suite: installs the extension and runs it through PGXS's `installcheck`, first pulling in anything you've hooked into <<_testdeps>> and, if enabled, sanity-checking your test SQL via <<_test_build>>. | ||
|
|
||
| `make test` runs `pg_regress` in up to two separate passes: | ||
|
|
||
| 1. If <<_test_build,test-build>> is enabled, it runs first, in its own isolated pass over `test/build/*.sql`. If it fails, the second pass never happens — there's no point checking install/query behavior against a build that doesn't even come up cleanly. | ||
| 2. The main pass follows: any <<_testinstall,test/install>> files, then your regular `test/sql/*.sql` files, together in a single `pg_regress` invocation (so state the install files create persists into the regular tests). | ||
|
|
||
| Within each pass, files run in alphabetical order by filename. | ||
|
|
||
| Whether `test-build` runs is controlled by the `PGXNTOOL_ENABLE_TEST_BUILD` variable — see <<_test_build>> for what it does and how to turn it on/off. | ||
|
|
||
| NOTE: `test` intentionally does *not* depend on `clean` — that caused problems with incremental/watch-based builds. If your tests need a clean build to pass, that's a sign of a missing dependency elsewhere rather than something to fix by adding `clean` back. | ||
|
|
@@ -63,7 +70,9 @@ Validates that extension SQL files are syntactically correct before running the | |
| 1. Place SQL files in `test/build/*.sql` | ||
| 2. Place expected output in `test/build/expected/*.out` | ||
| 3. These files run through `pg_regress` before `make test` runs the main test suite | ||
| 4. If any build test fails, the test run stops immediately with clear error messages | ||
| 4. If any build test fails, `make test` stops immediately — the main suite (test/install + test/sql) never runs, since its results would be meaningless against a broken build | ||
|
|
||
| NOTE: This also means a stale or simply wrong `test/build/expected/*.out` -- not just a genuinely broken build -- blocks the whole suite. See <<_build_results,build-results>> below for the supported way to refresh it, including how to handle a file that's *supposed* to show an error. | ||
|
|
||
|
Comment on lines
+74
to
76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new NOTE (and the similar WARNING added at README.asc#L195-L197) mixes literal This also means a stale or simply wrong <code>test/build/expected/<strong>.out</code>not just a genuinely broken buildblocks the whole suite. See <a href="#_build_results">build-results</a> below for the supported way to refresh it, including how to handle a file thats *supposed</strong> to show an error.The glob's asterisk is lost (renders as Fix: use passthrough/literal monospace so no substitution runs inside the glob, e.g. |
||
| **Directory structure:** | ||
|
|
||
|
|
@@ -128,27 +137,42 @@ This approach catches SQL syntax errors *before* running `CREATE EXTENSION`, giv | |
|
|
||
| When `CREATE EXTENSION` fails, PostgreSQL shows only "syntax error" with limited context. Running the SQL directly via `\i` shows the exact line and position of errors, making debugging much faster. | ||
|
|
||
| ==== build-results | ||
|
|
||
| Refreshes `test/build/expected/*.out` from the actual output of the last `test-build` run, mirroring <<_results,results>> for the main suite: | ||
|
|
||
| ---- | ||
| make build-results | ||
| ---- | ||
|
|
||
| `build-results` will *not* bless a file whose actual output contains an `ERROR:` line — accepting an errored build as the new expected baseline would defeat the point of test-build. It skips that file (leaving its existing expected output in place), tells you exactly which file and the command to bless it with, and exits non-zero so the skip can't go unnoticed. | ||
|
|
||
| If your project intentionally exercises a build-time error (e.g. asserting a migration fails the way it should), bless that file by hand instead — this is a deliberate, supported case, not a workaround, and you'll need to repeat it by hand every time that file's output legitimately changes, since `build-results` will always skip it: | ||
|
|
||
| ---- | ||
| cp test/build/results/<name>.out test/build/expected/<name>.out | ||
| ---- | ||
|
|
||
| === test/install | ||
| Runs setup files before the main test suite within the same `pg_regress` invocation. This allows expensive one-time operations (like extension installation) to set up state that persists into the regular test files. | ||
|
|
||
| **How it works:** | ||
|
|
||
| 1. Place SQL files in `test/install/*.sql` | ||
| 2. Place expected output alongside as `test/install/*.out` | ||
| 3. A schedule file is auto-generated that lists install files with `../install/` relative paths | ||
| 4. `pg_regress` processes the install schedule first, then runs regular test files — all in one invocation, so database state persists | ||
| 2. A schedule file is auto-generated that lists install files with `../install/` relative paths | ||
| 3. `pg_regress` processes the install schedule first, then runs regular test files — all in one invocation, so database state persists | ||
|
|
||
| **Directory structure:** | ||
|
|
||
| ---- | ||
| test/install/ | ||
| ├── *.sql # SQL setup files (checked in) | ||
| ├── *.out # Expected output (checked in, alongside .sql) | ||
| ├── *.out # GENERATED, gitignored -- see WARNING below | ||
| ├── .gitignore # Ignores pg_regress artifacts (*.out.diff) | ||
| └── schedule # GENERATED - auto-created by make | ||
| ---- | ||
|
|
||
| The `schedule` file is generated automatically and listed in `.gitignore`. Do not edit it. | ||
| The `schedule` file is generated automatically and listed in `.gitignore`. Do not edit it. `*.out` is gitignored too, for the reason explained below — don't commit it. | ||
|
|
||
| **Configuration:** | ||
|
|
||
|
|
@@ -169,6 +193,8 @@ Without `test/install`, each test file typically needs to run `CREATE EXTENSION` | |
|
|
||
| **Key detail:** Install files and regular tests run in a single `pg_regress` invocation. This means the database is NOT dropped between install and test phases — state created by install files persists into the main test suite. | ||
|
|
||
| WARNING: **`test/install/*.out` is never actually compared against anything.** Unlike every other test type pgxntool supports, `test/install`'s actual output is written to the exact same file as its expected output, so there is no diff — a wrong or changed result will never fail the build, no matter how much it changes. The *only* thing that still fails the build is a hard SQL error, and only if the file sets `ON_ERROR_STOP` (directly, or via `\i test/pgxntool/psql.sql`) — without it, psql prints the error, keeps going, and the file "passes" regardless. pgxntool enforces this by default (`check-test-install-error-stop`, see `PGXNTOOL_ENABLE_TEST_INSTALL_ERROR_STOP_CHECK` to disable), but that only guarantees errors are caught — it does not give you real output validation. If you need actual output comparison, put that logic in `test/sql` instead (or use pgTap assertions from within the install file itself). | ||
|
|
||
| ==== Update & Upgrade (U&U) Testing | ||
|
|
||
| Beyond validating a plain install, it's worth testing that your extension behaves correctly across the two transitions every extension with more than one release eventually goes through: | ||
|
|
@@ -718,6 +744,10 @@ Default: auto-detected -- `yes` if `test/build/*.sql` files exist, `no` otherwis | |
|
|
||
| Default: auto-detected -- `yes` if `test/install/*.sql` files exist, `no` otherwise. Enables or disables the <<_testinstall,test/install>> schedule-based setup feature. Same explicit-override semantics as `PGXNTOOL_ENABLE_TEST_BUILD`. | ||
|
|
||
| === PGXNTOOL_ENABLE_TEST_INSTALL_ERROR_STOP_CHECK * | ||
|
|
||
| Default: `yes`. Enables or disables a build-time check that every `test/install/*.sql` file sets `ON_ERROR_STOP` (directly, or via `\i test/pgxntool/psql.sql`) -- see <<_testinstall,test/install>> for why this is the only thing that makes a hard error in one of those files actually fail the build. Set to `no` to disable the check. | ||
|
|
||
| === PGXNTOOL_ENABLE_VERIFY_RESULTS * | ||
|
|
||
| Default: `yes`. Enables or disables the <<_verify_results_safeguard,verify-results safeguard>> that blocks `make results` when tests are failing. Setting it to empty on the command line (`make PGXNTOOL_ENABLE_VERIFY_RESULTS= results`) also disables it. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fix, not worth mentioning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which specific wording/detail this is flagging — I compared this header against the file's own conventions (underline length, backtick usage, blank-line spacing between entries) and against the PR body's parallel section and didn't find a concrete defect to fix. Could you point at the specific text? Flagging back to the coordinator in the meantime rather than guessing at an edit.