Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: asomers/mockall
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.12.0
Choose a base ref
...
head repository: asomers/mockall
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.12.1
Choose a head ref
  • 10 commits
  • 11 files changed
  • 1 contributor

Commits on Dec 10, 2023

  1. Copy the full SHA
    d605f45 View commit details
  2. chore: Release

    asomers committed Dec 10, 2023
    Copy the full SHA
    7e4af04 View commit details

Commits on Dec 13, 2023

  1. Fix using #[concretize] on functions with bounded generic types

    It's usually possible to turn such types into trait objects.  We just
    need to emit extra parenthesis in the generated code.
    
    Fixes #530
    asomers committed Dec 13, 2023
    Copy the full SHA
    b1f0e78 View commit details

Commits on Dec 16, 2023

  1. Merge pull request #531 from asomers/concretize-bounds

    Fix using #[concretize] on functions with bounded generic types
    asomers authored Dec 16, 2023
    Copy the full SHA
    d4e0710 View commit details

Commits on Dec 21, 2023

  1. Fix mocking functions that use raw identifiers for their names.

    This was a regression in 0.12.0, introduced by 60acf8e .
    
    Fixes #533
    asomers committed Dec 21, 2023
    Copy the full SHA
    71823a3 View commit details
  2. [skip ci] Clarify license terms

    Clarify that Mockall may be distributed under the terms of either the
    MIT or Apache-2.0 license.  This was always the intent, but was never
    expressed using the recommended SPDX syntax.
    
    Fixes #529
    asomers committed Dec 21, 2023
    Copy the full SHA
    80fee05 View commit details
  3. Merge pull request #538 from asomers/mit-or-apache

    [skip ci] Clarify license terms
    asomers authored Dec 21, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b252265 View commit details
  4. Merge pull request #534 from asomers/raw_identifier

    Fix mocking functions that use raw identifiers for their names.
    asomers authored Dec 21, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9406902 View commit details
  5. chore: Release

    asomers committed Dec 21, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    20e1c6d View commit details
  6. chore: Release

    asomers committed Dec 21, 2023
    Copy the full SHA
    51c4820 View commit details
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [ 0.12.1 ] - 2023-12-21

### Fixed

- Fixed using `#[mockall::concretize]` on functions whose generic types contain
trait bounds, yet are still object safe.
([#531](https://github.com/asomers/mockall/pull/531))

- Fixed mocking methods that use raw identifiers for their names. This was a
regression in 0.12.0.
([#534](https://github.com/asomers/mockall/pull/534))

## [ 0.12.0 ] - 2023-12-10

### Added
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ your `Cargo.toml`:

```toml
[dev-dependencies]
mockall = "0.12.0"
mockall = "0.12.1"
```

Then use it like this:
8 changes: 4 additions & 4 deletions mockall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "mockall"
version = "0.12.0"
version = "0.12.1"
authors = ["Alan Somers <asomers@gmail.com>"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/asomers/mockall"
categories = ["development-tools::testing"]
@@ -44,12 +44,12 @@ fragile = "2.0"
lazy_static = "1.1"
predicates = { version = "3.0.0", default-features = false }
predicates-tree = "1.0"
mockall_derive = { version = "=0.12.0", path = "../mockall_derive" }
mockall_derive = { version = "=0.12.1", path = "../mockall_derive" }

[dev-dependencies]
async-trait = "0.1.38"
futures = "0.3.7"
mockall_double = { version = "^0.3.0", path = "../mockall_double" }
mockall_double = { version = "^0.3.1", path = "../mockall_double" }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
135 changes: 135 additions & 0 deletions mockall/tests/mock_concretize_with_bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// vim: tw=80
//! Using #[concretize] on generic types with trait bounds
#![deny(warnings)]

use mockall::*;
use std::path::{Path, PathBuf};

trait AsRefMut<T: ?Sized>: AsRef<T> + AsMut<T> {}
impl<Q, T> AsRefMut<T> for Q where Q: AsRef<T> + AsMut<T>, T: ?Sized {}

mock! {
Foo {
/// Base concretized function
#[mockall::concretize]
fn foo<P: AsRef<std::path::Path> + Send>(&self, x: P);

/// With a where clause
#[mockall::concretize]
fn boom<P>(&self, x: P) where P: AsRef<std::path::Path> + Send;

/// Static function
#[mockall::concretize]
fn bang<P: AsRef<std::path::Path> + Send>(x: P);

/// Reference argument
#[mockall::concretize]
fn boomref<P: AsRef<std::path::Path> + Send>(&self, x: &P);

/// Mutable reference argument
#[mockall::concretize]
fn boom_mutref<T: AsRefMut<str> + Send>(&self, x: &mut T);

/// Slice argument
#[mockall::concretize]
fn boomv<P>(&self, x: &[P]) where P: AsRef<std::path::Path> + Send;
}
}

mod generic_arg {
use super::*;

#[test]
fn withf() {
let mut foo = MockFoo::new();
foo.expect_foo()
.withf(|p| p.as_ref() == Path::new("/tmp"))
.times(3)
.return_const(());
foo.foo(Path::new("/tmp"));
foo.foo(PathBuf::from(Path::new("/tmp")));
foo.foo("/tmp");
}
}

mod where_clause {
use super::*;

#[test]
fn withf() {
let mut foo = MockFoo::new();
foo.expect_boom()
.withf(|p| p.as_ref() == Path::new("/tmp"))
.times(3)
.return_const(());
foo.boom(Path::new("/tmp"));
foo.boom(PathBuf::from(Path::new("/tmp")));
foo.boom("/tmp");
}
}

mod mutable_reference_arg {
use super::*;

#[test]
fn withf() {
let mut foo = MockFoo::new();
foo.expect_boom_mutref()
.withf(|p| p.as_ref() == "/tmp")
.once()
.returning(|s| s.as_mut().make_ascii_uppercase());
let mut s = String::from("/tmp");
foo.boom_mutref(&mut s);
assert_eq!(s, "/TMP");
}
}

mod reference_arg {
use super::*;

#[test]
fn withf() {
let mut foo = MockFoo::new();
foo.expect_boomref()
.withf(|p| p.as_ref() == Path::new("/tmp"))
.times(3)
.return_const(());
foo.boomref(&Path::new("/tmp"));
foo.boomref(&PathBuf::from(Path::new("/tmp")));
foo.boomref(&"/tmp");
}
}

mod slice {
use super::*;

#[test]
fn withf() {
let mut foo = MockFoo::new();
foo.expect_boomv()
.withf(|v|
v[0].as_ref() == Path::new("/tmp") &&
v[1].as_ref() == Path::new("/mnt")
).times(3)
.return_const(());
foo.boomv(&[Path::new("/tmp"), Path::new("/mnt")]);
foo.boomv(&[PathBuf::from("/tmp"), PathBuf::from("/mnt")]);
foo.boomv(&["/tmp", "/mnt"]);
}
}

mod static_method {
use super::*;

#[test]
fn withf() {
let ctx = MockFoo::bang_context();
ctx.expect()
.withf(|p| p.as_ref() == Path::new("/tmp"))
.times(3)
.return_const(());
MockFoo::bang(Path::new("/tmp"));
MockFoo::bang(PathBuf::from(Path::new("/tmp")));
MockFoo::bang("/tmp");
}
}
72 changes: 72 additions & 0 deletions mockall/tests/raw_identifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// vim: tw=80
//! It should be possible to mock things that use raw identifiers
#![deny(warnings)]
#![allow(non_camel_case_types)]

use mockall::*;

#[automock]
trait r#while {
fn r#match(&self);
fn r#loop();
}

#[automock]
pub mod r#break {
pub fn r#if() {unimplemented!() }
}

mock! {
r#do {}
impl r#while for r#do {
fn r#match(&self);
fn r#loop();
}
}

struct r#else {}
#[automock]
impl r#while for r#else {
fn r#match(&self) {unimplemented!()}
fn r#loop() {unimplemented!()}
}

#[test]
fn by_ref() {
let mut foo = Mockwhile::new();
foo.expect_match()
.return_const(());
foo.r#match();
}

#[test]
fn static_method() {
let ctx = Mockwhile::loop_context();
ctx.expect()
.returning(|| ());
Mockwhile::r#loop();
}

#[test]
fn manual_mock() {
let mut foo = Mockdo::new();
foo.expect_match()
.return_const(());
foo.r#match();
}

#[test]
fn module() {
let ctx = mock_break::if_context();
ctx.expect()
.returning(|| ());
mock_break::r#if();
}

#[test]
fn trait_impl() {
let mut mock = Mockelse::new();
mock.expect_match()
.returning(|| ());
mock.r#match();
}
4 changes: 2 additions & 2 deletions mockall_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "mockall_derive"
version = "0.12.0"
version = "0.12.1"
authors = ["Alan Somers <asomers@gmail.com>"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/asomers/mockall"
categories = ["development-tools::testing"]
keywords = ["mock", "mocking", "testing"]
Loading