rspec/lib.rs
1#![doc(html_root_url = "https://mackwic.github.io/rspec")]
2#![cfg_attr(feature = "clippy", feature(plugin))]
3#![cfg_attr(feature = "clippy", plugin(clippy))]
4#![allow(dead_code)]
5
6#[macro_use]
7extern crate derive_builder;
8
9#[macro_use]
10extern crate derive_new;
11
12extern crate colored;
13#[cfg(feature = "expectest_compat")]
14extern crate expectest;
15extern crate rayon;
16extern crate time;
17
18pub mod block;
19pub mod header;
20pub mod logger;
21pub mod report;
22pub mod runner;
23
24mod visitor;
25
26pub use block::{describe, given, suite};
27pub use logger::Logger;
28pub use runner::{Configuration, ConfigurationBuilder, Runner};
29
30use block::Suite;
31
32/// A wrapper for conveniently running a test suite with
33/// the default configuration with considerebly less glue-code.
34///
35/// # Examples
36///
37/// ```
38/// # extern crate rspec;
39/// #
40/// # pub fn main() {
41/// rspec::run(&rspec::given("a scenario", (), |ctx| {
42/// ctx.when("...", |ctx| {
43/// // ...
44/// });
45///
46/// ctx.then("...", |env| { /* ... */ });
47/// }));
48/// # }
49/// ```
50pub fn run<T>(suite: &Suite<T>)
51where
52 T: Clone + Send + Sync + ::std::fmt::Debug,
53{
54 use std::io;
55 use std::sync::Arc;
56
57 let logger = Arc::new(Logger::new(io::stdout()));
58 let configuration = ConfigurationBuilder::default().build().unwrap();
59 let runner = Runner::new(configuration, vec![logger]);
60
61 runner.run(suite);
62}
63
64#[cfg(test)]
65mod tests {
66
67 pub use super::*;
68 pub use block::*;
69
70 // Test list:
71 // x check that tests can call `assert_eq!`
72 // x check that tests can return Err or Ok
73 // x runner can count the tests
74 // x runner can count the success and failed
75 // x check that we can use before in a describe
76 // x check that we can use after in a describe
77 // x check that after/before are run in all child contextes
78 // x runner broadcasts run events
79 // x progress logger is an event handler
80 // x pluggable loggers via logger trait
81 // - stats time events is an event handler
82 // - detect slow tests via treshold
83 // x time the total running time
84 // - failure-only via a tmp file
85 // - filter tests
86 // - coloration
87 // - seed for deterministic randomization
88 // - fail-fast fail at the first failed test
89 // x beforeAll
90 // x afterAll
91 // x beforeEach
92 // x afterEach
93 // - use Any to return anything that can be Ok-ed or () or None or panic-ed
94 // - bench ? --> see what's the protocol
95 //
96}