Skip to content

Commit 1d8eb2a

Browse files
authored
Fix (#3395) sqlx::test macro in 0.8 (#3403)
* fix: fixture macro attribute * remove extra new line * add extra new line * feat: add test for slqx::test macro * feat: update test for sqlx::test macro * remove old macro test * feat: add postgres and sqlite test * rust format * cargo fmt * fix fixtures execution order in test
1 parent ebf04ff commit 1d8eb2a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

sqlx-macros-core/src/test_attr.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ fn expand_advanced(args: AttributeArgs, input: syn::ItemFn) -> crate::Result<Tok
187187

188188
#[cfg(feature = "migrate")]
189189
fn parse_args(attr_args: AttributeArgs) -> syn::Result<Args> {
190-
use syn::{punctuated::Punctuated, Expr, Lit, LitStr, Meta, MetaNameValue, Token};
190+
use syn::{
191+
parenthesized, parse::Parse, punctuated::Punctuated, token::Comma, Expr, Lit, LitStr, Meta,
192+
MetaNameValue, Token,
193+
};
191194

192195
let mut fixtures = Vec::new();
193196
let mut migrations = MigrationsOpt::InferredPath;
@@ -208,8 +211,9 @@ fn parse_args(attr_args: AttributeArgs) -> syn::Result<Args> {
208211
parse_fixtures_path_args(&mut fixtures_type, val)?;
209212
} else if meta.path.is_ident("scripts") {
210213
// fixtures(path = "<path>", scripts("<file_1>","<file_2>")) checking `scripts` argument
211-
let parser = <Punctuated<LitStr, Token![,]>>::parse_terminated;
212-
let list = parser.parse2(list.tokens.clone())?;
214+
let content;
215+
parenthesized!(content in meta.input);
216+
let list = content.parse_terminated(<LitStr as Parse>::parse, Comma)?;
213217
parse_fixtures_scripts_args(&mut fixtures_type, list, &mut fixtures_local)?;
214218
} else {
215219
return Err(syn::Error::new_spanned(

tests/postgres/test-attr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,11 @@ async fn it_gets_comments(pool: PgPool) -> sqlx::Result<()> {
178178

179179
Ok(())
180180
}
181+
182+
#[sqlx::test(
183+
migrations = "tests/postgres/migrations",
184+
fixtures(path = "../fixtures/postgres", scripts("users", "posts"))
185+
)]
186+
async fn this_should_compile(_pool: PgPool) -> sqlx::Result<()> {
187+
Ok(())
188+
}

tests/sqlite/test-attr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,11 @@ async fn it_gets_comments(pool: SqlitePool) -> sqlx::Result<()> {
9797

9898
Ok(())
9999
}
100+
101+
#[sqlx::test(
102+
migrations = "tests/sqlite/migrations",
103+
fixtures(path = "./fixtures", scripts("users", "posts"))
104+
)]
105+
async fn this_should_compile(_pool: SqlitePool) -> sqlx::Result<()> {
106+
Ok(())
107+
}

0 commit comments

Comments
 (0)