Test against all supported runtime
This commit is contained in:
parent
514e12a335
commit
2cfaa34a33
@ -84,3 +84,23 @@ pub fn derive_from_query_result(input: TokenStream) -> TokenStream {
|
||||
Err(e) => e.to_compile_error().into(),
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[proc_macro_attribute]
|
||||
pub fn test(_: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let input = syn::parse_macro_input!(input as syn::ItemFn);
|
||||
|
||||
let ret = &input.sig.output;
|
||||
let name = &input.sig.ident;
|
||||
let body = &input.block;
|
||||
let attrs = &input.attrs;
|
||||
|
||||
quote::quote! (
|
||||
#[test]
|
||||
#(#attrs)*
|
||||
fn #name() #ret {
|
||||
::sea_orm::block_on!(async { #body })
|
||||
}
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find().one(&db).await?,
|
||||
@ -170,7 +170,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find_by_id(11).all(&db).await?,
|
||||
@ -207,7 +207,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake_filling};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// assert_eq!(
|
||||
/// cake_filling::Entity::find_by_id((2, 3)).all(&db).await?,
|
||||
@ -275,7 +275,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// ..Default::default()
|
||||
/// };
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let insert_result = cake::Entity::insert(apple).exec(&db).await?;
|
||||
///
|
||||
@ -326,7 +326,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// ..Default::default()
|
||||
/// };
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let insert_result = cake::Entity::insert_many(vec![apple, orange]).exec(&db).await?;
|
||||
///
|
||||
@ -378,7 +378,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// ..Default::default()
|
||||
/// };
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// assert_eq!(
|
||||
/// fruit::Entity::update(orange.clone()).exec(&db).await?, // Clone here because we need to assert_eq
|
||||
@ -422,7 +422,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::{Expr, Value}};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let update_result = fruit::Entity::update_many()
|
||||
/// .col_expr(fruit::Column::CakeId, Expr::value(Value::Null))
|
||||
@ -471,7 +471,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// ..Default::default()
|
||||
/// };
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let delete_result = fruit::Entity::delete(orange).exec(&db).await?;
|
||||
///
|
||||
@ -514,7 +514,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let delete_result = fruit::Entity::delete_many()
|
||||
/// .filter(fruit::Column::Name.contains("Apple"))
|
||||
|
@ -97,7 +97,7 @@ where
|
||||
/// # use sea_orm::{error::*, MockDatabase, DbBackend};
|
||||
/// # let owned_db = MockDatabase::new(DbBackend::Postgres).into_connection();
|
||||
/// # let db = &owned_db;
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
/// let mut cake_pages = cake::Entity::find()
|
||||
@ -125,7 +125,7 @@ where
|
||||
/// # use sea_orm::{error::*, MockDatabase, DbBackend};
|
||||
/// # let owned_db = MockDatabase::new(DbBackend::Postgres).into_connection();
|
||||
/// # let db = &owned_db;
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// use futures::TryStreamExt;
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
@ -203,7 +203,7 @@ mod tests {
|
||||
(db, num_items)
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn fetch_page() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
@ -233,7 +233,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn fetch() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
@ -267,7 +267,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn num_pages() -> Result<(), DbErr> {
|
||||
let (db, num_items) = setup_num_items();
|
||||
|
||||
@ -299,7 +299,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn next_and_cur_page() -> Result<(), DbErr> {
|
||||
let (db, _) = setup();
|
||||
|
||||
@ -315,7 +315,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn fetch_and_next() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
@ -350,7 +350,7 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[sea_orm_macros::test]
|
||||
async fn into_stream() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
|
@ -287,7 +287,7 @@ where
|
||||
/// num_of_cakes: i32,
|
||||
/// }
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let res: Vec<SelectResult> = cake::Entity::find().from_raw_sql(
|
||||
/// Statement::from_sql_and_values(
|
||||
@ -352,7 +352,7 @@ where
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let res: Vec<serde_json::Value> = cake::Entity::find().from_raw_sql(
|
||||
/// Statement::from_sql_and_values(
|
||||
@ -404,7 +404,7 @@ where
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let _: Option<cake::Model> = cake::Entity::find().from_raw_sql(
|
||||
/// Statement::from_sql_and_values(
|
||||
@ -439,7 +439,7 @@ where
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// # let _: Result<(), DbErr> = async_std::task::block_on(async {
|
||||
/// # let _: Result<(), DbErr> = sea_orm::block_on!(async {
|
||||
/// #
|
||||
/// let _: Vec<cake::Model> = cake::Entity::find().from_raw_sql(
|
||||
/// Statement::from_sql_and_values(
|
||||
|
@ -207,6 +207,8 @@ pub mod error;
|
||||
mod executor;
|
||||
pub mod query;
|
||||
#[doc(hidden)]
|
||||
pub mod runtime;
|
||||
#[doc(hidden)]
|
||||
pub mod tests_cfg;
|
||||
mod util;
|
||||
|
||||
|
@ -140,11 +140,11 @@ impl FromQueryResult for JsonValue {
|
||||
#[cfg(feature = "mock")]
|
||||
mod tests {
|
||||
use crate::tests_cfg::cake;
|
||||
use crate::{entity::*, DbBackend, MockDatabase};
|
||||
use crate::{entity::*, DbBackend, DbErr, MockDatabase};
|
||||
use sea_query::Value;
|
||||
|
||||
#[async_std::test]
|
||||
async fn to_json_1() {
|
||||
#[sea_orm_macros::test]
|
||||
async fn to_json_1() -> Result<(), DbErr> {
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_query_results(vec![vec![maplit::btreemap! {
|
||||
"id" => Into::<Value>::into(128), "name" => Into::<Value>::into("apple")
|
||||
@ -158,5 +158,7 @@ mod tests {
|
||||
"name": "apple"
|
||||
}))
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
33
src/runtime.rs
Normal file
33
src/runtime.rs
Normal file
@ -0,0 +1,33 @@
|
||||
#[cfg(any(
|
||||
feature = "runtime-async-std",
|
||||
all(
|
||||
not(feature = "runtime-async-std"),
|
||||
not(feature = "runtime-actix"),
|
||||
not(feature = "runtime-tokio"),
|
||||
),
|
||||
))]
|
||||
#[macro_export]
|
||||
macro_rules! block_on {
|
||||
($($expr:tt)*) => {
|
||||
::async_std::task::block_on( $($expr)* )
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-actix")]
|
||||
#[macro_export]
|
||||
macro_rules! block_on {
|
||||
($($expr:tt)*) => {
|
||||
::actix_rt::System::new()
|
||||
.block_on( $($expr)* )
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-tokio")]
|
||||
#[macro_export]
|
||||
macro_rules! block_on {
|
||||
($($expr:tt)*) => {
|
||||
::tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on( $($expr)* )
|
||||
};
|
||||
}
|
@ -2,9 +2,7 @@
|
||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn};
|
||||
|
||||
// DATABASE_URL="sqlite::memory:" cargo test --features sqlx-sqlit,runtime-async-std --test basic
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
async fn main() {
|
||||
use std::env;
|
||||
|
@ -8,9 +8,7 @@ mod crud;
|
||||
// Run the test locally:
|
||||
// DATABASE_URL="mysql://root:root@localhost" cargo test --features sqlx-mysql,runtime-async-std --test crud_tests
|
||||
// DATABASE_URL="postgres://root:root@localhost" cargo test --features sqlx-postgres,runtime-async-std --test crud_tests
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
|
@ -6,9 +6,7 @@ pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||
|
||||
// Run the test locally:
|
||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test query_tests
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -23,9 +21,7 @@ pub async fn find_one_with_no_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -50,9 +46,7 @@ pub async fn find_one_with_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -67,9 +61,7 @@ pub async fn find_by_id_with_no_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -98,9 +90,7 @@ pub async fn find_by_id_with_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -115,9 +105,7 @@ pub async fn find_all_with_no_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -151,9 +139,7 @@ pub async fn find_all_with_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -191,9 +177,7 @@ pub async fn find_all_filter_no_result() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
|
@ -8,9 +8,7 @@ pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||
|
||||
// Run the test locally:
|
||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test relational_tests
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -91,9 +89,7 @@ pub async fn left_join() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
pub async fn right_join() {
|
||||
let ctx = TestContext::new("test_right_join").await;
|
||||
@ -174,9 +170,7 @@ pub async fn right_join() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -265,9 +259,7 @@ pub async fn inner_join() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -371,9 +363,7 @@ pub async fn group_by() {
|
||||
ctx.delete().await;
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
|
@ -9,9 +9,7 @@ pub use common::{bakery_chain::*, setup::*, TestContext};
|
||||
|
||||
// Run the test locally:
|
||||
// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests
|
||||
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
|
||||
#[cfg_attr(feature = "runtime-actix", actix_rt::test)]
|
||||
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
|
||||
#[sea_orm_macros::test]
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
|
||||
pub async fn test_multiple_operations() {
|
||||
let ctx = TestContext::new("multiple_sequential_operations").await;
|
||||
|
Loading…
x
Reference in New Issue
Block a user