Skip to content

Commit

Permalink
Make assert_that a little more ergonomico
Browse files Browse the repository at this point in the history
Stop testing with `--all-targets` to ensure doctests run
(seems like rust-lang/cargo#5178 might still
exist).
  • Loading branch information
ian-h-chamberlain committed Jun 19, 2020
1 parent dae9d3f commit ec73de0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/corewa_rs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}
- name: Build and run tests
run: cargo test --color=always --workspace --all-targets --all-features
run: cargo test --color=always --workspace --all-features
1 change: 0 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"command": "test",
"args": [
"--all-features",
"--all-targets",
"--workspace"
],
"group": {
Expand Down
30 changes: 13 additions & 17 deletions corewa_rs/src/testutil.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
pub use predicates;
pub use predicates_tree;

/// Simple macro to panic with a prettier error message
/// Simple macro to make assertions with a better error message.
///
/// # Examples
///
/// ```
/// use predicates::prelude::*;
/// use testutil::assert_that;
/// extern crate corewa_rs;
/// use corewa_rs::assert_that;
///
/// assert_that!(
/// "Hello World",
/// str::similar("Hello World"),
/// );
/// assert_that!("Hello World", str::similar("Hello World"));
///
/// assert_that!("Hello World", str::diff("Goodbye World"));
///
/// // Can be used with more complex predicates
/// assert_that!(
/// "Hello World",
/// str::diff("Goodbye World"),
/// &1234,
/// ge(-5).and(le(i16::MAX))
/// );
///
/// assert_that!("Hello World", eq("Goodbye World"));
/// ```
#[macro_export]
macro_rules! assert_that {
(
$value:expr,
$($pred:tt)+ ( $args:tt ) $(,)?
) => {{
use predicate::*;
($value:expr, $pred:expr $(,)?) => {{
use $crate::predicates::prelude::*;
use $crate::predicates_tree::CaseTreeExt;

if let Some(case) = $($pred)+ rgo ($args).find_case(false, $value) {
use predicate::*;

if let Some(case) = $pred.find_case(false, $value) {
panic!("{}", case.tree());
};
}};
Expand Down
2 changes: 1 addition & 1 deletion corewa_rs/tests/dump_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn run_test(input: &str, expected_output: &'static str) {
.resolve()
.unwrap_or_else(|e| panic!("{}", e));

assert_that!(&parsed_core.to_string(), str::similar(expected_output),);
assert_that!(&parsed_core.to_string(), str::similar(expected_output));
}

#[test]
Expand Down

0 comments on commit ec73de0

Please sign in to comment.