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
This commit is contained in:
joeydewaal 2024-08-26 23:03:22 +02:00 committed by GitHub
parent ebf04ff499
commit 1d8eb2add4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 3 deletions

View file

@ -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;
@ -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(

View file

@ -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(())
}

View file

@ -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(())
}