Skip to content

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Apr 12, 2024
1 parent e4b97a4 commit a8bf78e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ jobs:
run: cargo fmt --check
- name: Lint
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo test --workspace
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ repository = "https://github.com/ultimaweapon/erdp"
edition = "2021"

[dependencies]

[dev-dependencies]
thiserror = "1.0.58"
30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@ impl<'a> std::fmt::Display for Display<'a> {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use thiserror::Error;

#[test]
fn single() {
let e = TestError::Single;

assert_eq!(e.display().to_string(), "an error without nested errors");
}

#[test]
fn nested() {
let e = std::io::Error::from(std::io::ErrorKind::NotFound);
let e = TestError::Nested(e);

assert_eq!(e.display().to_string(), "nested error -> entity not found");
}

#[derive(Debug, Error)]
enum TestError {
#[error("an error without nested errors")]
Single,

#[error("nested error")]
Nested(#[source] std::io::Error),
}
}

0 comments on commit a8bf78e

Please sign in to comment.