Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shim to ease integration with the [proptest](https://crates.io/crates/proptest) crate. #246

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

hovinen
Copy link
Collaborator

@hovinen hovinen commented Jun 30, 2023

Previously, it was awkward to use GoogleTest Rust assertions in Proptest property tests and to return GoogleTest Result from such tests. This required a fair amount of manual type conversion.

This adds two trait implementations behind an optional dependency on the proptest crate:

  • An implementation of 'IntoTestResultallows easily converting the output ofTestRunnerinto a GoogleTestResult`.
  • An implementation of From<TestAssertionFailure> for TestCaseError allows easily using GoogleTest macros such as verify_that! inside TestRunner::run.

In particular, with this change, it is much easier to have property-based tests using proptest which do not panic on failure but rather communicate failures using Result, as is idiomatic in GoogleTest.

@hovinen hovinen force-pushed the add-proptest-support branch 6 times, most recently from 15ec82d to 055ef56 Compare July 7, 2023 14:27
…crates/proptest) crate.

Previously, it was awkward to use GoogleTest Rust assertions in Proptest property tests and to return GoogleTest `Result` from such tests. This required a fair amount of manual type conversion.

This adds two trait implementations behind an optional dependency on the `proptest` crate:

 * An implementation of 'IntoTestResult` allows easily converting the output of `TestRunner` into a GoogleTest `Result`.
 * An implementation of `From<TestAssertionFailure>` for `TestCaseError` allows easily using GoogleTest macros such as `verify_that!` inside `TestRunner::run`.

In particular, with this change, it is much easier to have property-based tests using `proptest` which do not panic on failure but rather communicate failures using `Result`, as is idiomatic in GoogleTest.

Since proptest requires Rust 1.60, this also modifies the CI action so that the test against Rust 1.59 only runs with the --no-default-features flag.

This also adds a section on integrations to the crate-level documentation covering both the new proptest integration and the existing [anyhow](https://crates.io/crates/anyhow) integration.
@hovinen hovinen force-pushed the add-proptest-support branch from 055ef56 to dc128d6 Compare July 7, 2023 14:38
@copybara-service copybara-service bot merged commit dbdc5cc into main Jul 7, 2023
@gribozavr gribozavr deleted the add-proptest-support branch February 17, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant