mirror of
https://github.com/isar/rusqlite.git
synced 2025-11-03 23:48:56 +08:00
Make tests return Result
This commit is contained in:
16
src/trace.rs
16
src/trace.rs
@@ -128,10 +128,10 @@ mod test {
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::Connection;
|
||||
use crate::{Connection, Result};
|
||||
|
||||
#[test]
|
||||
fn test_trace() {
|
||||
fn test_trace() -> Result<()> {
|
||||
lazy_static! {
|
||||
static ref TRACED_STMTS: Mutex<Vec<String>> = Mutex::new(Vec::new());
|
||||
}
|
||||
@@ -140,7 +140,7 @@ mod test {
|
||||
traced_stmts.push(s.to_owned());
|
||||
}
|
||||
|
||||
let mut db = Connection::open_in_memory().unwrap();
|
||||
let mut db = Connection::open_in_memory()?;
|
||||
db.trace(Some(tracer));
|
||||
{
|
||||
let _ = db.query_row("SELECT ?", &[&1i32], |_| Ok(()));
|
||||
@@ -156,10 +156,11 @@ mod test {
|
||||
assert_eq!(traced_stmts.len(), 2);
|
||||
assert_eq!(traced_stmts[0], "SELECT 1");
|
||||
assert_eq!(traced_stmts[1], "SELECT 'hello'");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_profile() {
|
||||
fn test_profile() -> Result<()> {
|
||||
lazy_static! {
|
||||
static ref PROFILED: Mutex<Vec<(String, Duration)>> = Mutex::new(Vec::new());
|
||||
}
|
||||
@@ -168,14 +169,15 @@ mod test {
|
||||
profiled.push((s.to_owned(), d));
|
||||
}
|
||||
|
||||
let mut db = Connection::open_in_memory().unwrap();
|
||||
let mut db = Connection::open_in_memory()?;
|
||||
db.profile(Some(profiler));
|
||||
db.execute_batch("PRAGMA application_id = 1").unwrap();
|
||||
db.execute_batch("PRAGMA application_id = 1")?;
|
||||
db.profile(None);
|
||||
db.execute_batch("PRAGMA application_id = 2").unwrap();
|
||||
db.execute_batch("PRAGMA application_id = 2")?;
|
||||
|
||||
let profiled = PROFILED.lock().unwrap();
|
||||
assert_eq!(profiled.len(), 1);
|
||||
assert_eq!(profiled[0].0, "PRAGMA application_id = 1");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user