MCPcopy Create free account
hub / github.com/hashintel/hash / ensure

Function ensure

libs/error-stack/tests/test_macros.rs:34–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32
33#[test]
34fn ensure() {
35 capture_ok(|| {
36 ensure!(true, RootError);
37 Ok(())
38 });
39 let report = capture_error(|| {
40 ensure!(false, RootError);
41 Ok(())
42 })
43 .attach(PrintableA(0));
44 assert!(report.contains::<RootError>());
45 assert!(report.contains::<PrintableA>());
46 assert!(!report.contains::<PrintableB>());
47 assert_eq!(report.current_context(), &RootError);
48 assert_eq!(report.frames().count(), expect_count(2));
49 assert_eq!(
50 remove_builtin_messages(messages(&report)),
51 remove_builtin_messages(["printable A", "root error"])
52 );
53
54 let report = capture_error(|| {
55 ensure!(false, report);
56 Ok(())
57 })
58 .attach(PrintableB(0));
59 assert!(report.contains::<RootError>());
60 assert!(report.contains::<PrintableA>());
61 assert!(report.contains::<PrintableB>());
62 assert_eq!(report.current_context(), &RootError);
63 assert_eq!(report.frames().count(), expect_count(3));
64 assert_eq!(
65 remove_builtin_messages(messages(&report)),
66 remove_builtin_messages(["printable B", "printable A", "root error"])
67 );
68}

Callers

nothing calls this directly

Calls 6

capture_okFunction · 0.85
OkInterface · 0.85
capture_errorFunction · 0.85
PrintableAClass · 0.85
PrintableBClass · 0.85
attachMethod · 0.45

Tested by

no test coverage detected