krlmlr / mockr

Drop-in replacement for testthat::with_mock()

Home Page:https://krlmlr.github.io/mockr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

partialised function does not work

lorenzwalthert opened this issue · comments

plus <- function(x = 0, y = 0, z = 0) {
  x + y + z
}

x_times_two <- function(x, y) {
  plus(x, x)
}

test_that("multiplication works", {
    contains_plus <- purrr::partial(x_times_two, x = 3) # contains a call to plus()
    out <- mockr::with_mock(
      plus = function(x, y) -1111,
      contains_plus(y = 2)
    )
    expect_equal(out, -1111)
  })
── Warning (Line 3): multiplication works ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
The code passed to `with_mock()` must be a braced expression to get accurate file-line information for failures.
Backtrace:
 1. mockr::with_mock(plus = function(x, y) -1111, contains_plus(y = 2))
 2. mockr:::evaluate_code(get_code_dots(dots), .parent)

── Failure (Line 7): multiplication works ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
`out` (`actual`) not equal to -1111 (`expected`).

  `actual`:     6
`expected`: -1111

Note this is not exactly a reprex, you need package infra to run this: the reprex package is here: https://github.com/lorenzwalthert/mockr.partial

I just saw #23, so not sure it makes sense to address this.

Thanks. purrr::partial() applies advanced magic to create a wrapper function, I spent some time to understand what's happening to no avail. We could add an item to the README.

Ok. I also submitted an issue in mockery: r-lib/mockery#44

Not a priority, sorry.