diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30138cf143f6..6c5cb7599d0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ concurrency: jobs: check_and_test: name: Check - needs: [sqlite_bundled, rustfmt_and_clippy, postgres_bundled, mysql_bundled] + needs: [sqlite_bundled, sqlite_wasm, rustfmt_and_clippy, postgres_bundled, mysql_bundled] strategy: fail-fast: false matrix: @@ -278,6 +278,26 @@ jobs: - name: Run clippy + rustfmt run: cargo xtask tidy --keep-going + sqlite_wasm: + name: Check sqlite wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: "rust-src" + targets: "wasm32-unknown-unknown" + - name: Cache cargo registry + uses: Swatinem/rust-cache@v2 + with: + key: sqlite_wasm-cargo-${{ hashFiles('**/Cargo.toml') }} + + - name: Install wasm-pack + run: cargo install wasm-pack + + - name: Test unit and integration tests + run: cargo xtask run-tests --wasm sqlite + sqlite_bundled: name: Check sqlite bundled + Sqlite with asan runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index e3364699e831..ecb0c73423a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ in a way that makes the pools suitable for use in parallel tests. * Added `Json` and `Jsonb` support for the SQLite backend. * Fixed diesel thinking `a.eq_any(b)` was non-nullable even if `a` and `b` were nullable. * Generate `InstrumentationEvent::BeginTransaction` for immediate and exclusive transactions in SQLite +* Added `wasm32-unknown-unknown` target support for sqlite backend. ### Fixed diff --git a/Cargo.toml b/Cargo.toml index f9cc906b7efc..986faaed41d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "diesel_cli", "diesel_derives", "diesel_tests", + "diesel_test_helper", "diesel_migrations", "diesel_migrations/migrations_internals", "diesel_migrations/migrations_macros", diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index fc55f9476130..3290eb3bf6c5 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -24,7 +24,6 @@ include = [ byteorder = { version = "1.0", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] } libc = { version = "0.2.0", optional = true } -libsqlite3-sys = { version = ">=0.17.2, <0.31.0", optional = true, features = ["bundled_bindings"] } mysqlclient-sys = { version = ">=0.2.5, <0.5.0", optional = true } mysqlclient-src = { version = "0.1.0", optional = true } pq-sys = { version = ">=0.4.0, <0.8.0", optional = true } @@ -50,12 +49,24 @@ downcast-rs = "1.2.1" version = "~2.2.0" path = "../diesel_derives" +[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies] +libsqlite3-sys = { version = ">=0.17.2, <0.31.0", optional = true, features = ["bundled_bindings"] } + +[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] +sqlite-wasm-rs = { version = ">=0.1.3, <0.2.0", optional = true } + +[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies] +# Something is dependent on it, so we use feature to override it. +getrandom = { version = "0.2", features = ["js"] } +wasm-bindgen-test = "0.3.49" + [dev-dependencies] cfg-if = "1" dotenvy = "0.15" ipnetwork = ">=0.12.2, <0.22.0" quickcheck = "1.0.3" tempfile = "3.10.1" +diesel_test_helper = { path = "../diesel_test_helper" } [features] default = ["with-deprecated", "32-column-tables"] @@ -67,7 +78,7 @@ huge-tables = ["64-column-tables"] 64-column-tables = ["32-column-tables", "diesel_derives/64-column-tables"] 128-column-tables = ["64-column-tables", "diesel_derives/128-column-tables"] postgres = ["dep:pq-sys", "postgres_backend"] -sqlite = ["dep:libsqlite3-sys", "diesel_derives/sqlite", "time?/formatting", "time?/parsing"] +sqlite = ["dep:libsqlite3-sys", "dep:sqlite-wasm-rs", "diesel_derives/sqlite", "time?/formatting", "time?/parsing"] mysql = ["dep:mysqlclient-sys", "dep:url", "dep:percent-encoding", "dep:bitflags", "mysql_backend"] without-deprecated = ["diesel_derives/without-deprecated"] with-deprecated = ["diesel_derives/with-deprecated"] diff --git a/diesel/src/connection/statement_cache/strategy.rs b/diesel/src/connection/statement_cache/strategy.rs index 7c7919038827..64bfe6e4c1a4 100644 --- a/diesel/src/connection/statement_cache/strategy.rs +++ b/diesel/src/connection/statement_cache/strategy.rs @@ -171,7 +171,7 @@ mod tests_pg { conn } - #[test] + #[diesel_test_helper::test] fn prepared_statements_are_cached() { let connection = &mut connection(); @@ -183,7 +183,7 @@ mod tests_pg { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_with_identical_sql_but_different_types_are_cached_separately() { let connection = &mut connection(); @@ -196,7 +196,7 @@ mod tests_pg { assert_eq!(2, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_with_identical_types_and_sql_but_different_bind_types_are_cached_separately() { let connection = &mut connection(); @@ -211,7 +211,7 @@ mod tests_pg { define_sql_function!(fn lower(x: VarChar) -> VarChar); - #[test] + #[diesel_test_helper::test] fn queries_with_identical_types_and_binds_but_different_sql_are_cached_separately() { let connection = &mut connection(); @@ -225,7 +225,7 @@ mod tests_pg { assert_eq!(2, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_with_sql_literal_nodes_are_not_cached() { let connection = &mut connection(); let query = crate::select(sql::("1")); @@ -234,7 +234,7 @@ mod tests_pg { assert_eq!(0, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn inserts_from_select_are_cached() { let connection = &mut connection(); connection.begin_test_transaction().unwrap(); @@ -260,7 +260,7 @@ mod tests_pg { assert_eq!(2, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn single_inserts_are_cached() { let connection = &mut connection(); connection.begin_test_transaction().unwrap(); @@ -278,7 +278,7 @@ mod tests_pg { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn dynamic_batch_inserts_are_not_cached() { let connection = &mut connection(); connection.begin_test_transaction().unwrap(); @@ -296,7 +296,7 @@ mod tests_pg { assert_eq!(0, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn static_batch_inserts_are_cached() { let connection = &mut connection(); connection.begin_test_transaction().unwrap(); @@ -314,7 +314,7 @@ mod tests_pg { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_containing_in_with_vec_are_cached() { let connection = &mut connection(); let one_as_expr = 1.into_sql::(); @@ -324,7 +324,7 @@ mod tests_pg { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn disabling_the_cache_works() { let connection = &mut connection(); connection.set_prepared_statement_cache_size(CacheSize::Disabled); @@ -356,7 +356,7 @@ mod tests_sqlite { conn } - #[test] + #[diesel_test_helper::test] fn prepared_statements_are_cached_when_run() { let connection = &mut connection(); let query = crate::select(1.into_sql::()); @@ -367,7 +367,7 @@ mod tests_sqlite { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn sql_literal_nodes_are_not_cached() { let connection = &mut connection(); let query = crate::select(sql::("1")); @@ -376,7 +376,7 @@ mod tests_sqlite { assert_eq!(0, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_containing_sql_literal_nodes_are_not_cached() { let connection = &mut connection(); let one_as_expr = 1.into_sql::(); @@ -386,7 +386,7 @@ mod tests_sqlite { assert_eq!(0, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_containing_in_with_vec_are_not_cached() { let connection = &mut connection(); let one_as_expr = 1.into_sql::(); @@ -396,7 +396,7 @@ mod tests_sqlite { assert_eq!(0, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn queries_containing_in_with_subselect_are_cached() { let connection = &mut connection(); let one_as_expr = 1.into_sql::(); @@ -406,7 +406,7 @@ mod tests_sqlite { assert_eq!(1, count_cache_calls(connection)); } - #[test] + #[diesel_test_helper::test] fn disabling_the_cache_works() { let connection = &mut connection(); connection.set_prepared_statement_cache_size(CacheSize::Disabled); diff --git a/diesel/src/connection/transaction_manager.rs b/diesel/src/connection/transaction_manager.rs index b741e7a478c0..98d6c175f254 100644 --- a/diesel/src/connection/transaction_manager.rs +++ b/diesel/src/connection/transaction_manager.rs @@ -610,7 +610,7 @@ mod test { } } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn transaction_manager_returns_an_error_when_attempting_to_commit_outside_of_a_transaction() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -629,7 +629,7 @@ mod test { assert!(matches!(result, Err(Error::NotInTransaction))) } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn transaction_manager_returns_an_error_when_attempting_to_rollback_outside_of_a_transaction() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -648,7 +648,7 @@ mod test { assert!(matches!(result, Err(Error::NotInTransaction))) } - #[test] + #[diesel_test_helper::test] fn transaction_manager_enters_broken_state_when_connection_is_broken() { use crate::connection::transaction_manager::AnsiTransactionManager; use crate::connection::transaction_manager::TransactionManager; @@ -702,7 +702,7 @@ mod test { assert!(matches!(result, Err(Error::BrokenTransactionManager))) } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] fn mysql_transaction_is_rolled_back_upon_syntax_error() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -737,7 +737,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "sqlite")] fn sqlite_transaction_is_rolled_back_upon_syntax_error() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -772,7 +772,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] fn nested_mysql_transaction_is_rolled_back_upon_syntax_error() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -824,7 +824,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] // This function uses a collect with side effects (spawning threads) // so clippy is wrong here @@ -930,7 +930,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] // This function uses a collect with side effects (spawning threads) // so clippy is wrong here @@ -1038,7 +1038,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "sqlite")] fn sqlite_transaction_is_rolled_back_upon_deferred_constraint_failure() { use crate::connection::transaction_manager::AnsiTransactionManager; @@ -1079,7 +1079,7 @@ mod test { // regression test for #3470 // crates.io depends on this behaviour - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn some_libpq_failures_are_recoverable_by_rolling_back_the_savepoint_only() { use crate::connection::{AnsiTransactionManager, TransactionManager}; @@ -1128,7 +1128,7 @@ mod test { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn other_libpq_failures_are_not_recoverable_by_rolling_back_the_savepoint_only() { use crate::connection::{AnsiTransactionManager, TransactionManager}; diff --git a/diesel/src/lib.rs b/diesel/src/lib.rs index e866cf77a114..040f6f4e8a1f 100644 --- a/diesel/src/lib.rs +++ b/diesel/src/lib.rs @@ -268,6 +268,11 @@ #![deny(unsafe_code)] #![cfg_attr(test, allow(clippy::map_unwrap_or, clippy::unwrap_used))] +// Running wasm tests on dedicated_worker +#[cfg(test)] +#[cfg(all(target_family = "wasm", target_os = "unknown"))] +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker); + extern crate diesel_derives; #[macro_use] @@ -773,6 +778,12 @@ pub mod prelude { #[cfg(feature = "sqlite")] #[doc(inline)] pub use crate::sqlite::SqliteConnection; + + // These exported API from `sqlite-wasm-rs` are stable: + #[cfg(feature = "sqlite")] + #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[doc(inline)] + pub use sqlite_wasm_rs::export::init_sqlite; } #[doc(inline)] diff --git a/diesel/src/macros/mod.rs b/diesel/src/macros/mod.rs index 8290d0517398..bea638e67139 100644 --- a/diesel/src/macros/mod.rs +++ b/diesel/src/macros/mod.rs @@ -515,7 +515,7 @@ mod tests { } } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn table_with_custom_schema() { use crate::pg::Pg; @@ -556,7 +556,7 @@ mod tests { } ); - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn table_with_column_renaming_postgres() { use crate::pg::Pg; @@ -567,7 +567,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] fn table_with_column_renaming_mysql() { use crate::mysql::Mysql; @@ -578,7 +578,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "sqlite")] fn table_with_column_renaming_sqlite() { use crate::sqlite::Sqlite; @@ -600,7 +600,7 @@ mod tests { } ); - #[test] + #[diesel_test_helper::test] #[cfg(feature = "postgres")] fn table_renaming_postgres() { use crate::pg::Pg; @@ -611,7 +611,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "mysql")] fn table_renaming_mysql() { use crate::mysql::Mysql; @@ -622,7 +622,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] #[cfg(feature = "sqlite")] fn table_renaming_sqlite() { use crate::sqlite::Sqlite; diff --git a/diesel/src/mysql/connection/bind.rs b/diesel/src/mysql/connection/bind.rs index 991de7b7f2bb..0d8baba3e9fc 100644 --- a/diesel/src/mysql/connection/bind.rs +++ b/diesel/src/mysql/connection/bind.rs @@ -777,7 +777,7 @@ mod tests { } #[cfg(feature = "extras")] - #[test] + #[diesel_test_helper::test] fn check_all_the_types() { let conn = &mut crate::test_helpers::connection(); @@ -1310,7 +1310,7 @@ mod tests { } } - #[test] + #[diesel_test_helper::test] fn check_json_bind() { table! { json_test { @@ -1474,7 +1474,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn check_enum_bind() { let conn = &mut crate::test_helpers::connection(); @@ -1664,7 +1664,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn check_set_bind() { let conn = &mut crate::test_helpers::connection(); diff --git a/diesel/src/mysql/connection/mod.rs b/diesel/src/mysql/connection/mod.rs index d43c21ad2642..880f04aa525e 100644 --- a/diesel/src/mysql/connection/mod.rs +++ b/diesel/src/mysql/connection/mod.rs @@ -356,14 +356,14 @@ mod tests { MysqlConnection::establish(&database_url).unwrap() } - #[test] + #[diesel_test_helper::test] fn batch_execute_handles_single_queries_with_results() { let connection = &mut connection(); assert!(connection.batch_execute("SELECT 1").is_ok()); assert!(connection.batch_execute("SELECT 1").is_ok()); } - #[test] + #[diesel_test_helper::test] fn batch_execute_handles_multi_queries_with_results() { let connection = &mut connection(); let query = "SELECT 1; SELECT 2; SELECT 3;"; @@ -371,14 +371,14 @@ mod tests { assert!(connection.batch_execute(query).is_ok()); } - #[test] + #[diesel_test_helper::test] fn execute_handles_queries_which_return_results() { let connection = &mut connection(); assert!(crate::sql_query("SELECT 1").execute(connection).is_ok()); assert!(crate::sql_query("SELECT 1").execute(connection).is_ok()); } - #[test] + #[diesel_test_helper::test] fn check_client_found_rows_flag() { let conn = &mut crate::test_helpers::connection(); crate::sql_query("DROP TABLE IF EXISTS update_test CASCADE") diff --git a/diesel/src/mysql/connection/stmt/iterator.rs b/diesel/src/mysql/connection/stmt/iterator.rs index 79954db9203b..707abdf05d14 100644 --- a/diesel/src/mysql/connection/stmt/iterator.rs +++ b/diesel/src/mysql/connection/stmt/iterator.rs @@ -229,7 +229,8 @@ impl<'a> Field<'a, Mysql> for MysqlField<'a> { } } -#[test] +#[cfg(test)] +#[diesel_test_helper::test] #[allow(clippy::drop_non_drop)] // we want to explicitly extend lifetimes here fn fun_with_row_iters() { crate::table! { diff --git a/diesel/src/mysql/connection/url.rs b/diesel/src/mysql/connection/url.rs index 6ad11c4e4018..d77b8ebc3790 100644 --- a/diesel/src/mysql/connection/url.rs +++ b/diesel/src/mysql/connection/url.rs @@ -206,218 +206,223 @@ fn connection_url_error() -> ConnectionError { ConnectionError::InvalidConnectionUrl(msg.into()) } -#[test] -fn urls_with_schemes_other_than_mysql_are_errors() { - assert!(ConnectionOptions::parse("postgres://localhost").is_err()); - assert!(ConnectionOptions::parse("http://localhost").is_err()); - assert!(ConnectionOptions::parse("file:///tmp/mysql.sock").is_err()); - assert!(ConnectionOptions::parse("socket:///tmp/mysql.sock").is_err()); - assert!(ConnectionOptions::parse("mysql://localhost?database=somedb").is_err()); - assert!(ConnectionOptions::parse("mysql://localhost").is_ok()); -} - -#[test] -fn urls_must_have_zero_or_one_path_segments() { - assert!(ConnectionOptions::parse("mysql://localhost/foo/bar").is_err()); - assert!(ConnectionOptions::parse("mysql://localhost/foo").is_ok()); -} +#[cfg(test)] +mod tests { + use super::*; + + #[diesel_test_helper::test] + fn urls_with_schemes_other_than_mysql_are_errors() { + assert!(ConnectionOptions::parse("postgres://localhost").is_err()); + assert!(ConnectionOptions::parse("http://localhost").is_err()); + assert!(ConnectionOptions::parse("file:///tmp/mysql.sock").is_err()); + assert!(ConnectionOptions::parse("socket:///tmp/mysql.sock").is_err()); + assert!(ConnectionOptions::parse("mysql://localhost?database=somedb").is_err()); + assert!(ConnectionOptions::parse("mysql://localhost").is_ok()); + } -#[test] -fn first_path_segment_is_treated_as_database() { - let foo_cstr = CString::new("foo").unwrap(); - let bar_cstr = CString::new("bar").unwrap(); - assert_eq!( - Some(&*foo_cstr), - ConnectionOptions::parse("mysql://localhost/foo") - .unwrap() - .database() - ); - assert_eq!( - Some(&*bar_cstr), - ConnectionOptions::parse("mysql://localhost/bar") - .unwrap() - .database() - ); - assert_eq!( - None, - ConnectionOptions::parse("mysql://localhost") - .unwrap() - .database() - ); -} + #[diesel_test_helper::test] + fn urls_must_have_zero_or_one_path_segments() { + assert!(ConnectionOptions::parse("mysql://localhost/foo/bar").is_err()); + assert!(ConnectionOptions::parse("mysql://localhost/foo").is_ok()); + } -#[test] -fn userinfo_should_be_percent_decode() { - use self::percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; - const USERINFO_ENCODE_SET: &AsciiSet = &CONTROLS - .add(b' ') - .add(b'"') - .add(b'<') - .add(b'>') - .add(b'`') - .add(b'#') - .add(b'?') - .add(b'{') - .add(b'}') - .add(b'/') - .add(b':') - .add(b';') - .add(b'=') - .add(b'@') - .add(b'[') - .add(b'\\') - .add(b']') - .add(b'^') - .add(b'|'); - - let username = "x#gfuL?4Zuj{n73m}eeJt0"; - let encoded_username = utf8_percent_encode(username, USERINFO_ENCODE_SET); - - let password = "x/gfuL?4Zuj{n73m}eeJt1"; - let encoded_password = utf8_percent_encode(password, USERINFO_ENCODE_SET); - - let db_url = format!("mysql://{encoded_username}:{encoded_password}@localhost/bar",); - let db_url = Url::parse(&db_url).unwrap(); - - let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); - let username = CString::new(username.as_bytes()).unwrap(); - let password = CString::new(password.as_bytes()).unwrap(); - assert_eq!(username, conn_opts.user); - assert_eq!(password, conn_opts.password.unwrap()); -} + #[diesel_test_helper::test] + fn first_path_segment_is_treated_as_database() { + let foo_cstr = CString::new("foo").unwrap(); + let bar_cstr = CString::new("bar").unwrap(); + assert_eq!( + Some(&*foo_cstr), + ConnectionOptions::parse("mysql://localhost/foo") + .unwrap() + .database() + ); + assert_eq!( + Some(&*bar_cstr), + ConnectionOptions::parse("mysql://localhost/bar") + .unwrap() + .database() + ); + assert_eq!( + None, + ConnectionOptions::parse("mysql://localhost") + .unwrap() + .database() + ); + } -#[test] -fn ipv6_host_not_wrapped_in_brackets() { - let host1 = CString::new("::1").unwrap(); - let host2 = CString::new("2001:db8:85a3::8a2e:370:7334").unwrap(); + #[diesel_test_helper::test] + fn userinfo_should_be_percent_decode() { + use self::percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; + const USERINFO_ENCODE_SET: &AsciiSet = &CONTROLS + .add(b' ') + .add(b'"') + .add(b'<') + .add(b'>') + .add(b'`') + .add(b'#') + .add(b'?') + .add(b'{') + .add(b'}') + .add(b'/') + .add(b':') + .add(b';') + .add(b'=') + .add(b'@') + .add(b'[') + .add(b'\\') + .add(b']') + .add(b'^') + .add(b'|'); + + let username = "x#gfuL?4Zuj{n73m}eeJt0"; + let encoded_username = utf8_percent_encode(username, USERINFO_ENCODE_SET); + + let password = "x/gfuL?4Zuj{n73m}eeJt1"; + let encoded_password = utf8_percent_encode(password, USERINFO_ENCODE_SET); + + let db_url = format!("mysql://{encoded_username}:{encoded_password}@localhost/bar",); + let db_url = Url::parse(&db_url).unwrap(); + + let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); + let username = CString::new(username.as_bytes()).unwrap(); + let password = CString::new(password.as_bytes()).unwrap(); + assert_eq!(username, conn_opts.user); + assert_eq!(password, conn_opts.password.unwrap()); + } - assert_eq!( - Some(&*host1), - ConnectionOptions::parse("mysql://[::1]").unwrap().host() - ); - assert_eq!( - Some(&*host2), - ConnectionOptions::parse("mysql://[2001:db8:85a3::8a2e:370:7334]") - .unwrap() - .host() - ); -} + #[diesel_test_helper::test] + fn ipv6_host_not_wrapped_in_brackets() { + let host1 = CString::new("::1").unwrap(); + let host2 = CString::new("2001:db8:85a3::8a2e:370:7334").unwrap(); + + assert_eq!( + Some(&*host1), + ConnectionOptions::parse("mysql://[::1]").unwrap().host() + ); + assert_eq!( + Some(&*host2), + ConnectionOptions::parse("mysql://[2001:db8:85a3::8a2e:370:7334]") + .unwrap() + .host() + ); + } -#[test] -fn unix_socket_tests() { - let unix_socket = "/var/run/mysqld.sock"; - let username = "foo"; - let password = "bar"; - let db_url = format!("mysql://{username}:{password}@localhost?unix_socket={unix_socket}",); - let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); - let cstring = |s| CString::new(s).unwrap(); - assert_eq!(None, conn_opts.host); - assert_eq!(None, conn_opts.port); - assert_eq!(cstring(username), conn_opts.user); - assert_eq!(cstring(password), conn_opts.password.unwrap()); - assert_eq!( - CString::new(unix_socket).unwrap(), - conn_opts.unix_socket.unwrap() - ); -} + #[diesel_test_helper::test] + fn unix_socket_tests() { + let unix_socket = "/var/run/mysqld.sock"; + let username = "foo"; + let password = "bar"; + let db_url = format!("mysql://{username}:{password}@localhost?unix_socket={unix_socket}",); + let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); + let cstring = |s| CString::new(s).unwrap(); + assert_eq!(None, conn_opts.host); + assert_eq!(None, conn_opts.port); + assert_eq!(cstring(username), conn_opts.user); + assert_eq!(cstring(password), conn_opts.password.unwrap()); + assert_eq!( + CString::new(unix_socket).unwrap(), + conn_opts.unix_socket.unwrap() + ); + } -#[test] -fn ssl_ca_tests() { - let ssl_ca = "/etc/ssl/certs/ca-certificates.crt"; - let username = "foo"; - let password = "bar"; - let db_url = format!("mysql://{username}:{password}@localhost?ssl_ca={ssl_ca}",); - let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); - let cstring = |s| CString::new(s).unwrap(); - assert_eq!(Some(cstring("localhost")), conn_opts.host); - assert_eq!(None, conn_opts.port); - assert_eq!(cstring(username), conn_opts.user); - assert_eq!(cstring(password), conn_opts.password.unwrap()); - assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts.ssl_ca.unwrap()); - - let url_with_unix_str_and_ssl_ca = format!( + #[diesel_test_helper::test] + fn ssl_ca_tests() { + let ssl_ca = "/etc/ssl/certs/ca-certificates.crt"; + let username = "foo"; + let password = "bar"; + let db_url = format!("mysql://{username}:{password}@localhost?ssl_ca={ssl_ca}",); + let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); + let cstring = |s| CString::new(s).unwrap(); + assert_eq!(Some(cstring("localhost")), conn_opts.host); + assert_eq!(None, conn_opts.port); + assert_eq!(cstring(username), conn_opts.user); + assert_eq!(cstring(password), conn_opts.password.unwrap()); + assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts.ssl_ca.unwrap()); + + let url_with_unix_str_and_ssl_ca = format!( "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_ca={ssl_ca}" ); - let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_ca.as_str()).unwrap(); - assert_eq!(None, conn_opts2.host); - assert_eq!(None, conn_opts2.port); - assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts2.ssl_ca.unwrap()); -} + let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_ca.as_str()).unwrap(); + assert_eq!(None, conn_opts2.host); + assert_eq!(None, conn_opts2.port); + assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts2.ssl_ca.unwrap()); + } -#[test] -fn ssl_cert_tests() { - let ssl_cert = "/etc/ssl/certs/client-cert.crt"; - let username = "foo"; - let password = "bar"; - let db_url = format!("mysql://{username}:{password}@localhost?ssl_cert={ssl_cert}"); - let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); - let cstring = |s| CString::new(s).unwrap(); - assert_eq!(Some(cstring("localhost")), conn_opts.host); - assert_eq!(None, conn_opts.port); - assert_eq!(cstring(username), conn_opts.user); - assert_eq!(cstring(password), conn_opts.password.unwrap()); - assert_eq!(CString::new(ssl_cert).unwrap(), conn_opts.ssl_cert.unwrap()); - - let url_with_unix_str_and_ssl_cert = format!( + #[diesel_test_helper::test] + fn ssl_cert_tests() { + let ssl_cert = "/etc/ssl/certs/client-cert.crt"; + let username = "foo"; + let password = "bar"; + let db_url = format!("mysql://{username}:{password}@localhost?ssl_cert={ssl_cert}"); + let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); + let cstring = |s| CString::new(s).unwrap(); + assert_eq!(Some(cstring("localhost")), conn_opts.host); + assert_eq!(None, conn_opts.port); + assert_eq!(cstring(username), conn_opts.user); + assert_eq!(cstring(password), conn_opts.password.unwrap()); + assert_eq!(CString::new(ssl_cert).unwrap(), conn_opts.ssl_cert.unwrap()); + + let url_with_unix_str_and_ssl_cert = format!( "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_cert={ssl_cert}" ); - let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_cert.as_str()).unwrap(); - assert_eq!(None, conn_opts2.host); - assert_eq!(None, conn_opts2.port); - assert_eq!( - CString::new(ssl_cert).unwrap(), - conn_opts2.ssl_cert.unwrap() - ); -} + let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_cert.as_str()).unwrap(); + assert_eq!(None, conn_opts2.host); + assert_eq!(None, conn_opts2.port); + assert_eq!( + CString::new(ssl_cert).unwrap(), + conn_opts2.ssl_cert.unwrap() + ); + } -#[test] -fn ssl_key_tests() { - let ssl_key = "/etc/ssl/certs/client-key.crt"; - let username = "foo"; - let password = "bar"; - let db_url = format!("mysql://{username}:{password}@localhost?ssl_key={ssl_key}"); - let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); - let cstring = |s| CString::new(s).unwrap(); - assert_eq!(Some(cstring("localhost")), conn_opts.host); - assert_eq!(None, conn_opts.port); - assert_eq!(cstring(username), conn_opts.user); - assert_eq!(cstring(password), conn_opts.password.unwrap()); - assert_eq!(CString::new(ssl_key).unwrap(), conn_opts.ssl_key.unwrap()); - - let url_with_unix_str_and_ssl_key = format!( + #[diesel_test_helper::test] + fn ssl_key_tests() { + let ssl_key = "/etc/ssl/certs/client-key.crt"; + let username = "foo"; + let password = "bar"; + let db_url = format!("mysql://{username}:{password}@localhost?ssl_key={ssl_key}"); + let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap(); + let cstring = |s| CString::new(s).unwrap(); + assert_eq!(Some(cstring("localhost")), conn_opts.host); + assert_eq!(None, conn_opts.port); + assert_eq!(cstring(username), conn_opts.user); + assert_eq!(cstring(password), conn_opts.password.unwrap()); + assert_eq!(CString::new(ssl_key).unwrap(), conn_opts.ssl_key.unwrap()); + + let url_with_unix_str_and_ssl_key = format!( "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_key={ssl_key}" ); - let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_key.as_str()).unwrap(); - assert_eq!(None, conn_opts2.host); - assert_eq!(None, conn_opts2.port); - assert_eq!(CString::new(ssl_key).unwrap(), conn_opts2.ssl_key.unwrap()); -} + let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_key.as_str()).unwrap(); + assert_eq!(None, conn_opts2.host); + assert_eq!(None, conn_opts2.port); + assert_eq!(CString::new(ssl_key).unwrap(), conn_opts2.ssl_key.unwrap()); + } -#[test] -fn ssl_mode() { - let ssl_mode = |url| ConnectionOptions::parse(url).unwrap().ssl_mode(); - assert_eq!(ssl_mode("mysql://localhost"), None); - assert_eq!( - ssl_mode("mysql://localhost?ssl_mode=disabled"), - Some(mysql_ssl_mode::SSL_MODE_DISABLED) - ); - assert_eq!( - ssl_mode("mysql://localhost?ssl_mode=PREFERRED"), - Some(mysql_ssl_mode::SSL_MODE_PREFERRED) - ); - assert_eq!( - ssl_mode("mysql://localhost?ssl_mode=required"), - Some(mysql_ssl_mode::SSL_MODE_REQUIRED) - ); - assert_eq!( - ssl_mode("mysql://localhost?ssl_mode=VERIFY_CA"), - Some(mysql_ssl_mode::SSL_MODE_VERIFY_CA) - ); - assert_eq!( - ssl_mode("mysql://localhost?ssl_mode=verify_identity"), - Some(mysql_ssl_mode::SSL_MODE_VERIFY_IDENTITY) - ); + #[diesel_test_helper::test] + fn ssl_mode() { + let ssl_mode = |url| ConnectionOptions::parse(url).unwrap().ssl_mode(); + assert_eq!(ssl_mode("mysql://localhost"), None); + assert_eq!( + ssl_mode("mysql://localhost?ssl_mode=disabled"), + Some(mysql_ssl_mode::SSL_MODE_DISABLED) + ); + assert_eq!( + ssl_mode("mysql://localhost?ssl_mode=PREFERRED"), + Some(mysql_ssl_mode::SSL_MODE_PREFERRED) + ); + assert_eq!( + ssl_mode("mysql://localhost?ssl_mode=required"), + Some(mysql_ssl_mode::SSL_MODE_REQUIRED) + ); + assert_eq!( + ssl_mode("mysql://localhost?ssl_mode=VERIFY_CA"), + Some(mysql_ssl_mode::SSL_MODE_VERIFY_CA) + ); + assert_eq!( + ssl_mode("mysql://localhost?ssl_mode=verify_identity"), + Some(mysql_ssl_mode::SSL_MODE_VERIFY_IDENTITY) + ); + } } diff --git a/diesel/src/mysql/types/date_and_time/chrono.rs b/diesel/src/mysql/types/date_and_time/chrono.rs index 80f188f79ff6..1f3c259f9b19 100644 --- a/diesel/src/mysql/types/date_and_time/chrono.rs +++ b/diesel/src/mysql/types/date_and_time/chrono.rs @@ -136,7 +136,7 @@ mod tests { use crate::sql_types::{Date, Datetime, Time, Timestamp}; use crate::test_helpers::connection; - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly() { let connection = &mut connection(); let time = NaiveDate::from_ymd_opt(1970, 1, 1) @@ -149,7 +149,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly() { let connection = &mut connection(); let time = NaiveDate::from_ymd_opt(1970, 1, 1) @@ -164,7 +164,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn times_relative_to_now_encode_correctly() { let connection = &mut connection(); let time = Utc::now().naive_utc() + Duration::try_days(1).unwrap(); @@ -176,7 +176,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_encode_correctly() { let connection = &mut connection(); @@ -193,7 +193,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_decode_correctly() { let connection = &mut connection(); let midnight = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); @@ -212,7 +212,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn dates_encode_correctly() { let connection = &mut connection(); let january_first_2000 = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(); @@ -224,7 +224,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn dates_decode_correctly() { let connection = &mut connection(); let january_first_2000 = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(); diff --git a/diesel/src/mysql/types/date_and_time/time.rs b/diesel/src/mysql/types/date_and_time/time.rs index e4bec4c9a5f7..b3e9b0939b41 100644 --- a/diesel/src/mysql/types/date_and_time/time.rs +++ b/diesel/src/mysql/types/date_and_time/time.rs @@ -223,7 +223,7 @@ mod tests { use crate::sql_types::{Date, Datetime, Time, Timestamp}; use crate::test_helpers::connection; - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:0:0); @@ -233,7 +233,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:0:0); @@ -245,7 +245,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn times_relative_to_now_encode_correctly() { let connection = &mut connection(); let time = to_primitive_datetime(OffsetDateTime::now_utc()) + Duration::days(1); @@ -257,7 +257,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_encode_correctly() { let connection = &mut connection(); @@ -274,7 +274,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_decode_correctly() { let connection = &mut connection(); let midnight = time!(0:0:0); @@ -293,7 +293,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn dates_encode_correctly() { let connection = &mut connection(); let january_first_2000 = date!(2000 - 1 - 1); @@ -305,7 +305,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn dates_decode_correctly() { let connection = &mut connection(); let january_first_2000 = date!(2000 - 1 - 1); diff --git a/diesel/src/mysql/types/json.rs b/diesel/src/mysql/types/json.rs index 3be4a6b36405..efead3f5c2d3 100644 --- a/diesel/src/mysql/types/json.rs +++ b/diesel/src/mysql/types/json.rs @@ -19,43 +19,47 @@ impl ToSql for serde_json::Value { } } -#[test] -fn json_to_sql() { - use crate::query_builder::bind_collector::ByteWrapper; +#[cfg(test)] +mod tests { + use super::*; + #[diesel_test_helper::test] + fn json_to_sql() { + use crate::query_builder::bind_collector::ByteWrapper; - let mut buffer = Vec::new(); - let mut bytes = Output::test(ByteWrapper(&mut buffer)); - let test_json = serde_json::Value::Bool(true); - ToSql::::to_sql(&test_json, &mut bytes).unwrap(); - assert_eq!(buffer, b"true"); -} + let mut buffer = Vec::new(); + let mut bytes = Output::test(ByteWrapper(&mut buffer)); + let test_json = serde_json::Value::Bool(true); + ToSql::::to_sql(&test_json, &mut bytes).unwrap(); + assert_eq!(buffer, b"true"); + } -#[test] -fn some_json_from_sql() { - use crate::mysql::MysqlType; - let input_json = b"true"; - let output_json: serde_json::Value = FromSql::::from_sql( - MysqlValue::new_internal(input_json, MysqlType::String), - ) - .unwrap(); - assert_eq!(output_json, serde_json::Value::Bool(true)); -} + #[diesel_test_helper::test] + fn some_json_from_sql() { + use crate::mysql::MysqlType; + let input_json = b"true"; + let output_json: serde_json::Value = FromSql::::from_sql( + MysqlValue::new_internal(input_json, MysqlType::String), + ) + .unwrap(); + assert_eq!(output_json, serde_json::Value::Bool(true)); + } -#[test] -fn bad_json_from_sql() { - use crate::mysql::MysqlType; - let uuid: Result = FromSql::::from_sql( - MysqlValue::new_internal(b"boom", MysqlType::String), - ); - assert_eq!(uuid.unwrap_err().to_string(), "Invalid Json"); -} + #[diesel_test_helper::test] + fn bad_json_from_sql() { + use crate::mysql::MysqlType; + let uuid: Result = FromSql::::from_sql( + MysqlValue::new_internal(b"boom", MysqlType::String), + ); + assert_eq!(uuid.unwrap_err().to_string(), "Invalid Json"); + } -#[test] -fn no_json_from_sql() { - let uuid: Result = - FromSql::::from_nullable_sql(None); - assert_eq!( - uuid.unwrap_err().to_string(), - "Unexpected null for non-null column" - ); + #[diesel_test_helper::test] + fn no_json_from_sql() { + let uuid: Result = + FromSql::::from_nullable_sql(None); + assert_eq!( + uuid.unwrap_err().to_string(), + "Unexpected null for non-null column" + ); + } } diff --git a/diesel/src/pg/connection/cursor.rs b/diesel/src/pg/connection/cursor.rs index 01b50ea064e8..4fec4864aa20 100644 --- a/diesel/src/pg/connection/cursor.rs +++ b/diesel/src/pg/connection/cursor.rs @@ -151,7 +151,7 @@ mod tests { use crate::connection::DefaultLoadingMode; use crate::pg::PgRowByRowLoadingMode; - #[test] + #[diesel_test_helper::test] fn fun_with_row_iters() { crate::table! { #[allow(unused_parens)] @@ -264,7 +264,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn loading_modes_return_the_same_result() { use crate::prelude::*; @@ -308,7 +308,7 @@ mod tests { assert_eq!(users_by_default_mode, vec!["Sean", "Tess"]); } - #[test] + #[diesel_test_helper::test] fn fun_with_row_iters_row_by_row() { crate::table! { #[allow(unused_parens)] diff --git a/diesel/src/pg/connection/mod.rs b/diesel/src/pg/connection/mod.rs index 90ad676090b4..680b6a16246d 100644 --- a/diesel/src/pg/connection/mod.rs +++ b/diesel/src/pg/connection/mod.rs @@ -626,7 +626,7 @@ mod tests { crate::test_helpers::pg_connection_no_transaction() } - #[test] + #[diesel_test_helper::test] fn malformed_sql_query() { let connection = &mut connection(); let query = @@ -646,7 +646,7 @@ mod tests { } } - #[test] + #[diesel_test_helper::test] fn transaction_manager_returns_an_error_when_attempting_to_commit_outside_of_a_transaction() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::result::Error; @@ -663,7 +663,7 @@ mod tests { assert!(matches!(result, Err(Error::NotInTransaction))) } - #[test] + #[diesel_test_helper::test] fn transaction_manager_returns_an_error_when_attempting_to_rollback_outside_of_a_transaction() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::result::Error; @@ -680,7 +680,7 @@ mod tests { assert!(matches!(result, Err(Error::NotInTransaction))) } - #[test] + #[diesel_test_helper::test] fn postgres_transaction_is_rolled_back_upon_syntax_error() { use std::num::NonZeroU32; @@ -724,7 +724,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn nested_postgres_transaction_is_rolled_back_upon_syntax_error() { use std::num::NonZeroU32; @@ -784,7 +784,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] // This function uses collect with an side effect (spawning threads) // so this is a false positive from clippy #[allow(clippy::needless_collect)] @@ -891,7 +891,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] // This function uses collect with an side effect (spawning threads) // so this is a false positive from clippy #[allow(clippy::needless_collect)] @@ -1007,7 +1007,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn postgres_transaction_is_rolled_back_upon_deferred_constraint_failure() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::pg::connection::raw::PgTransactionStatus; @@ -1056,7 +1056,7 @@ mod tests { assert!(result.is_err()); } - #[test] + #[diesel_test_helper::test] fn postgres_transaction_is_rolled_back_upon_deferred_trigger_failure() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::pg::connection::raw::PgTransactionStatus; @@ -1131,7 +1131,7 @@ mod tests { assert!(result.is_err()); } - #[test] + #[diesel_test_helper::test] fn nested_postgres_transaction_is_rolled_back_upon_deferred_trigger_failure() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::pg::connection::raw::PgTransactionStatus; @@ -1213,7 +1213,7 @@ mod tests { assert!(result.is_ok(), "Expected success, got {:?}", result); } - #[test] + #[diesel_test_helper::test] fn nested_postgres_transaction_is_rolled_back_upon_deferred_constraint_failure() { use crate::connection::{AnsiTransactionManager, TransactionManager}; use crate::pg::connection::raw::PgTransactionStatus; diff --git a/diesel/src/pg/expression/extensions/interval_dsl.rs b/diesel/src/pg/expression/extensions/interval_dsl.rs index 0280266370ce..1bc20479657c 100644 --- a/diesel/src/pg/expression/extensions/interval_dsl.rs +++ b/diesel/src/pg/expression/extensions/interval_dsl.rs @@ -292,7 +292,7 @@ mod tests { }; } - #[test] + #[diesel_test_helper::test] fn intervals_match_pg_values_i32() { test_fn!(i32, test_microseconds, microseconds, i32::MAX); test_fn!(i32, test_milliseconds, milliseconds, i32::MAX); @@ -305,7 +305,7 @@ mod tests { test_fn!(i32, test_years, years, i32::MAX / 12); } - #[test] + #[diesel_test_helper::test] fn intervals_match_pg_values_i64() { // postgres does not really support intervals with more than i32::MAX microseconds // https://www.postgresql.org/message-id/20140126025049.GL9750@momjian.us @@ -320,7 +320,7 @@ mod tests { test_fn!(i64, test_years, years, (i32::MAX / 12) as i64); } - #[test] + #[diesel_test_helper::test] fn intervals_match_pg_values_f64() { const MAX_DIFF: i64 = 1_000_000; // postgres does not really support intervals with more than i32::MAX microseconds diff --git a/diesel/src/pg/query_builder/mod.rs b/diesel/src/pg/query_builder/mod.rs index bfe36b10eda2..ed775844c522 100644 --- a/diesel/src/pg/query_builder/mod.rs +++ b/diesel/src/pg/query_builder/mod.rs @@ -57,7 +57,8 @@ impl QueryBuilder for PgQueryBuilder { } } -#[test] +#[cfg(test)] +#[diesel_test_helper::test] fn check_sql_query_increments_bind_count() { use crate::query_builder::{AstPass, AstPassToSqlOptions, QueryFragment}; use crate::sql_types::*; diff --git a/diesel/src/pg/query_builder/tablesample.rs b/diesel/src/pg/query_builder/tablesample.rs index 6906db780b97..46618ce662d1 100644 --- a/diesel/src/pg/query_builder/tablesample.rs +++ b/diesel/src/pg/query_builder/tablesample.rs @@ -193,7 +193,7 @@ mod test { } } - #[test] + #[diesel_test_helper::test] fn test_generated_tablesample_sql() { assert_sql!( users::table.tablesample_bernoulli(10), diff --git a/diesel/src/pg/transaction.rs b/diesel/src/pg/transaction.rs index 700af018d276..2249e3771e5e 100644 --- a/diesel/src/pg/transaction.rs +++ b/diesel/src/pg/transaction.rs @@ -379,7 +379,8 @@ impl QueryFragment for Deferrable { } } -#[test] +#[cfg(test)] +#[diesel_test_helper::test] fn test_transaction_builder_generates_correct_sql() { extern crate dotenvy; diff --git a/diesel/src/pg/types/date_and_time/chrono.rs b/diesel/src/pg/types/date_and_time/chrono.rs index 34960ac227bd..2de887534f64 100644 --- a/diesel/src/pg/types/date_and_time/chrono.rs +++ b/diesel/src/pg/types/date_and_time/chrono.rs @@ -222,7 +222,7 @@ mod tests { use crate::sql_types::{Date, Interval, Time, Timestamp, Timestamptz}; use crate::test_helpers::connection; - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly() { let connection = &mut connection(); let time = NaiveDate::from_ymd_opt(1970, 1, 1) @@ -233,7 +233,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly_with_utc_timezone() { let connection = &mut connection(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).single().unwrap(); @@ -241,7 +241,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly_with_timezone() { let connection = &mut connection(); let time = FixedOffset::west_opt(3600) @@ -253,7 +253,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly() { let connection = &mut connection(); let time = NaiveDate::from_ymd_opt(1970, 1, 1) @@ -265,7 +265,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly_with_timezone() { let connection = &mut connection(); let time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).single().unwrap(); @@ -274,7 +274,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn times_relative_to_now_encode_correctly() { let connection = &mut connection(); let time = Utc::now().naive_utc() + Duration::try_seconds(60).unwrap(); @@ -286,7 +286,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_with_timezones_round_trip_after_conversion() { let connection = &mut connection(); let time = FixedOffset::east_opt(3600) @@ -301,7 +301,7 @@ mod tests { assert_eq!(Ok(expected), query.get_result(connection)); } - #[test] + #[diesel_test_helper::test] fn times_of_day_encode_correctly() { let connection = &mut connection(); @@ -318,7 +318,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_decode_correctly() { let connection = &mut connection(); let midnight = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); @@ -337,7 +337,7 @@ mod tests { ); } - #[test] + #[diesel_test_helper::test] fn dates_encode_correctly() { let connection = &mut connection(); let january_first_2000 = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(); @@ -365,7 +365,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn dates_decode_correctly() { let connection = &mut connection(); let january_first_2000 = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(); @@ -423,7 +423,7 @@ mod tests { ) } - #[test] + #[diesel_test_helper::test] fn duration_encode_correctly() { let connection = &mut connection(); let (duration, literal_strings) = get_test_duration_and_literal_strings(); @@ -433,7 +433,7 @@ mod tests { } } - #[test] + #[diesel_test_helper::test] fn duration_decode_correctly() { let connection = &mut connection(); let (duration, literal_strings) = get_test_duration_and_literal_strings(); diff --git a/diesel/src/pg/types/date_and_time/std_time.rs b/diesel/src/pg/types/date_and_time/std_time.rs index 90910f27e597..f5deeafb4baa 100644 --- a/diesel/src/pg/types/date_and_time/std_time.rs +++ b/diesel/src/pg/types/date_and_time/std_time.rs @@ -69,14 +69,14 @@ mod tests { use crate::sql_types::Timestamp; use crate::test_helpers::pg_connection; - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly() { let connection = &mut pg_connection(); let query = select(sql::("'1970-01-01'").eq(UNIX_EPOCH)); assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly() { let connection = &mut pg_connection(); let epoch_from_sql = select(sql::("'1970-01-01'::timestamp")) @@ -84,7 +84,7 @@ mod tests { assert_eq!(Ok(UNIX_EPOCH), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn times_relative_to_now_encode_correctly() { let connection = &mut pg_connection(); let time = SystemTime::now() + Duration::from_secs(60); diff --git a/diesel/src/pg/types/date_and_time/time.rs b/diesel/src/pg/types/date_and_time/time.rs index eca92d901a5d..25f054b4ed65 100644 --- a/diesel/src/pg/types/date_and_time/time.rs +++ b/diesel/src/pg/types/date_and_time/time.rs @@ -160,7 +160,7 @@ mod tests { PrimitiveDateTime::new(offset_now.date(), offset_now.time()) } - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:00:00); @@ -168,7 +168,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly_with_utc_timezone() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:00:00 utc); @@ -176,7 +176,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_encodes_correctly_with_timezone() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:00:00 -1:00); @@ -184,7 +184,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:0:0); @@ -193,7 +193,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn unix_epoch_decodes_correctly_with_timezone() { let connection = &mut connection(); let time = datetime!(1970-1-1 0:00:00 utc); @@ -202,7 +202,7 @@ mod tests { assert_eq!(Ok(time), epoch_from_sql); } - #[test] + #[diesel_test_helper::test] fn times_relative_to_now_encode_correctly() { let connection = &mut connection(); let time = naive_now() + Duration::seconds(60); @@ -214,7 +214,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_with_timezones_round_trip_after_conversion() { let connection = &mut connection(); let time = datetime!(2016-1-2 1:00:00 +1); @@ -223,7 +223,7 @@ mod tests { assert_eq!(Ok(expected), query.get_result(connection)); } - #[test] + #[diesel_test_helper::test] fn times_of_day_encode_correctly() { let connection = &mut connection(); @@ -240,7 +240,7 @@ mod tests { assert!(query.get_result::(connection).unwrap()); } - #[test] + #[diesel_test_helper::test] fn times_of_day_decode_correctly() { let connection = &mut connection(); let query = select(sql::