Add testing suite

The `testsuite` crate is a library which contains testing utils.
`testsuite` re-exports tdb-derive for ease of use.
next
Sayan Nandan 4 years ago
parent 0b901b0492
commit f2b040e578
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

8
Cargo.lock generated

@ -588,7 +588,6 @@ dependencies = [
"devtimer",
"libtdb",
"rand",
"tdb-derive",
]
[[package]]
@ -608,6 +607,13 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "testsuite"
version = "0.1.0"
dependencies = [
"tdb-derive",
]
[[package]]
name = "textwrap"
version = "0.11.0"

@ -4,7 +4,8 @@ members = [
"server",
"libtdb",
"tdb-bench",
"tdb-derive"
"tdb-derive",
"testsuite"
]
[profile.release]

@ -1,7 +1,7 @@
[package]
name = "tdb-bench"
version = "0.1.0"
authors = ["Sayan Nandan <nandansayan@outlook.com>"]
authors = ["Sayan Nandan <ohsayan@outlook.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,7 @@
[package]
name = "tdb-derive"
version = "0.1.0"
authors = ["Sayan Nandan <nandansayan@outlook.com>"]
authors = ["Sayan Nandan <ohsayan@outlook.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -19,6 +19,8 @@
*
*/
//! A library containing a collection of custom derives used by TerrabaseDB
use proc_macro::TokenStream;
use quote::quote;
use syn;
@ -35,7 +37,7 @@ fn parse_toks(mut input: syn::ItemFn) -> Result<TokenStream, syn::Error> {
#header
#(#attrs)*
#vis #sig {
let runtime = service::BackGroundTask::new();
let runtime = testsuite::service::BackGroundTask::new();
runtime.execute(|| {#body});
drop(runtime);
}

@ -0,0 +1,10 @@
[package]
name = "testsuite"
version = "0.1.0"
authors = ["Sayan Nandan <ohsayan@outlook.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tdb-derive = {path="../tdb-derive"}

@ -0,0 +1,27 @@
/*
* Created on Mon Sep 14 2020
*
* This file is a part of TerrabaseDB
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
//! TerrabaseDB's testing suite
//!
//! This crate contains modules which are used for testing TerrabaseDB
pub mod service;
pub use tdb_derive;

@ -0,0 +1,56 @@
/*
* Created on Sun Sep 13 2020
*
* This file is a part of TerrabaseDB
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
//! Objects for handling background services
//!
use std::path;
use std::process;
/// A `BackgroundTask` starts `tdb` in a background
pub struct BackGroundTask {
child: process::Child,
}
impl BackGroundTask {
/// Start a new background database server
///
/// **Note**: This function expects that you're running it from the workspace
/// root. It is **test-only**, and this must be kept in mind.
pub fn new() -> Self {
if !path::Path::new("../target/debug/tdb").exists() {
panic!("The `tdb` binary could not be found");
}
let cmd = process::Command::new("../target/debug/tdb")
.spawn()
.unwrap();
BackGroundTask { child: cmd }
}
/// Execute a function block
pub fn execute(&self, body: fn() -> ()) {
body()
}
}
impl Drop for BackGroundTask {
fn drop(&mut self) {
// Terminate the background server
self.child.kill().unwrap();
}
}
Loading…
Cancel
Save