Skip to content
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

Fix (#3395) sqlx::test macro in 0.8 #3403

Merged
merged 11 commits into from
Aug 26, 2024
10 changes: 7 additions & 3 deletions sqlx-macros-core/src/test_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ fn expand_advanced(args: AttributeArgs, input: syn::ItemFn) -> crate::Result<Tok

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

let mut fixtures = Vec::new();
let mut migrations = MigrationsOpt::InferredPath;
Expand All @@ -208,8 +211,9 @@ fn parse_args(attr_args: AttributeArgs) -> syn::Result<Args> {
parse_fixtures_path_args(&mut fixtures_type, val)?;
} else if meta.path.is_ident("scripts") {
// fixtures(path = "<path>", scripts("<file_1>","<file_2>")) checking `scripts` argument
let parser = <Punctuated<LitStr, Token![,]>>::parse_terminated;
let list = parser.parse2(list.tokens.clone())?;
let content;
parenthesized!(content in meta.input);
let list = content.parse_terminated(<LitStr as Parse>::parse, Comma)?;
parse_fixtures_scripts_args(&mut fixtures_type, list, &mut fixtures_local)?;
} else {
return Err(syn::Error::new_spanned(
Expand Down
8 changes: 8 additions & 0 deletions tests/postgres/test-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ async fn it_gets_comments(pool: PgPool) -> sqlx::Result<()> {

Ok(())
}

#[sqlx::test(
migrations = "tests/postgres/migrations",
fixtures(path = "../fixtures/postgres", scripts("users", "posts"))
)]
async fn this_should_compile(_pool: PgPool) -> sqlx::Result<()> {
Ok(())
}
8 changes: 8 additions & 0 deletions tests/sqlite/test-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ async fn it_gets_comments(pool: SqlitePool) -> sqlx::Result<()> {

Ok(())
}

#[sqlx::test(
migrations = "tests/sqlite/migrations",
fixtures(path = "./fixtures", scripts("users", "posts"))
)]
async fn this_should_compile(_pool: SqlitePool) -> sqlx::Result<()> {
Ok(())
}