enhanced_output/
enhanced_output.rs1use fluent_test::prelude::*;
2
3fn main() {
4 println!("FluentTest Enhanced Output Example\n");
5
6 config().enhanced_output(true).apply();
8
9 println!("Running assertions with enhanced output enabled:");
11
12 let number = 42;
14 print_result("expect!(number).to_be_even()", || {
15 expect!(number).to_be_even().evaluate()
17 });
18
19 print_result("expect!(number).to_be_greater_than(30).and().to_be_less_than(50)", || {
20 expect!(number).to_be_greater_than(30).and().to_be_less_than(50).evaluate()
21 });
22
23 let result = std::panic::catch_unwind(|| {
25 expect!(number).to_be_greater_than(100);
26 });
27 match result {
28 Ok(_) => println!("\nš expect!(number).to_be_greater_than(100)\n ā Failed but did not panic"),
29 Err(e) => {
30 if let Some(s) = e.downcast_ref::<String>() {
31 println!("\nš expect!(number).to_be_greater_than(100)\n ā Failed with: {}", s);
32 } else {
33 println!("\nš expect!(number).to_be_greater_than(100)\n ā Failed with panic");
34 }
35 }
36 }
37
38 let text = "Hello, world!";
40 print_result("expect!(text).to_contain(\"world\")", || expect!(text).to_contain("world").evaluate());
41
42 let items = vec![1, 2, 3, 4, 5];
44 print_result("expect!(items.as_slice()).to_have_length(5)", || expect!(items.as_slice()).to_have_length(5).evaluate());
45
46 println!("\nNOTE: Without enhanced output enabled (the default), these assertions would");
47 println!(" produce standard Rust assertion messages instead of the detailed ones shown above.");
48 println!("\nUse config().enhanced_output(true).apply() to enable enhanced output in your code,");
49 println!("or set the FLUENT_TEST_ENHANCED_OUTPUT=true environment variable.");
50}
51
52fn print_result<F>(desc: &str, f: F)
54where
55 F: FnOnce() -> bool,
56{
57 println!("\nš {}", desc);
58 match f() {
59 true => println!(" ā
Passed"),
60 false => println!(" ā Failed (but did not panic)"),
61 }
62}