Skip to content

Commit

Permalink
Merge branch 'main' into update-template
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Jun 26, 2023
2 parents 71666aa + 3084c7b commit 325e8eb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ Suggests:
devtools,
knitr,
lintr,
mockr,
rmarkdown,
rstudioapi,
testthat (>= 3.0.2),
testthat (>= 3.1.7),
usethis
VignetteBuilder:
knitr
Expand Down
13 changes: 0 additions & 13 deletions tests/testthat/_snaps/rust-siterp.md

This file was deleted.

8 changes: 4 additions & 4 deletions tests/testthat/test-rust-sitrep.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test_that("`cargo` or `rustup` are not found", {
mockr::local_mock(try_exec_cmd = function(...) {
local_mocked_bindings(try_exec_cmd = function(...) {
NA_character_
})
expect_snapshot(rust_sitrep())
})

test_that("`cargo` is found, `rustup` is missing", {
mockr::local_mock(try_exec_cmd = function(cmd, ...) {
local_mocked_bindings(try_exec_cmd = function(cmd, ...) {
if (cmd == "cargo") {
"cargo 1.0.0 (0000000 0000-00-00)"
} else {
Expand All @@ -17,7 +17,7 @@ test_that("`cargo` is found, `rustup` is missing", {
})

test_that("`rustup` is found, `cargo` is missing", {
mockr::local_mock(try_exec_cmd = function(cmd, args) {
local_mocked_bindings(try_exec_cmd = function(cmd, args) {
if (cmd == "cargo") {
NA_character_
} else if (all(args %in% "--version")) {
Expand All @@ -36,7 +36,7 @@ test_that("`rustup` is found, `cargo` is missing", {
})

test_that("`cargo` and`rustup` are found", {
mockr::local_mock(try_exec_cmd = function(cmd, args) {
local_mocked_bindings(try_exec_cmd = function(cmd, args) {
if (cmd == "cargo") {
"cargo 1.0.0 (0000000 0000-00-00)"
} else if (all(args %in% "--version")) {
Expand Down
15 changes: 6 additions & 9 deletions tests/testthat/test-use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,26 @@ test_that("use_rextendr_template() works when usethis not available", {
skip_if_not_installed("usethis")

path <- local_package("testpkg.wrap")

mockr::with_mock(
# mock that usethis installed
is_installed = function(...) TRUE,
# mock that usethis installed
with_mocked_bindings(
{
use_rextendr_template(
"_gitignore",
save_as = file.path("installed")
)
},
.env = "rextendr"
is_installed = function(...) TRUE
)

mockr::with_mock(
# mock that usethis not installed
is_installed = function(...) FALSE,
# mock that usethis not installed
with_mocked_bindings(
{
use_rextendr_template(
"_gitignore",
save_as = file.path("not_installed")
)
},
.env = "rextendr"
is_installed = function(...) FALSE
)

expect_identical(brio::read_file(file.path("installed")), brio::read_file(file.path("not_installed")))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test_that("`cargo_command_available()` returns TRUE when `try_exec_cmd()` returns not `NA`", {
mockr::local_mock(try_exec_cmd = function(...) {
local_mocked_bindings(try_exec_cmd = function(...) {
"output"
})
expect_true(cargo_command_available())
})

test_that("`cargo_command_available()` returns FALSE when `try_exec_cmd()` returns `NA`", {
mockr::local_mock(try_exec_cmd = function(...) {
local_mocked_bindings(try_exec_cmd = function(...) {
NA_character_
})
expect_false(cargo_command_available())
Expand Down

0 comments on commit 325e8eb

Please sign in to comment.