Skip to content

Commit

Permalink
docs(tryfn): Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 23, 2024
1 parent 8e26ddb commit c736e03
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/tryfn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
//! # Examples
//!
//! ```rust,no_run
//! fn some_func(num: usize) -> usize {
//! // ...
//! # 10
//! }
//!
//! tryfn::Harness::new(
//! "tests/fixtures/invalid",
//! setup,
//! test,
//! )
//! .select(["tests/cases/*.in"])
//! .action_env("SNAPSHOTS")
//! .test();
//!
//! fn setup(input_path: std::path::PathBuf) -> tryfn::Case {
Expand All @@ -29,7 +33,7 @@
//! let raw = std::fs::read_to_string(input_path)?;
//! let num = raw.parse::<usize>()?;
//!
//! let actual = num + 10;
//! let actual = some_func(num);
//!
//! Ok(actual)
//! }
Expand All @@ -38,6 +42,7 @@
use libtest_mimic::Trial;

pub use snapbox::assert::Action;
pub use snapbox::data::DataFormat;
pub use snapbox::Data;

/// [`Harness`] for discovering test inputs and asserting against snapshot files
Expand Down Expand Up @@ -87,7 +92,7 @@ where

/// Path patterns for selecting input files
///
/// This used gitignore syntax
/// This uses gitignore syntax
pub fn select<'p>(mut self, patterns: impl IntoIterator<Item = &'p str>) -> Self {
let mut overrides = ignore::overrides::OverrideBuilder::new(&self.root);
for line in patterns {
Expand Down Expand Up @@ -160,6 +165,7 @@ where
}
}

/// Function signature for generating a test [`Case`] from a path fixture
pub trait Setup {
fn setup(&self, fixture: std::path::PathBuf) -> Case;
}
Expand All @@ -173,6 +179,7 @@ where
}
}

/// Function signature for running a test [`Case`]
pub trait Test<S, E>
where
S: std::fmt::Display,
Expand All @@ -192,7 +199,7 @@ where
}
}

/// A test case enumerated by the [`Harness`] with data from the `setup` function
/// A test case enumerated by the [`Harness`] with data from the [`Setup`] function
pub struct Case {
/// Display name
pub name: String,
Expand Down

0 comments on commit c736e03

Please sign in to comment.