Make tests return Result

This commit is contained in:
gwenn
2020-11-05 22:14:00 +01:00
parent 65c38bf813
commit da94f8eba6
30 changed files with 1040 additions and 1179 deletions

View File

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