Debian Codegraph @

tests/test_macros.rs

raw symbols SCIP
1 #![allow(
2 clippy::assertions_on_result_states,
3 clippy::eq_op,
4 clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257
5 clippy::items_after_statements,
6 clippy::match_single_binding,
7 clippy::needless_pass_by_value,
8 clippy::shadow_unrelated,
9 clippy::uninlined_format_args,
10 clippy::wildcard_imports
11 )]
12
13 mod commonrust-analyzer cargo anyhow 1.0.103 common/;
14
15 use selfrust-analyzer cargo anyhow 1.0.103 crate/::commonrust-analyzer cargo anyhow 1.0.103 common/::*;
16 use anyhowrust-analyzer cargo anyhow 1.0.103 crate/::{anyhowrust-analyzer cargo anyhow 1.0.103 macros/anyhow!, ensurerust-analyzer cargo anyhow 1.0.103 ensure/, Resultrust-analyzer cargo anyhow 1.0.103 Result#};
17 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#;
18 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/;
19
20 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
21 fn test_messagesrust-analyzer cargo anyhow 1.0.103 test_messages().() {
22 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("oh no!", bail_literalrust-analyzer cargo anyhow 1.0.103 common/bail_literal().().unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
23 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("oh no!", bail_fmtrust-analyzer cargo anyhow 1.0.103 common/bail_fmt().().unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
24 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("oh no!", bail_errorrust-analyzer cargo anyhow 1.0.103 common/bail_error().().unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
25 }
26
27 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
28 fn test_ensurerust-analyzer cargo anyhow 1.0.103 test_ensure().() {
29 let f = || {
30 ensurerust-analyzer cargo anyhow 1.0.103 macros/ensure!!(1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). 1 == 2, "This is correct");
31 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
32 };
33 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
34
35 let v = 1;
36 let f = || {
37 ensurerust-analyzer cargo anyhow 1.0.103 macros/ensure!!(v +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). v == 2, "This is correct, v: {}", v);
38 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
39 };
40 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
41
42 let f = || {
43 ensurerust-analyzer cargo anyhow 1.0.103 macros/ensure!!(v +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). v == 1, "This is not correct, v: {}", v);
44 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
45 };
46 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(f().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
47
48 let f = || {
49 ensurerust-analyzer cargo anyhow 1.0.103 macros/ensure!!(v +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). v == 1);
50 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
51 };
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
53 f().unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
54 "Condition failed: `v + v == 1` (2 vs 1)",
55 );
56 }
57
58 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
59 fn test_ensure_nonboolrust-analyzer cargo anyhow 1.0.103 test_ensure_nonbool().() -> Resultrust-analyzer cargo anyhow 1.0.103 Result#<()> {
60 struct Structrust-analyzer cargo anyhow 1.0.103 Struct# {
61 conditionrust-analyzer cargo anyhow 1.0.103 Struct#condition.: bool,
62 }
63
64 let s = Structrust-analyzer cargo anyhow 1.0.103 Struct# { conditionrust-analyzer cargo anyhow 1.0.103 Struct#condition.: true };
65 match &s {
66 Structrust-analyzer cargo anyhow 1.0.103 Struct# { conditionrust-analyzer cargo anyhow 1.0.103 Struct#condition. } => ensurerust-analyzer cargo anyhow 1.0.103 macros/ensure!!(condition), // &bool
67 }
68
69 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
70 }
71
72 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
73 fn test_temporariesrust-analyzer cargo anyhow 1.0.103 test_temporaries().() {
74 fn require_send_syncrust-analyzer cargo anyhow 1.0.103 require_send_sync().(_: impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#) {}
75
76 require_send_syncrust-analyzer cargo anyhow 1.0.103 require_send_sync().(async {
77 // If anyhow hasn't dropped any temporary format_args it creates by the
78 // time it's done evaluating, those will stick around until the
79 // semicolon, which is on the other side of the await point, making the
80 // enclosing future non-Send.
81 futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/ready().(anyhowrust-analyzer cargo anyhow 1.0.103 macros/anyhow!!("...")).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/impl#[`Ready<T>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/impl#[`Ready<T>`][Future]poll().;
82 });
83
84 fn messagerust-analyzer cargo anyhow 1.0.103 message().(cell: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<&str>) -> &str {
85 cell.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().()
86 }
87
88 require_send_syncrust-analyzer cargo anyhow 1.0.103 require_send_sync().(async {
89 futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/ready().(anyhowrust-analyzer cargo anyhow 1.0.103 macros/anyhow!!(messagerust-analyzer cargo anyhow 1.0.103 message().(Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().("...")))).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/impl#[`Ready<T>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/ready/impl#[`Ready<T>`][Future]poll().;
90 });
91 }
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn test_brace_escaperust-analyzer cargo anyhow 1.0.103 test_brace_escape().() {
95 let err = anyhowrust-analyzer cargo anyhow 1.0.103 macros/anyhow!!("unterminated ${{..}} expression");
96 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("unterminated ${..} expression", err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
97 }