| 1 | // Copyright 2021 Martin Pool |
| 2 | |
| 3 | //! Test compatibility with Anyhow. |
| 4 | |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 6 | |
| 7 | use anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Contextrust-analyzer cargo anyhow 1.0.104 Context#; |
| 8 | use cp_rrust-analyzer cargo cp_r 0.5.2 crate/::CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#; |
| 9 | |
| 10 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 11 | fn attach_anyhow_context_to_successrust-analyzer cargo cp_r 0.5.2 attach_anyhow_context_to_success().() { |
| 12 | // This is mostly an assertion that the error type is compatible with that expected by Anyhow. |
| 13 | let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 14 | let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().() |
| 15 | .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("src"), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().()) |
| 16 | .contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("copy src dir for test") |
| 17 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 18 | dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(&stats); |
| 19 | } |
| 20 | |
| 21 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 22 | fn attach_anyhow_context_to_failurerust-analyzer cargo cp_r 0.5.2 attach_anyhow_context_to_failure().() { |
| 23 | // This is mostly an assertion that the error type is compatible with that expected by Anyhow. |
| 24 | let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 25 | let err = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().() |
| 26 | .create_destinationrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]create_destination().(false) |
| 27 | .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("src"), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("nonexistent")) |
| 28 | .contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("copy src dir for test") |
| 29 | .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 30 | dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(&err); |
| 31 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Display error: {}", err); |
| 32 | } |