diff --git a/Cargo.lock b/Cargo.lock index 7891a9cf..02d04019 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 8640e2c2..efedeb12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,8 @@ members = [ "server", "libtdb", "tdb-bench", - "tdb-derive" + "tdb-derive", + "testsuite" ] [profile.release] diff --git a/tdb-bench/Cargo.toml b/tdb-bench/Cargo.toml index 44e5e0db..7bd4e036 100644 --- a/tdb-bench/Cargo.toml +++ b/tdb-bench/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tdb-bench" version = "0.1.0" -authors = ["Sayan Nandan "] +authors = ["Sayan Nandan "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tdb-derive/Cargo.toml b/tdb-derive/Cargo.toml index c57f89cd..464bfa3f 100644 --- a/tdb-derive/Cargo.toml +++ b/tdb-derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tdb-derive" version = "0.1.0" -authors = ["Sayan Nandan "] +authors = ["Sayan Nandan "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tdb-derive/src/lib.rs b/tdb-derive/src/lib.rs index d4e02516..9b644222 100644 --- a/tdb-derive/src/lib.rs +++ b/tdb-derive/src/lib.rs @@ -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 { #header #(#attrs)* #vis #sig { - let runtime = service::BackGroundTask::new(); + let runtime = testsuite::service::BackGroundTask::new(); runtime.execute(|| {#body}); drop(runtime); } diff --git a/testsuite/Cargo.toml b/testsuite/Cargo.toml new file mode 100644 index 00000000..9e054c3d --- /dev/null +++ b/testsuite/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "testsuite" +version = "0.1.0" +authors = ["Sayan Nandan "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tdb-derive = {path="../tdb-derive"} \ No newline at end of file diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs new file mode 100644 index 00000000..b312b42d --- /dev/null +++ b/testsuite/src/lib.rs @@ -0,0 +1,27 @@ +/* + * Created on Mon Sep 14 2020 + * + * This file is a part of TerrabaseDB + * Copyright (c) 2020, Sayan Nandan + * + * 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 . + * +*/ + +//! TerrabaseDB's testing suite +//! +//! This crate contains modules which are used for testing TerrabaseDB + +pub mod service; +pub use tdb_derive; diff --git a/testsuite/src/service.rs b/testsuite/src/service.rs new file mode 100644 index 00000000..b6f0b650 --- /dev/null +++ b/testsuite/src/service.rs @@ -0,0 +1,56 @@ +/* + * Created on Sun Sep 13 2020 + * + * This file is a part of TerrabaseDB + * Copyright (c) 2020, Sayan Nandan + * + * 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 . + * +*/ + +//! 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(); + } +}