mirror of
https://github.com/isar/rusqlite.git
synced 2025-01-19 18:40:52 +08:00
Fix non-bundled tests against macOS system SQLite
This commit is contained in:
parent
f8b9ad8907
commit
9699b4a210
23
src/lib.rs
23
src/lib.rs
@ -1515,15 +1515,28 @@ mod test {
|
||||
#[test]
|
||||
fn test_pragma_query_row() -> Result<()> {
|
||||
let db = Connection::open_in_memory()?;
|
||||
|
||||
assert_eq!(
|
||||
"memory",
|
||||
db.query_row::<String, _, _>("PRAGMA journal_mode", [], |r| r.get(0))?
|
||||
);
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?
|
||||
);
|
||||
let mode = db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?;
|
||||
if cfg!(features = "bundled") {
|
||||
assert_eq!(mode, "off");
|
||||
} else {
|
||||
// Note: system SQLite on macOS defaults to "off" rather than
|
||||
// "memory" for the journal mode (which cannot be changed for
|
||||
// in-memory connections). This seems like it's *probably* legal
|
||||
// according to the docs below, so we relax this test when not
|
||||
// bundling:
|
||||
//
|
||||
// From https://www.sqlite.org/pragma.html#pragma_journal_mode
|
||||
// > Note that the journal_mode for an in-memory database is either
|
||||
// > MEMORY or OFF and can not be changed to a different value. An
|
||||
// > attempt to change the journal_mode of an in-memory database to
|
||||
// > any setting other than MEMORY or OFF is ignored.
|
||||
assert!(mode == "memory" || mode == "off", "Got mode {:?}", mode);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -406,18 +406,20 @@ mod test {
|
||||
let db = Connection::open_in_memory()?;
|
||||
let journal_mode: String =
|
||||
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
|
||||
assert_eq!("off", &journal_mode);
|
||||
assert!(
|
||||
journal_mode == "off" || journal_mode == "memory",
|
||||
"mode: {:?}",
|
||||
journal_mode,
|
||||
);
|
||||
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row
|
||||
.get::<_, String>(0))?,
|
||||
);
|
||||
let mode = db
|
||||
.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
|
||||
let param: &dyn crate::ToSql = &"OFF";
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?,
|
||||
);
|
||||
let mode =
|
||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,16 @@ use rusqlite::ffi;
|
||||
use rusqlite::Connection;
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_error_when_singlethread_mode() {
|
||||
// put SQLite into single-threaded mode
|
||||
unsafe {
|
||||
// Note: macOS system SQLite seems to return an error if you attempt to
|
||||
// reconfigure to single-threaded mode.
|
||||
if ffi::sqlite3_config(ffi::SQLITE_CONFIG_SINGLETHREAD) != ffi::SQLITE_OK {
|
||||
return;
|
||||
}
|
||||
if ffi::sqlite3_initialize() != ffi::SQLITE_OK {
|
||||
return;
|
||||
}
|
||||
assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK);
|
||||
}
|
||||
|
||||
let _ = Connection::open_in_memory().unwrap();
|
||||
let res = Connection::open_in_memory();
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user