Skip to content

Commit

Permalink
Fix (#3395) sqlx::test macro in 0.8 (#3403)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joeydewaal authored Aug 26, 2024
1 parent ebf04ff commit 1d8eb2a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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(())
}

0 comments on commit 1d8eb2a

Please sign in to comment.