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

Test that fails when devtools isn't installed #247

Closed
hadley opened this issue Apr 15, 2015 · 3 comments · Fixed by #248
Closed

Test that fails when devtools isn't installed #247

hadley opened this issue Apr 15, 2015 · 3 comments · Fixed by #248
Milestone

Comments

@hadley
Copy link
Member

hadley commented Apr 15, 2015

from @s-u

1. Error: can mock if package is not loaded ------------------------------------
there is no package called 'devtools'
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: with_mock(`devtools::add_path` = identity, expect_identical(devtools::add_path, identity)) at test-mock.r:120
5: extract_mocks(new_values = new_values[!code_pos], .env = .env)
6: lapply(setNames(nm = mock_qual_names), function(qual_name) {
       pkg_name <- gsub(pkg_and_name_rx, "\\1", qual_name)
       name <- gsub(pkg_and_name_rx, "\\2", qual_name)
       if (pkg_name == "")
           pkg_name <- .env
       env <- asNamespace(pkg_name)
       if (!exists(name, envir = env, mode = "function"))
           stop("Function ", name, " not found in environment ", environmentName(env),
               ".")
       mock(name = name, env = env, new = eval(new_values[[qual_name]]))
   })
7: FUN(X[[i]], ...)
8: asNamespace(pkg_name)
9: getNamespace(ns)
10: tryCatch(loadNamespace(name), error = function(e) stop(e))
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatchOne(expr, names, parentenv, handlers[[1L]])
13: value[[3L]](cond)

Error: Test failures
Execution halted

@krlmlr can you please take a look?

@jimhester
Copy link
Member

I know I am not Kirill, but it looks like adding the following before tests/testthat/test-mock.r#L119-L121 should fix this

if (!"devtools" %in% installed.packages()[, "Package"])
  skip("devtools is not installed")

@s-u
Copy link

s-u commented Apr 15, 2015

FWIW installed.packages() is not cheap so it may be faster to use

if (!length(find.package("devtools", quiet=TRUE)))

@krlmlr
Copy link
Member

krlmlr commented Apr 15, 2015

Thanks, @jimhester and @s-u.

@hadley hadley modified the milestone: 0.11.0 Sep 29, 2015
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 a pull request may close this issue.

4 participants