Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! Macros for testing conditions without panicking. The `expect_*` family of macros cause an early
2 //! return of an [`anyhow::Error`] if the expected condition is not met.
3
4 use anyhowrust-analyzer cargo anyhow 1.0.104 crate/::anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!;
5
6 #[doc(hidden)]
7 pub fn msgrust-analyzer cargo expecting 0.6.0 msg().(file: &str, line: u32, expr: &str, msg: &str) -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Errorrust-analyzer cargo anyhow 1.0.104 Error# {
8 anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("\n\n\x1B[1m[{file}:{line}]\x1B[0m \x1B[4m{expr}\x1B[0m: \x1B[31m{msg}\x1B[0m\n")
9 }
10
11 /// Expects that the given condition evaluates to `true`; otherwise returns early.
12 ///
13 /// # Examples
14 ///
15 /// ```
16 /// # use anyhow::Result;
17 /// # use expecting::expect;
18 /// fn passing_test() -> Result<()> {
19 /// expect!(1 + 1 == 2);
20 /// Ok(())
21 /// }
22 /// # assert!(passing_test().is_ok());
23 ///
24 /// fn failing_test() -> Result<()> {
25 /// expect!(1 + 1 == 69); // returns early
26 /// Ok(()) // won't be reached
27 /// }
28 /// # assert!(failing_test().is_err());
29 /// ```
30 ///
31 /// `failing_test()` will return early after calling `expect!`. The `Err` will be wrapped in a
32 /// descriptive error message such as:
33 ///
34 /// > **[my/file.rs:12]** *"expect!(condition)"* Expected true but was false.<br/>
35 /// > [ ... wrapped Err details ...]
36 ///
37 #[macro_export]
38 macro_rules! expectrust-analyzer cargo expecting 0.6.0 expect! {
39 ( $a:expr ) => {{
40 if $a {
41 Ok(())
42 } else {
43 let expr_str = format!("expect({})", stringify!($a));
44 let msg = format!("Expected true but was false.");
45 Err($crate::msg(file!(), line!(), &expr_str, &msg))
46 }
47 }?};
48 }
49
50 /// Expects that the given [`Result`] is `Ok` and returns its unwrapped contents; otherwise returns
51 /// early.
52 ///
53 /// # Examples
54 ///
55 /// ```
56 /// # use anyhow::{anyhow, Result};
57 /// # use expecting::{expect_eq, expect_ok};
58 /// fn passing_test() -> Result<()> {
59 /// let result: Result<i32> = Ok(69);
60 /// let contents = expect_ok!(result);
61 /// expect_eq!(contents, 69);
62 /// Ok(())
63 /// }
64 /// # assert!(passing_test().is_ok());
65 ///
66 /// fn failing_test() -> Result<()> {
67 /// let result: Result<i32> = Err(anyhow!("ruh roh!"));
68 /// let contents = expect_ok!(result); // returns early
69 /// Ok(()) // won't be reached
70 /// }
71 /// # assert!(failing_test().is_err());
72 /// ```
73 ///
74 /// `failing_test()` will return early after calling `expect_ok!`. The `Err` will be wrapped in a
75 /// descriptive error message such as:
76 ///
77 /// > **[my/file.rs:12]** *"expect_ok!(result)"* Expected Ok, got Err: "ruh roh!"<br/>
78 /// > [ ... wrapped Err details ...]
79 ///
80 #[macro_export]
81 macro_rules! expect_okrust-analyzer cargo expecting 0.6.0 expect_ok! {
82 ( $result:expr ) => {
83 match $result {
84 Ok(t) => Ok(t),
85 Err(ref e) => {
86 let expr_str = format!("expect_ok({})", stringify!($result));
87 let msg = format!("Expected Ok, got Err:\n{e:?})");
88 Err($crate::msg(file!(), line!(), &expr_str, &msg))
89 }
90 }?
91 };
92 }
93
94 /// Expects that the given [`Result`] is `Err` and returns the unwrapped error; otherwise returns
95 /// early.
96 ///
97 /// # Examples
98 ///
99 /// ```
100 /// # use anyhow::{anyhow, Result};
101 /// # use expecting::{expect, expect_err};
102 /// fn passing_test() -> Result<()> {
103 /// let result: Result<i32> = Err(anyhow!("ruh roh!"));
104 /// let err = expect_err!(result);
105 /// expect!(err.to_string().contains("ruh roh!"));
106 /// Ok(())
107 /// }
108 /// # assert!(passing_test().is_ok());
109 ///
110 /// fn failing_test() -> Result<()> {
111 /// let err = expect_err!(Ok(())); // returns early
112 /// Ok(()) // won't be reached
113 /// }
114 /// # assert!(failing_test().is_err());
115 /// ```
116 ///
117 /// `failing_test()` will return early after calling `expect_err!`. The `Err` will be wrapped in a
118 /// descriptive error message such as:
119 ///
120 /// > **[my/file.rs:12]** *"expect_err!(result)"* Expected Err, got Ok: [ contents ]<br/>
121 /// > [ ... wrapped Err details ...]
122 ///
123 #[macro_export]
124 macro_rules! expect_errrust-analyzer cargo expecting 0.6.0 expect_err! {
125 ( $result:expr ) => {
126 match $result {
127 Err(e) => Ok(e),
128 Ok(t) => {
129 let expr_str = format!("expect_err({})", stringify!($result));
130 let msg = format!("Expected Err, got Ok:\n{t:?}");
131 Err($crate::msg(file!(), line!(), &expr_str, &msg))
132 }
133 }?
134 };
135 }
136
137 /// Expects that the given [`Option`] is `Some` and returns its unwrapped contents; otherwise
138 /// returns early.
139 ///
140 /// # Examples
141 ///
142 /// ```
143 /// # use anyhow::Result;
144 /// # use expecting::{expect_eq, expect_some};
145 /// fn passing_test() -> Result<()> {
146 /// let option = Some(69);
147 /// let contents = expect_some!(option);
148 /// expect_eq!(contents, 69);
149 /// Ok(())
150 /// }
151 /// # assert!(passing_test().is_ok());
152 ///
153 /// fn failing_test() -> Result<()> {
154 /// let option = None::<()>;
155 /// let contents = expect_some!(option); // returns early with Err
156 /// Ok(()) // won't be reached
157 /// }
158 /// # assert!(failing_test().is_err());
159 /// ```
160 ///
161 /// `failing_test()` will return early after calling `expect_some!`. The `Err` will be wrapped in a
162 /// descriptive error message such as:
163 ///
164 /// > **[my/file.rs:12]** *"expect_some!(option)"* Expected Some, got None"<br/>
165 /// > [ ... wrapped Err details ...]
166 ///
167 #[macro_export]
168 macro_rules! expect_somerust-analyzer cargo expecting 0.6.0 expect_some! {
169 ( $option:expr ) => {
170 match $option {
171 Some(t) => Ok(t),
172 None => {
173 let expr_str = format!("expect_some({})", stringify!($option));
174 let msg = format!("Expected Some, got None");
175 Err($crate::msg(file!(), line!(), &expr_str, &msg))
176 }
177 }?
178 };
179 }
180
181 /// Expects that the given [`Option`] is `None`; otherwise returns early.
182 ///
183 /// # Examples
184 ///
185 /// ```
186 /// # use anyhow::Result;
187 /// # use expecting::expect_none;
188 /// fn passing_test() -> Result<()> {
189 /// expect_none!(None::<()>);
190 /// Ok(())
191 /// }
192 /// # assert!(passing_test().is_ok());
193 ///
194 /// fn failing_test() -> Result<()>{
195 /// expect_none!(Some(())); // returns early
196 /// Ok(()) // won't be reached
197 /// }
198 /// # assert!(failing_test().is_err());
199 /// ```
200 ///
201 /// `failing_test()` will return early after calling `expect_none!`. The `Err` will be wrapped in a
202 /// descriptive error message such as:
203 ///
204 /// > **[my/file.rs:12]** *"expect_none!(option)"* Expected None, got Some: [ contents ]"<br/>
205 /// > [ ... wrapped Err details ...]
206 ///
207 #[macro_export]
208 macro_rules! expect_nonerust-analyzer cargo expecting 0.6.0 expect_none! {
209 ( $option:expr ) => {
210 match $option {
211 None => Ok(()),
212 Some(t) => {
213 let expr_str = format!("expect_none({})", stringify!($option));
214 let msg = format!("Expected None, got Some:\n{t:?})");
215 Err($crate::msg(file!(), line!(), &expr_str, &msg))
216 }
217 }?
218 };
219 }
220
221 /// Expects that a == b; otherwise returns early.
222 ///
223 /// # Examples
224 ///
225 /// ```
226 /// # use anyhow::Result;
227 /// # use expecting::expect_eq;
228 ///
229 /// fn passing_test() -> Result<()> {
230 /// expect_eq!(1, 1);
231 /// Ok(())
232 /// }
233 /// # assert!(passing_test().is_ok());
234 ///
235 /// fn failing_test() -> Result<()> {
236 /// expect_eq!(1, 2); // returns early
237 /// Ok(()) // won't be reached
238 /// }
239 /// # assert!(failing_test().is_err());
240 /// ```
241 #[macro_export]
242 macro_rules! expect_eqrust-analyzer cargo expecting 0.6.0 expect_eq! {
243 ( $a:expr, $b:expr ) => {{
244 let a = $a;
245 let b = $b;
246 if a == b {
247 Ok(())
248 } else {
249 let expr_str = format!("expect_eq({}, {})", stringify!($a), stringify!($b));
250 let msg = format!("{:?} != {:?}, expected them to be equal.", a, b);
251 Err($crate::msg(file!(), line!(), &expr_str, &msg))
252 }
253 }?};
254 }
255
256 /// Expects that a != b; otherwise returns early.
257 ///
258 /// # Examples
259 ///
260 /// ```
261 /// # use anyhow::Result;
262 /// # use expecting::expect_ne;
263 ///
264 /// fn passing_test() -> Result<()> {
265 /// expect_ne!(1, 2);
266 /// Ok(())
267 /// }
268 /// # assert!(passing_test().is_ok());
269 ///
270 /// fn failing_test() -> Result<()> {
271 /// expect_ne!(1, 1); // returns early
272 /// Ok(()) // won't be reached
273 /// }
274 /// # assert!(failing_test().is_err());
275 /// ```
276 #[macro_export]
277 macro_rules! expect_nerust-analyzer cargo expecting 0.6.0 expect_ne! {
278 ( $a:expr, $b:expr ) => {{
279 let a = $a;
280 let b = $b;
281 if a != b {
282 Ok(())
283 } else {
284 let expr_str = format!("expect_ne({}, {})", stringify!($a), stringify!($b));
285 let msg = format!("{:?} == {:?}, expected them *not* to be equal.", a, b);
286 Err($crate::msg(file!(), line!(), &expr_str, &msg))
287 }
288 }?};
289 }
290
291 /// Expects that the given container (e.g., [`Vec`]) is empty; otherwise returns early.
292 ///
293 /// # Examples
294 ///
295 /// ```
296 /// # use anyhow::Result;
297 /// # use expecting::expect_empty;
298 ///
299 /// fn passing_test() -> Result<()> {
300 /// let empty: Vec<i32> = vec![];
301 /// expect_empty!(empty);
302 /// Ok(())
303 /// }
304 /// # assert!(passing_test().is_ok());
305 ///
306 /// fn failing_test() -> Result<()> {
307 /// expect_empty!(vec![0, 1, 1, 2, 3, 5, 8, 13, 21]); // returns early
308 /// Ok(()) // won't be reached
309 /// }
310 /// # assert!(failing_test().is_err());
311 /// ```
312 #[macro_export]
313 macro_rules! expect_emptyrust-analyzer cargo expecting 0.6.0 expect_empty! {
314 ( $a:expr ) => {{
315 let a = $a;
316 if a.is_empty() {
317 Ok(())
318 } else {
319 let expr_str = format!("expect_empty({})", stringify!($a));
320 let msg = format!("Expected empty, but contained elements:\n{:?}", a);
321 Err($crate::msg(file!(), line!(), &expr_str, &msg))
322 }
323 }?};
324 }
325
326 /// Expects that the given container (e.g., [`Vec`]) contains at least one element or given string
327 /// has non-zero length; otherwise returns early.
328 ///
329 /// # Examples
330 ///
331 /// ```
332 /// # use anyhow::Result;
333 /// # use expecting::expect_not_empty;
334 ///
335 /// fn passing_test() -> Result<()> {
336 /// expect_not_empty!(vec![1]);
337 /// Ok(())
338 /// }
339 /// # assert!(passing_test().is_ok());
340 ///
341 /// fn failing_test() -> Result<()> {
342 /// let empty: Vec<i32> = vec![];
343 /// expect_not_empty!(empty); // returns early
344 /// Ok(()) // won't be reached
345 /// }
346 /// # assert!(failing_test().is_err());
347 /// ```
348 #[macro_export]
349 macro_rules! expect_not_emptyrust-analyzer cargo expecting 0.6.0 expect_not_empty! {
350 ( $a:expr ) => {{
351 let a = $a;
352 if !a.is_empty() {
353 Ok(())
354 } else {
355 let expr_str = format!("expect_not_empty({})", stringify!($a));
356 let msg = "Expected non-empty, but was empty.";
357 Err($crate::msg(file!(), line!(), &expr_str, &msg))
358 }
359 }?};
360 }
361
362 /// Expects that the given container (e.g., [`Vec`]) contains the element or given string contains
363 /// the substring; otherwise returns early.
364 ///
365 /// # Examples
366 ///
367 /// ```
368 /// # use anyhow::Result;
369 /// # use expecting::expect_contains;
370 ///
371 /// fn passing_test() -> Result<()> {
372 /// let v: Vec<i32> = vec![42, 1337];
373 /// expect_contains!(v, 42);
374 /// Ok(())
375 /// }
376 /// # assert!(passing_test().is_ok());
377 ///
378 /// fn passing_test_for_string() -> Result<()> {
379 /// let superstring = "angelheaded hipsters";
380 /// expect_contains!(superstring, "hip");
381 /// Ok(())
382 /// }
383 /// # assert!(passing_test_for_string().is_ok());
384 ///
385 /// fn failing_test() -> Result<()> {
386 /// let v: Vec<i32> = vec![42, 1337];
387 /// expect_contains!(v, 13); // returns early
388 /// Ok(()) // won't be reached
389 /// }
390 /// # assert!(failing_test().is_err());
391 /// ```
392 #[macro_export]
393 macro_rules! expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains! {
394 ( $container:expr, $element_or_substr:expr ) => {{
395 let container = $container;
396 let element_or_substr = $element_or_substr;
397 if container.contains(&element_or_substr) {
398 Ok(())
399 } else {
400 let expr_str = format!(
401 "expect_contains({}, {})",
402 stringify!($container),
403 stringify!($element_or_substr)
404 );
405 let msg = format!(
406 "Expected to contain {:?}, but did not:\n{:?}",
407 element_or_substr, container,
408 );
409 Err($crate::msg(file!(), line!(), &expr_str, &msg))
410 }
411 }?};
412 }
413
414 /// Expects that `a` is `Some` and its contents are equal to `b`.
415 ///
416 /// # Examples
417 ///
418 /// ```
419 /// # use anyhow::Result;
420 /// # use expecting::expect_some_eq;
421 ///
422 /// fn passing_test() -> Result<()> {
423 /// expect_some_eq!(Some(1), 1);
424 /// Ok(())
425 /// }
426 /// # assert!(passing_test().is_ok());
427 ///
428 /// fn failing_test1() -> Result<()> {
429 /// // wrong contents, 1 != 2
430 /// expect_some_eq!(Some(1), 2); // returns early
431 /// Ok(()) // won't be reached
432 /// }
433 /// # assert!(failing_test1().is_err());
434 ///
435 /// fn failing_test2() -> Result<()> {
436 /// // first arg is None
437 /// expect_some_eq!(None::<i32>, 2); // returns early
438 /// Ok(()) // won't be reached
439 /// }
440 /// # assert!(failing_test2().is_err());
441 /// ```
442 #[macro_export]
443 macro_rules! expect_some_eqrust-analyzer cargo expecting 0.6.0 expect_some_eq! {
444 ( $some_a:expr, $b:expr ) => {{
445 let b = $b;
446 let msg: String = match $some_a {
447 Some(a) => {
448 if a == b {
449 "".to_string()
450 } else {
451 format!("{:?} != {:?}, expected them to be equal.", a, b)
452 }
453 }
454 None => format!("Expected {} to be Some, was None.", stringify!($some_a)),
455 };
456
457 if msg.is_empty() {
458 Ok(())
459 } else {
460 let expr_str = format!(
461 "expect_some_eq({}, {})",
462 stringify!($some_a),
463 stringify!($b)
464 );
465 Err($crate::msg(file!(), line!(), &expr_str, &msg))
466 }
467 }?};
468 }
469
470 #[cfg(test)]
471 #[allow(non_snake_case)]
472 mod testsrust-analyzer cargo expecting 0.6.0 tests/ {
473 use anyhowrust-analyzer cargo anyhow 1.0.104 crate/::{anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!, Resultrust-analyzer cargo anyhow 1.0.104 Result#};
474
475 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
476 fn expect__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect__success__no_early_return().() {
477 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
478 expectrust-analyzer cargo expecting 0.6.0 expect!!(1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). 1 == 2);
479 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
480 };
481 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
482 }
483
484 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
485 fn expect__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect__failure__causes_early_return().() {
486 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
487 expectrust-analyzer cargo expecting 0.6.0 expect!!(1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). 1 == 69); // should return early
488 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
489 };
490 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
491 }
492
493 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
494 fn expect_ok__success__returns_ok_valuerust-analyzer cargo expecting 0.6.0 tests/expect_ok__success__returns_ok_value().() {
495 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<i64> {
496 let result: Resultrust-analyzer cargo anyhow 1.0.104 Result#<i64> = Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(69);
497 let contents = expect_okrust-analyzer cargo expecting 0.6.0 expect_ok!!(result);
498 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(contents)
499 };
500 let result = test();
501 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
502 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 69);
503 }
504
505 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
506 fn expect_ok__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_ok__failure__causes_early_return().() {
507 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
508 let result: Resultrust-analyzer cargo anyhow 1.0.104 Result#<i64> = Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("ruh roh!"));
509 let _ = expect_okrust-analyzer cargo expecting 0.6.0 expect_ok!!(result); // returns early with Err
510 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
511 };
512 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
513 }
514
515 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
516 fn expect_err__success__returns_err_valuerust-analyzer cargo expecting 0.6.0 tests/expect_err__success__returns_err_value().() {
517 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Errorrust-analyzer cargo anyhow 1.0.104 Error#> {
518 let result: Resultrust-analyzer cargo anyhow 1.0.104 Result#<i64> = Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("ruh roh!"));
519 let err = expect_errrust-analyzer cargo expecting 0.6.0 expect_err!!(result);
520 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(err)
521 };
522 let result = test();
523 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
524 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ruh roh!"));
525 }
526
527 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
528 fn expect_err__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_err__failure__causes_early_return().() {
529 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
530 let result: Resultrust-analyzer cargo anyhow 1.0.104 Result#<i64> = Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(69);
531 let _ = expect_errrust-analyzer cargo expecting 0.6.0 expect_err!!(result); // returns early with Err
532 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
533 };
534 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
535 }
536
537 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
538 fn expect_some__success__returns_some_valuerust-analyzer cargo expecting 0.6.0 tests/expect_some__success__returns_some_value().() {
539 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<i32> {
540 let some = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1337);
541 let contents = expect_somerust-analyzer cargo expecting 0.6.0 expect_some!!(some);
542 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(contents)
543 };
544 let result = test();
545 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
546 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1337);
547 }
548
549 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
550 fn expect_some__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_some__failure__causes_early_return().() {
551 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
552 let _ = expect_somerust-analyzer cargo expecting 0.6.0 expect_some!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#::<i32>); // returns early with Err
553 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
554 };
555 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
556 }
557
558 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
559 fn expect_none__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_none__success__no_early_return().() {
560 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
561 expect_nonerust-analyzer cargo expecting 0.6.0 expect_none!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#::<i64>);
562 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
563 };
564 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
565 }
566
567 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
568 fn expect_none__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_none__failure__causes_early_return().() {
569 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
570 expect_nonerust-analyzer cargo expecting 0.6.0 expect_none!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1337)); // returns early with Err
571 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
572 };
573 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
574 }
575
576 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
577 fn expect_eq__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_eq__success__no_early_return().() {
578 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
579 expect_eqrust-analyzer cargo expecting 0.6.0 expect_eq!!(1, 1);
580 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
581 };
582 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
583 }
584
585 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
586 fn expect_eq__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_eq__failure__causes_early_return().() {
587 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
588 expect_eqrust-analyzer cargo expecting 0.6.0 expect_eq!!(1, 2); // returns early with Err
589 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
590 };
591 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
592 }
593
594 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
595 fn expect_ne__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_ne__success__no_early_return().() {
596 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
597 expect_nerust-analyzer cargo expecting 0.6.0 expect_ne!!(1, 2);
598 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
599 };
600 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
601 }
602
603 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
604 fn expect_ne__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_ne__failure__causes_early_return().() {
605 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
606 expect_nerust-analyzer cargo expecting 0.6.0 expect_ne!!(1, 1); // returns early with Err
607 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
608 };
609 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
610 }
611
612 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
613 fn expect_empty__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_empty__success__no_early_return().() {
614 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
615 let empty: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
616 expect_emptyrust-analyzer cargo expecting 0.6.0 expect_empty!!(empty);
617 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
618 };
619 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
620 }
621
622 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
623 fn expect_empty__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_empty__failure__causes_early_return().() {
624 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
625 let not_empty: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1];
626 expect_emptyrust-analyzer cargo expecting 0.6.0 expect_empty!!(not_empty); // should return early
627 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
628 };
629 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
630 }
631
632 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
633 fn expect_not_empty__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_not_empty__success__no_early_return().() {
634 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
635 let not_empty: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1];
636 expect_not_emptyrust-analyzer cargo expecting 0.6.0 expect_not_empty!!(not_empty);
637 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
638 };
639 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
640 }
641
642 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
643 fn expect_not_empty__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_not_empty__failure__causes_early_return().() {
644 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
645 let empty: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
646 expect_not_emptyrust-analyzer cargo expecting 0.6.0 expect_not_empty!!(empty); // should return early
647 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
648 };
649 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
650 }
651
652 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
653 fn expect_not_empty__string__success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_not_empty__string__success__no_early_return().() {
654 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
655 expect_not_emptyrust-analyzer cargo expecting 0.6.0 expect_not_empty!!("asdf");
656 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
657 };
658 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
659 }
660
661 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
662 fn expect_not_empty__string__failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_not_empty__string__failure__causes_early_return().() {
663 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
664 expect_not_emptyrust-analyzer cargo expecting 0.6.0 expect_not_empty!!(""); // should return early
665 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
666 };
667 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
668 }
669
670 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
671 fn expect_contains__vec_of_int_success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_contains__vec_of_int_success__no_early_return().() {
672 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
673 let v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![42, 1337];
674 expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains!!(v, 42);
675 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
676 };
677 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
678 }
679
680 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
681 fn expect_contains__vec_of_int_failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_contains__vec_of_int_failure__causes_early_return().() {
682 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
683 let v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i64> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![42, 1337];
684 expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains!!(v, 69);
685 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
686 };
687 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
688 }
689
690 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
691 fn expect_contains__string_success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_contains__string_success__no_early_return().() {
692 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
693 let superstring = "angelheaded hipsters burning for the ancient heavenly connection";
694 expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains!!(superstring, "hipsters");
695 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
696 };
697 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
698 }
699
700 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
701 fn expect_contains__string_failure__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_contains__string_failure__causes_early_return().() {
702 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
703 let superstring = "angelheaded hipsters burning for the ancient heavenly connection";
704 expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains!!(superstring, "yuppies");
705 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
706 };
707 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
708 }
709
710 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
711 fn expect_contains__string_failure__returns_correct_err_messagerust-analyzer cargo expecting 0.6.0 tests/expect_contains__string_failure__returns_correct_err_message().() {
712 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
713 let superstring = "angelheaded hipsters burning";
714 expect_containsrust-analyzer cargo expecting 0.6.0 expect_contains!!(superstring, "yuppies");
715 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
716 };
717 let result = test();
718 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
719 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.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().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(
720 "Expected to contain \"yuppies\", but did not:\n\"angelheaded hipsters burning\""
721 ));
722 }
723
724 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
725 fn expect_some_eq__int_success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_some_eq__int_success__no_early_return().() {
726 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
727 expect_some_eqrust-analyzer cargo expecting 0.6.0 expect_some_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), 1);
728 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
729 };
730 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
731 }
732
733 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
734 fn expect_some_eq__int_wrong_contents__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_some_eq__int_wrong_contents__causes_early_return().() {
735 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
736 expect_some_eqrust-analyzer cargo expecting 0.6.0 expect_some_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), 2); // returns early with Err
737 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
738 };
739 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
740 }
741
742 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
743 fn expect_some_eq__int_none__causes_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_some_eq__int_none__causes_early_return().() {
744 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
745 expect_some_eqrust-analyzer cargo expecting 0.6.0 expect_some_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#::<i32>, 2); // returns early with Err
746 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) // won't be reached
747 };
748 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
749 }
750
751 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
752 fn expect_some_eq__string_success__no_early_returnrust-analyzer cargo expecting 0.6.0 tests/expect_some_eq__string_success__no_early_return().() {
753 let test = || -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
754 let contents = "george";
755 expect_some_eqrust-analyzer cargo expecting 0.6.0 expect_some_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(contents.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), contents);
756 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("no early return"))
757 };
758 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(test().is_err_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err_and().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no early return")));
759 }
760 }