Cannot Put `#[pg_schema]` Tests in Separate File
I created a new extension:
cargo pgrx new separate_tests
Then followed the first example in this Discord post to try to move tests into a separate file, replacing this:
#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests {
// ...
}
With this:
#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests;
Alas, the compiler doesn't like it:
error[E0658]: non-inline modules in proc macro input are unstable
--> src/lib.rs:12:1
|
12 | mod tests;
| ^^^^^^^^^^
|
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
error: custom attribute panicked
--> src/lib.rs:11:1
|
11 | #[pg_schema]
| ^^^^^^^^^^^^
|
= help: message: Can only support `mod {}` right now.
For more information about this error, try `rustc --explain E0658`.
error: could not compile `separate_tests` (lib test) due to 2 previous errors
As a secondary issue, having moved tests into tests.rs, the rust language server tells me that the file isn't part of the crate. I'd have to use this directive above mod tests; as well:
#[path = "./tests.rs"]
Though it might work if I instead created the file ./tests/mod.rs.
Unfortunate.
As a secondary issue, having moved tests into tests.rs, the rust language server tells me that the file isn't part of the crate. I'd have to use this directive above mod tests; as well:
Which Rust language server are you using? Are you using RLS, or rust-analyzer?
Which Rust language server are you using? Are you using RLS, or rust-analyzer?
rust-analyzer I think. I didn't realize VSCode was't using Rust's own RLS.
It should be using rust-analyzer, which is our Rust language server, I just have to ask now and then because sometimes people wind up finding and enabling the legacy server.
I am very surprised rust-analyzer fails to detect the module. Odd.