pub struct TestContext { /* private fields */ }Implementations§
Source§impl TestContext
impl TestContext
pub fn new() -> Self
Sourcepub fn stdout<S>(&mut self, value: S)
pub fn stdout<S>(&mut self, value: S)
Examples found in repository?
examples/example_smoke.rs (line 9)
5fn main() {
6 let tests = collect_tests(|| {
7 describe!("math", {
8 test!("adds two numbers", |ctx| {
9 ctx.stdout("ok\n");
10 expect(2 + 3).to_be(5);
11 });
12
13 test!("handles negatives", id = "math/handles-negatives", |ctx| {
14 assert!(ctx.observe().metric("wall_time_ns", 42.0));
15 expect(-2 + 1).to_be(-1);
16 });
17 });
18 })
19 .expect("collection should validate");
20
21 for test in &tests {
22 let outcome = run_test(test);
23 println!("{} => {}", test.canonical_name(), outcome.exit);
24 }
25}More examples
examples/host_example.rs (line 9)
5fn main() {
6 let tests = collect_tests(|| {
7 describe!("pkg", {
8 test!("smoke test", id = "pkg::smoke", |ctx| {
9 ctx.stdout("ok\n");
10 expect(true).to_be_truthy();
11 });
12
13 test!("failing test", id = "pkg::fail", |ctx| {
14 ctx.stderr("failure\n");
15 ctx.set_exit(1);
16 });
17 });
18 })
19 .expect("collection should validate");
20
21 let exit_code = match observer_host_main("rust", &tests) {
22 Ok(()) => 0,
23 Err(error) => {
24 eprintln!("{error}");
25 2
26 }
27 };
28 std::process::exit(exit_code);
29}examples/host_embed_example.rs (line 13)
9fn main() {
10 let tests = collect_tests(|| {
11 describe!("pkg", {
12 test!("embedded smoke test", id = "pkg::embedded-smoke", |ctx| {
13 ctx.stdout("ok\n");
14 expect(true).to_be_truthy();
15 });
16 });
17 })
18 .expect("collection should validate");
19
20 let args = std::env::args().collect::<Vec<_>>();
21 if args.get(1).map(String::as_str) == Some("observe") {
22 let exit_code = match observer_host_dispatch_embedded("rust", "observe", &tests, args) {
23 Ok(()) => 0,
24 Err(error) => {
25 eprintln!("{error}");
26 2
27 }
28 };
29 std::process::exit(exit_code);
30 }
31
32 app_main(&args);
33}Sourcepub fn stderr<S>(&mut self, value: S)
pub fn stderr<S>(&mut self, value: S)
Examples found in repository?
examples/host_example.rs (line 14)
5fn main() {
6 let tests = collect_tests(|| {
7 describe!("pkg", {
8 test!("smoke test", id = "pkg::smoke", |ctx| {
9 ctx.stdout("ok\n");
10 expect(true).to_be_truthy();
11 });
12
13 test!("failing test", id = "pkg::fail", |ctx| {
14 ctx.stderr("failure\n");
15 ctx.set_exit(1);
16 });
17 });
18 })
19 .expect("collection should validate");
20
21 let exit_code = match observer_host_main("rust", &tests) {
22 Ok(()) => 0,
23 Err(error) => {
24 eprintln!("{error}");
25 2
26 }
27 };
28 std::process::exit(exit_code);
29}Sourcepub fn set_exit(&mut self, exit: i32)
pub fn set_exit(&mut self, exit: i32)
Examples found in repository?
examples/host_example.rs (line 15)
5fn main() {
6 let tests = collect_tests(|| {
7 describe!("pkg", {
8 test!("smoke test", id = "pkg::smoke", |ctx| {
9 ctx.stdout("ok\n");
10 expect(true).to_be_truthy();
11 });
12
13 test!("failing test", id = "pkg::fail", |ctx| {
14 ctx.stderr("failure\n");
15 ctx.set_exit(1);
16 });
17 });
18 })
19 .expect("collection should validate");
20
21 let exit_code = match observer_host_main("rust", &tests) {
22 Ok(()) => 0,
23 Err(error) => {
24 eprintln!("{error}");
25 2
26 }
27 };
28 std::process::exit(exit_code);
29}pub fn fail(&mut self, message: &str)
Sourcepub fn observe(&mut self) -> Observe<'_>
pub fn observe(&mut self) -> Observe<'_>
Examples found in repository?
examples/example_smoke.rs (line 14)
5fn main() {
6 let tests = collect_tests(|| {
7 describe!("math", {
8 test!("adds two numbers", |ctx| {
9 ctx.stdout("ok\n");
10 expect(2 + 3).to_be(5);
11 });
12
13 test!("handles negatives", id = "math/handles-negatives", |ctx| {
14 assert!(ctx.observe().metric("wall_time_ns", 42.0));
15 expect(-2 + 1).to_be(-1);
16 });
17 });
18 })
19 .expect("collection should validate");
20
21 for test in &tests {
22 let outcome = run_test(test);
23 println!("{} => {}", test.canonical_name(), outcome.exit);
24 }
25}pub fn as_raw_mut(&mut self) -> &mut TestContext
pub fn finish(self) -> TestOutcome
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TestContext
impl RefUnwindSafe for TestContext
impl Send for TestContext
impl Sync for TestContext
impl Unpin for TestContext
impl UnsafeUnpin for TestContext
impl UnwindSafe for TestContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more