pub fn expect<T>(actual: T) -> Expectation<T>Examples found in repository?
examples/example_smoke.rs (line 10)
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 10)
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 14)
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}