Skip to content

Commit 1eb0f49

Browse files
committed
fix: doctest
1 parent 0a32d01 commit 1eb0f49

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/macros/test.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Mark an `async fn` as a test with SQLx support.
22

3-
The test will automatically be executed in the async runtime according to the chosen
3+
The test will automatically be executed in the async runtime according to the chosen
44
`runtime-{async-std, tokio}` feature. If more than one runtime feature is enabled, `runtime-tokio` is preferred.
55

66
By default, this behaves identically to `#[tokio::test]`<sup>1</sup> or `#[async_std::test]`:
@@ -31,25 +31,24 @@ but are isolated from each other.
3131
This feature is activated by changing the signature of your test function. The following signatures are supported:
3232

3333
* `async fn(Pool<DB>) -> Ret`
34-
* the `Pool`s used by all running tests share a single connection limit to avoid exceeding the server's limit.
34+
* the `Pool`s used by all running tests share a single connection limit to avoid exceeding the server's limit.
3535
* `async fn(PoolConnection<DB>) -> Ret`
36-
* `PoolConnection<Postgres>`, etc.
36+
* `PoolConnection<Postgres>`, etc.
3737
* `async fn(PoolOptions<DB>, impl ConnectOptions<DB>) -> Ret`
3838
* Where `impl ConnectOptions` is, e.g, `PgConnectOptions`, `MySqlConnectOptions`, etc.
39-
* If your test wants to create its own `Pool` (for example, to set pool callbacks or to modify `ConnectOptions`),
39+
* If your test wants to create its own `Pool` (for example, to set pool callbacks or to modify `ConnectOptions`),
4040
you can use this signature.
4141

4242
Where `DB` is a supported `Database` type and `Ret` is `()` or `Result<_, _>`.
4343

4444
##### Supported Databases
4545

46-
Most of these will require you to set `DATABASE_URL` as an environment variable
46+
Most of these will require you to set `DATABASE_URL` as an environment variable
4747
or in a `.env` file like `sqlx::query!()` _et al_, to give the test driver a superuser connection with which
4848
to manage test databases.
4949

50-
5150
| Database | Requires `DATABASE_URL` |
52-
| --- | --- |
51+
|----------|-------------------------|
5352
| Postgres | Yes |
5453
| MySQL | Yes |
5554
| SQLite | No<sup>2</sup> |
@@ -58,7 +57,7 @@ Test databases are automatically cleaned up as tests succeed, but failed tests w
5857
to facilitate debugging. Note that to simplify the implementation, panics are _always_ considered to be failures,
5958
even for `#[should_panic]` tests.
6059

61-
To limit disk space usage, any previously created test databases will be deleted the next time a test binary using
60+
To limit disk space usage, any previously created test databases will be deleted the next time a test binary using
6261
`#[sqlx::test]` is run.
6362

6463
```rust,no_run
@@ -86,8 +85,8 @@ converted to a filesystem path (`::` replaced with `/`).
8685

8786
### Automatic Migrations (requires `migrate` feature)
8887

89-
To ensure a straightforward test implementation against a fresh test database, migrations are automatically applied if a
90-
`migrations` folder is found in the same directory as `CARGO_MANIFEST_DIR` (the directory where the current crate's
88+
To ensure a straightforward test implementation against a fresh test database, migrations are automatically applied if a
89+
`migrations` folder is found in the same directory as `CARGO_MANIFEST_DIR` (the directory where the current crate's
9190
`Cargo.toml` resides).
9291

9392
You can override the resolved path relative to `CARGO_MANIFEST_DIR` in the attribute (global overrides are not currently
@@ -116,11 +115,13 @@ async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
116115
Or if you're already embedding migrations in your main crate, you can reference them directly:
117116

118117
`foo_crate/lib.rs`
118+
119119
```rust,ignore
120120
pub static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("foo_migrations");
121121
```
122122

123123
`foo_crate/tests/foo_test.rs`
124+
124125
```rust,no_run
125126
# #[cfg(all(feature = "migrate", feature = "postgres"))]
126127
# mod example {
@@ -129,12 +130,7 @@ use sqlx::{PgPool, Row};
129130
# // This is standing in for the main crate since doc examples don't support multiple crates.
130131
# mod foo_crate {
131132
# use std::borrow::Cow;
132-
# static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate::Migrator {
133-
# migrations: Cow::Borrowed(&[]),
134-
# ignore_missing: false,
135-
# locking: true,
136-
# no_tx: false
137-
# };
133+
# static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate::Migrator::DEFAULT;
138134
# }
139135
140136
// You could also do `use foo_crate::MIGRATOR` and just refer to it as `MIGRATOR` here.
@@ -188,9 +184,12 @@ the database to already have users and posts in it so the comments tests don't h
188184

189185
You can either pass a list of fixture to the attribute `fixtures` in three different operating modes:
190186

191-
1) Pass a list of references files in `./fixtures` (resolved as `./fixtures/{name}.sql`, `.sql` added only if extension is missing);
192-
2) Pass a list of file paths (including associated extension), in which case they can either be absolute, or relative to the current file;
193-
3) Pass a `path = <path to folder>` parameter and a `scripts(<filename_1>, <filename_2>, ...)` parameter that are relative to the provided path (resolved as `{path}/{filename_x}.sql`, `.sql` added only if extension is missing).
187+
1) Pass a list of references files in `./fixtures` (resolved as `./fixtures/{name}.sql`, `.sql` added only if extension
188+
is missing);
189+
2) Pass a list of file paths (including associated extension), in which case they can either be absolute, or relative to
190+
the current file;
191+
3) Pass a `path = <path to folder>` parameter and a `scripts(<filename_1>, <filename_2>, ...)` parameter that are
192+
relative to the provided path (resolved as `{path}/{filename_x}.sql`, `.sql` added only if extension is missing).
194193

195194
In any case they will be applied in the given order<sup>3</sup>:
196195

@@ -225,6 +224,6 @@ async fn test_create_comment(pool: PgPool) -> sqlx::Result<()> {
225224
Multiple `fixtures` attributes can be used to combine different operating modes.
226225

227226
<sup>3</sup>Ordering for test fixtures is entirely up to the application, and each test may choose which fixtures to
228-
apply and which to omit. However, since each fixture is applied separately (sent as a single command string, so wrapped
229-
in an implicit `BEGIN` and `COMMIT`), you will want to make sure to order the fixtures such that foreign key
227+
apply and which to omit. However, since each fixture is applied separately (sent as a single command string, so wrapped
228+
in an implicit `BEGIN` and `COMMIT`), you will want to make sure to order the fixtures such that foreign key
230229
requirements are always satisfied, or else you might get errors.

0 commit comments

Comments
 (0)