Skip to content

Commit 44d0966

Browse files
committed
cargo-pgrx: fix pg_regress path inconsistency
The 'cargo pgrx new' command was creating pg_regress directories at the project root (./pg_regress/), while 'cargo pgrx regress' expected them under the tests directory (./tests/pg_regress/). This inconsistency caused immediate failures when running regression tests on newly created projects. Fix the path mismatch by updating 'cargo pgrx new' to create the pg_regress directory structure under tests/, aligning with where 'cargo pgrx regress' expects to find them. This follows Rust's convention of organizing test files in a tests/ directory. Also update the documentation and the hooks example to use the consistent path structure. Fixes: #2136 ("Inconsistencies in the pg_regress path") Signed-off-by: Charalampos Mitrodimas <[email protected]>
1 parent 0b04f1a commit 44d0966

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

cargo-pgrx/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@ $ tree
590590

591591
`setup.sql` is a special test in that it's run first, by itself, whenever the test database is first created, or reset using the `--resetdb` argument.
592592

593-
When creating a new test, first make the `.sql` file in `./pg_regress/sql/` and then run `cargo pgrx regress`. pgrx will detect that the file is new and interactively prompt you to add its output, automatically adding it to git (if the directory is managed by git).
593+
When creating a new test, first make the `.sql` file in `./tests/pg_regress/sql/` and then run `cargo pgrx regress`. pgrx will detect that the file is new and interactively prompt you to add its output, automatically adding it to git (if the directory is managed by git).
594594

595595
For example,
596596

597597
```console
598-
$ echo "SELECT 1;" > ./pg_regress/sql/example.sql
598+
$ echo "SELECT 1;" > ./tests/pg_regress/sql/example.sql
599599
$ cargo pgrx regress
600600
Using DefaultFeature("pg13") and `pg_config` from ~/.pgrx/13.20/pgrx-install/bin/pg_config
601601
Stopping Postgres v13
@@ -627,7 +627,7 @@ test `example` generated the above output:
627627
Accept [Y, n]?
628628
```
629629

630-
Typing `Y` (or just pressing return) will copy the test output to the proper location, `./pg_regress/expected/example.sql` and then run the entire test suite:
630+
Typing `Y` (or just pressing return) will copy the test output to the proper location, `./tests/pg_regress/expected/example.out` and then run the entire test suite:
631631

632632
```console
633633
...
@@ -657,7 +657,7 @@ Alternatively, you can run `cargo pgrx regress --auto` (or `-a`) to **automatica
657657
- tests are executed in alphabetical order
658658
- pgrx creates a database named `$extname_regress` unless `--dbname` is used
659659
- Postgres' documentation for `pg_regress` [begins here](https://www.postgresql.org/docs/current/regress.html). While pgrx does not support every knob and dial, its organization is largely compatible (PRs welcome to enhance features)
660-
- to regenerate the expected test output, delete the `./pg_regress/expected/TEST_NAME.out` file and run `cargo pgrx regress`. You'll be prompted to accept the new output and it'll automatically be run through `git add`
660+
- to regenerate the expected test output, delete the `./tests/pg_regress/expected/TEST_NAME.out` file and run `cargo pgrx regress`. You'll be prompted to accept the new output and it'll automatically be run through `git add`
661661
- `pg_regress` uses `psql` to run each test and literally diffs the output against the expected output file. pgrx does two things to help eliminate noise in the test output. The first is it sets `client_min_messages=warning` when starting the Postgres instance and it also passes `-v VERBOSITY=terse` through to `psql`.
662662

663663
### Diffing `psql` Output?
@@ -731,7 +731,7 @@ file " ~/_work/pgrx/tests/pgrx-examples/range/tests/pg_regress/regression.diffs"
731731
above is saved in the file " ~/_work/pgrx/tests/pgrx-examples/range/tests/pg_regress/regression.out".
732732
```
733733

734-
And you see the `bad` test immediately failed! To see how it failed, look at the `./pg_regress/regression.diffs` file:
734+
And you see the `bad` test immediately failed! To see how it failed, look at the `./tests/pg_regress/regression.diffs` file:
735735

736736
```console
737737
$ diff -U3 ~/_work/pgrx/tests/pgrx-examples/range/tests/pg_regress/expected/bad.out ~/_work/pgrx/tests/pgrx-examples/range/tests/pg_regress/results/bad.out

cargo-pgrx/src/command/new.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub(crate) fn create_crate_template(
6767
fn create_directory_structure(root: PathBuf) -> Result<(), std::io::Error> {
6868
std::fs::create_dir_all(root.join(".cargo"))?;
6969
std::fs::create_dir_all(root.join("src").join("bin"))?;
70-
std::fs::create_dir_all(root.join("pg_regress").join("expected"))?;
71-
std::fs::create_dir_all(root.join("pg_regress").join("sql"))?;
70+
std::fs::create_dir_all(root.join("tests").join("pg_regress").join("expected"))?;
71+
std::fs::create_dir_all(root.join("tests").join("pg_regress").join("sql"))?;
7272
std::fs::create_dir_all(root.join("sql"))?;
7373

7474
Ok(())
@@ -141,6 +141,7 @@ fn create_pgrx_embed_rs(mut filename: PathBuf) -> Result<(), std::io::Error> {
141141
}
142142

143143
fn create_setup_sql(mut filename: PathBuf, name: &str) -> Result<(), std::io::Error> {
144+
filename.push("tests");
144145
filename.push("pg_regress");
145146
filename.push("sql");
146147
filename.push("setup.sql");
@@ -150,6 +151,7 @@ fn create_setup_sql(mut filename: PathBuf, name: &str) -> Result<(), std::io::Er
150151
}
151152

152153
fn create_setup_out(mut filename: PathBuf, name: &str) -> Result<(), std::io::Error> {
154+
filename.push("tests");
153155
filename.push("pg_regress");
154156
filename.push("expected");
155157
filename.push("setup.out");

cargo-pgrx/src/templates/gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
*.iml
55
**/*.rs.bk
66
Cargo.lock
7-
pg_regress/results
8-
pg_regress/regression.diffs
9-
pg_regress/regression.out
7+
tests/pg_regress/results
8+
tests/pg_regress/regression.diffs
9+
tests/pg_regress/regression.out

0 commit comments

Comments
 (0)