| 1 | // Copyright 2021 Martin Pool |
| 2 | |
| 3 | //! Test compatibility with Anyhow. |
| 4 | |
| 5 | use std::path::Path; |
| 6 | |
| 7 | use anyhow::Context; |
| 8 | use cp_r::CopyOptions; |
| 9 | |
| 10 | #[test] |
| 11 | fn 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 = tempfile::tempdir().unwrap(); |
| 14 | let stats = CopyOptions::new() |
| 15 | .copy_tree(Path::new("src"), dest.path()) |
| 16 | .context("copy src dir for test") |
| 17 | .unwrap(); |
| 18 | dbg!(&stats); |
| 19 | } |
| 20 | |
| 21 | #[test] |
| 22 | fn 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 = tempfile::tempdir().unwrap(); |
| 25 | let err = CopyOptions::new() |
| 26 | .create_destination(false) |
| 27 | .copy_tree(Path::new("src"), dest.path().join("nonexistent")) |
| 28 | .context("copy src dir for test") |
| 29 | .unwrap_err(); |
| 30 | dbg!(&err); |
| 31 | println!("Display error: {}", err); |
| 32 | } |