Move a test from /tests to /src

This commit is contained in:
Ivan Ukhov 2015-06-08 09:37:44 -04:00
parent a8396a0d1e
commit 1f0db50312
3 changed files with 38 additions and 10 deletions

View File

@ -113,3 +113,23 @@ extern fn execute_callback(callback: *mut c_void, count: c_int, values: *mut *mu
if callback(pairs) { 0 } else { 1 }
}
}
#[cfg(test)]
mod tests {
use super::Database;
use tests::setup;
macro_rules! ok(
($result:expr) => ($result.unwrap());
);
#[test]
fn execute() {
let (path, _directory) = setup();
let database = ok!(Database::open(&path));
match database.execute(":)", None) {
Err(error) => assert_eq!(error.message, Some(String::from(r#"unrecognized token: ":""#))),
_ => assert!(false),
}
}
}

View File

@ -3,6 +3,9 @@
extern crate libc;
extern crate sqlite3_sys as raw;
#[cfg(test)]
extern crate temporary;
macro_rules! raise(
($message:expr) => (return Err(::Error::from($message)));
);
@ -68,3 +71,18 @@ pub use statement::{Statement, Binding, Value};
pub fn open(path: &std::path::Path) -> Result<Database> {
Database::open(path)
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use temporary::Directory;
macro_rules! ok(
($result:expr) => ($result.unwrap());
);
pub fn setup() -> (PathBuf, Directory) {
let directory = ok!(Directory::new("sqlite"));
(directory.path().join("database.sqlite3"), directory)
}
}

View File

@ -55,16 +55,6 @@ fn workflow() {
}
}
#[test]
fn failure() {
let (path, _directory) = setup();
let database = ok!(sqlite::open(&path));
match database.execute(":)", None) {
Err(error) => assert_eq!(error.message, Some(String::from(r#"unrecognized token: ":""#))),
_ => assert!(false),
}
}
fn setup() -> (PathBuf, Directory) {
let directory = ok!(Directory::new("sqlite"));
(directory.path().join("database.sqlite3"), directory)