Commit c0bef80b authored by Hero Bird's avatar Hero Bird
Browse files

[pdsl_core] Add test_utils helper library

This will help writing tests with general setup and tear-down mechanics.
Used to initialize env_logger for every unit test.
parent ffb89422
......@@ -23,6 +23,9 @@ parity-codec-derive = { version = "2.0" }
tiny-keccak = "1.4"
log = "0.4"
[dev-dependencies]
env_logger = { version = "0.6", default-features = false }
[features]
default = []
test-env = []
......@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with pDSL. If not, see <http://www.gnu.org/licenses/>.
#[cfg(test)]
#[macro_use]
mod test_utils;
mod byte_utils;
pub mod env;
pub mod hash;
......
//! The minimal test framework for the pdsl core libraries.
/// The set-up procedure of the entire crate under test.
fn setup() {
let _ = env_logger::try_init();
}
/// The tear-down procedure of the entire crate under test.
fn teardown() {}
/// Runs the given test.
///
/// This executes general setup routines before executing
/// the test and general tear-down procedures after executing.
pub(crate) fn run_test<F>(test: F) -> ()
where F: FnOnce() -> () + std::panic::UnwindSafe
{
setup();
let result = std::panic::catch_unwind(|| {
test()
});
teardown();
assert!(result.is_ok())
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment