diff --git a/.Rbuildignore b/.Rbuildignore index 4548e5d..34918a1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ ^codecov\.yml$ ^LICENSE\.md$ ^screencast.gif$ +^debugme\.Rproj$ diff --git a/DESCRIPTION b/DESCRIPTION index dba6d43..747f4a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,6 @@ Imports: grDevices Suggests: covr, - mockery, R6, testthat (>= 3.0.0), withr diff --git a/debugme.Rproj b/debugme.Rproj new file mode 100644 index 0000000..5d79cb7 --- /dev/null +++ b/debugme.Rproj @@ -0,0 +1,18 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/tests/testthat/test-colors.R b/tests/testthat/test-colors.R index 4167122..090f575 100644 --- a/tests/testthat/test-colors.R +++ b/tests/testthat/test-colors.R @@ -1,24 +1,21 @@ test_that("color palette is fine", { - - val <- NULL - - mockery::stub(initialize_colors, "assign", - function(x, value, envir, ...) val <<- value) initialize_colors(c("foo", "bar")) - expect_equal(names(val), c("foo", "bar")) - expect_true(all(val %in% grDevices::colors())) + expect_equal(names(debug_data[["palette"]]), c("foo", "bar")) + expect_true(all(debug_data[["palette"]] %in% grDevices::colors())) initialize_colors(letters) - expect_equal(names(val), letters) - expect_true(all(val %in% c("silver", grDevices::colors()))) + expect_equal(names(debug_data[["palette"]]), letters) + expect_true(all(debug_data[["palette"]] %in% c("silver", grDevices::colors()))) }) ## Quite an artificial test case... test_that("get a package style", { - mockery::stub(get_package_style, "is_debugged", function(...) TRUE) - mockery::stub(get_package_style, "make_style", function(x) substitute(x)) + local_mocked_bindings( + is_debugged = function(...) TRUE, + make_style = function(x) substitute(x) + ) ret <- get_package_style("pkg") expect_equal(ret, quote(debug_data$palette[pkg])) }) diff --git a/tests/testthat/test-debug.R b/tests/testthat/test-debug.R index 22eff85..0524daa 100644 --- a/tests/testthat/test-debug.R +++ b/tests/testthat/test-debug.R @@ -41,7 +41,9 @@ test_that("debug indent", { test_that("debug levels", { - mockery::stub(debug, "get_package_debug_level", 1) + local_mocked_bindings( + get_package_debug_level = function(...) 1 + ) env <- new.env() env$f1 <- function() debug("foobar", level = 1) env$f2 <- function() debug("baz", level = 2) @@ -68,7 +70,7 @@ test_that("get_timestamp_stamp", { mytime <- structure(1477967634, class = c("POSIXct", "POSIXt"), tzone = "UTC") - mockery::stub(get_timestamp_stamp, "Sys.time", mytime) + local_mocked_bindings(Sys.time = function() mytime, .package = "base") expect_equal( get_timestamp_stamp(), "2016-11-01T02:33:54.54.000+00:00 " diff --git a/tests/testthat/test-levels.R b/tests/testthat/test-levels.R index b91cfac..0a5d128 100644 --- a/tests/testthat/test-levels.R +++ b/tests/testthat/test-levels.R @@ -27,7 +27,7 @@ test_that("log levels work properly", { ) for (pkg_level in 1:6) { - mockery::stub(debug, "get_package_debug_level", pkg_level) + local_mocked_bindings(get_package_debug_level = function(...) pkg_level) for (idx in seq_along(fs)) { if (idx <= pkg_level) { expect_output(fs[[idx]][[2]](), fs[[idx]][[1]]) diff --git a/tests/testthat/test-package.R b/tests/testthat/test-package.R index b3f30a0..4b3008b 100644 --- a/tests/testthat/test-package.R +++ b/tests/testthat/test-package.R @@ -1,13 +1,9 @@ test_that(".onLoad", { - - val <- NULL - - mockery::stub(refresh_pkg_info, "initialize_colors", function(pkgs) val <<- pkgs) withr::with_envvar( c("DEBUGME" = c("foo,bar")), refresh_pkg_info() ) - expect_identical(val, c("foo", "bar")) + expect_identical(names(debug_data$palette), c("foo", "bar")) }) test_that("debugme", { @@ -18,13 +14,12 @@ test_that("debugme", { env$notme <- "!DEBUG nonono" env$.hidden <- function() { "!DEBUG foobar2" } - expect_silent(debugme(env)) - - mockery::stub(debugme, "is_debugged", TRUE) - debugme(env) + withr::local_envvar(DEBUGME = "debugme") + refresh_pkg_info() + debugme(env, pkg = "debugme") expect_silent(env$f1()) - expect_output(env$f2(), "debugme foobar \\+[0-9]+ms") + expect_output(env$f2(), "debugme foobar ") expect_identical(env$notme, "!DEBUG nonono") expect_output(env$.hidden(), "debugme foobar2 \\+[0-9]+ms") }) @@ -35,14 +30,14 @@ test_that("instrument environments", { env$env <- new.env() env$env$fun <- function() { "!DEBUG coocoo" } - mockery::stub(debugme, "is_debugged", TRUE) - expect_silent(debugme(env)) + withr::local_envvar(DEBUGME = "debugme") + refresh_pkg_info() + debugme(env, pkg = "debugme") expect_output(env$env$fun(), "coocoo") }) test_that("instrument R6 classes", { - env <- new.env() env$class <- R6::R6Class( "foobar", @@ -61,8 +56,9 @@ test_that("instrument R6 classes", { ) ) - mockery::stub(debugme, "is_debugged", TRUE) - expect_silent(debugme(env)) + withr::local_envvar(DEBUGME = "debugme") + refresh_pkg_info() + debugme(env, pkg = "debugme") expect_output(x <- env$class$new("mrx"), "debugme.*creating mrx") expect_output(x$hello(), "debugme.*hello mrx")