Skip to content

Commit

Permalink
Improve wording and README structure
Browse files Browse the repository at this point in the history
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
  • Loading branch information
wiktor-k committed Mar 12, 2024
1 parent 0883161 commit b604b16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["Wiktor Kwapisiewicz <wiktor@metacode.biz>"]
description = "Provides TestResult type for concise and precise test failures"
repository = "https://github.com/wiktor-k/testresult"
license = "MIT OR Apache-2.0"
keywords = ["testing"]
categories = ["development-tools::testing"]
keywords = ["testing", "error", "error-handling"]
categories = ["development-tools::testing", "rust-patterns"]
exclude = [".github"]

[dependencies]
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Provides `TestResult` type that can be used in tests to avoid
`unwrap`s but at the same time to have precise stacktraces with the
point of failure clearly written.

It's like a lean [`anyhow`](https://crates.io/crates/anyhow) for tests!

## Details

Consider the following code. It uses `unwrap` so the test failure
stacktrace will informative. Unfortunately it's not as concise as it
could be:
Expand Down Expand Up @@ -87,3 +91,19 @@ The advantages of using `TestResult`:
For a more elaborate description see ["Improving failure messages in Rust tests returning a Result"][IMPROV].

[IMPROV]: https://bluxte.net/musings/2023/01/08/improving_failure_messages_rust_tests/

## License

This project is licensed under either of:

- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0),
- [MIT license](https://opensource.org/licenses/MIT).

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in this crate by you, as defined in the
Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#![deny(missing_debug_implementations)]
#![deny(missing_docs)]

/// Error with stacktrace
/// Error with a stacktrace
///
/// Any other type of error can be converted to this one but the
/// conversion will always panic.
///
/// This type is useful only in the result of unit tests and cannot be instantiated.
/// This type is useful only in unit tests and cannot be directly instantiated.
#[derive(Debug)]
#[doc(hidden)]
pub enum TestError {}
Expand All @@ -25,13 +25,13 @@ impl<T: std::fmt::Display> From<T> for TestError {
/// Unit test result
///
/// This type allows panicking when encountering any type of
/// failure. Thus it allows using `?` operator in unit tests but still
/// get the complete stacktrace and exact place of failure during
/// failure. Thus it allows using the `?` operator in unit tests but still
/// getting the complete stacktrace and the exact place of a failure during
/// tests.
///
/// # Examples
///
/// Using [`TestResult`] as a result of the test function:
/// Using [`TestResult`] as a result of a test function:
///
/// ```
/// use testresult::TestResult;
Expand All @@ -47,6 +47,7 @@ impl<T: std::fmt::Display> From<T> for TestError {
///
/// As [`TestResult`] is generic one can use it in test helper functions to return
/// objects to test functions.
///
/// For example [`TestResult`] used in `rstest` fixture returns a [`std::fs::File`] object that
/// can be used by the test:
///
Expand Down

0 comments on commit b604b16

Please sign in to comment.