From a7616d662dee797c5ce3c0fce3c1b982a6864244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20V=C3=B6lkle?= Date: Wed, 11 Oct 2023 13:22:38 +0200 Subject: [PATCH 1/3] Update tests (#36) * migrate tests to testtthat edition 3 * update github actions --- .github/workflows/R-CMD-check.yaml | 23 +- DESCRIPTION | 16 +- R/chrome.R | 2 +- R/gecko.R | 2 +- R/phantom.R | 2 +- R/selenium.R | 4 +- tests/testthat.R | 7 +- tests/testthat/helper.R | 32 +++ tests/testthat/test-assertions.R | 2 - tests/testthat/test-chrome.R | 151 +++++++------ tests/testthat/test-gecko.R | 153 +++++++------ tests/testthat/test-iedriver.R | 168 ++++++++------ tests/testthat/test-phantom.R | 148 ++++++------ tests/testthat/test-selenium.R | 348 ++++++++++++----------------- tests/testthat/test-utils.R | 117 +++++----- 15 files changed, 627 insertions(+), 548 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 126acaf..026c944 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,4 +1,4 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: workflow_dispatch: @@ -30,22 +30,27 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: | - rcmdcheck + extra-packages: any::rcmdcheck + needs: check - - uses: r-lib/actions/check-r-package@v1 + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true - name: Check drivers - run: Rscript inst/etc/checks.R + run: | + Rscript -e "install.packages('devtools')" + Rscript -e "devtools::install('.')" + Rscript inst/etc/checks.R diff --git a/DESCRIPTION b/DESCRIPTION index ea86a0b..79f9b1d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,10 +3,12 @@ Type: Package Title: 'Webdriver'/'Selenium' Binary Manager Version: 0.2.6 Authors@R: c( - person("John", "Harrison", , "johndharrison0@gmail.com", - role = "aut", comment = "original author"), - person("Ju Yeong", "Kim", , "jkim2345@fredhutch.org", - role = "cre", comment = "rOpenSci maintainer")) + person("John", "Harrison", , "johndharrison0@gmail.com", role = "aut", + comment = "original author"), + person("Ju Yeong", "Kim", , "jkim2345@fredhutch.org", role = "aut", + comment = "rOpenSci maintainer"), + person("Jonathan", "Völkle", , "jonathan.voelkle@web.de", role = "cre") + ) Description: There are a number of binary files associated with the 'Webdriver'/'Selenium' project. This package provides functions to download these binaries and to manage processes involving them. @@ -15,10 +17,11 @@ Encoding: UTF-8 Depends: R (>= 3.2) Suggests: - testthat, + testthat (>= 3.1.7), covr, knitr, - rmarkdown + rmarkdown, + R6 Imports: binman, assertthat, @@ -31,3 +34,4 @@ URLNote: https://github.com/ropensci/wdman BugReports: https://github.com/ropensci/wdman/issues RoxygenNote: 7.2.1 VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/R/chrome.R b/R/chrome.R index af6e160..67a7bf0 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -126,7 +126,7 @@ chrome_check <- function(verbose, check = TRUE) { } chrome_ver <- function(platform, version) { - chromever <- binman::list_versions("chromedriver")[[platform]] + chromever <- list_versions("chromedriver")[[platform]] chromever <- if (identical(version, "latest")) { as.character(max(package_version(chromever))) } else { diff --git a/R/gecko.R b/R/gecko.R index e76b691..07d25ed 100644 --- a/R/gecko.R +++ b/R/gecko.R @@ -124,7 +124,7 @@ gecko_check <- function(verbose, check = TRUE) { } gecko_ver <- function(platform, version) { - geckover <- binman::list_versions("geckodriver")[[platform]] + geckover <- list_versions("geckodriver")[[platform]] geckover <- if (identical(version, "latest")) { as.character(max(semver::parse_version(geckover))) } else { diff --git a/R/phantom.R b/R/phantom.R index 140cb36..b2cb773 100644 --- a/R/phantom.R +++ b/R/phantom.R @@ -127,7 +127,7 @@ phantom_check <- function(verbose, check = TRUE) { } phantom_ver <- function(platform, version) { - phantomver <- binman::list_versions("phantomjs")[[platform]] + phantomver <- list_versions("phantomjs")[[platform]] phantomver <- if (identical(version, "latest")) { as.character(max(semver::parse_version(phantomver))) } else { diff --git a/R/selenium.R b/R/selenium.R index e20c5f7..106a335 100644 --- a/R/selenium.R +++ b/R/selenium.R @@ -93,7 +93,7 @@ selenium <- function(port = 4567L, ) if (isFALSE(seleniumdrv$is_alive())) { err <- paste0(readLines(pfile[["err"]]), collapse = "\n") - stop("Selenium server couldn't be started\n", err) + stop("Selenium server couldn't be started\n", err) } startlog <- generic_start_log(seleniumdrv, # poll = 10000L, outfile = pfile[["out"]], @@ -156,7 +156,7 @@ selenium_check <- function(verbose, check = TRUE) { } selenium_ver <- function(platform, version) { - selver <- binman::list_versions("seleniumserver")[[platform]] + selver <- list_versions("seleniumserver")[[platform]] selver <- if (identical(version, "latest")) { as.character(max(semver::parse_version(selver))) } else { diff --git a/tests/testthat.R b/tests/testthat.R index fdfb870..2080d3d 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,6 +1,7 @@ library(testthat) library(wdman) -# if (identical(tolower(Sys.getenv("NOT_CRAN")), "true")) { -# test_check("wdman") -# } +if (identical(tolower(Sys.getenv("NOT_CRAN")), "true")) { + test_check("wdman") +} + diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index bc045c3..5983997 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -4,6 +4,7 @@ mock_binman_list_versions_chrome <- function(...) { list( linux64 = c("2.23", "2.24", "2.25", "2.26"), mac64 = c("2.23", "2.24", "2.25"), + mac64_m1 = c("2.23", "2.24", "2.25"), win32 = c("2.23", "2.24", "2.25") ) } @@ -21,6 +22,7 @@ mock_binman_list_versions_gecko <- function(...) { list( linux64 = c("0.10.0", "0.11.0", "0.11.1"), macos = c("0.10.0", "0.11.0", "0.11.1"), + `macos-aarch64` = c("0.10.0", "0.11.0", "0.11.1"), win32 = c("0.10.0", "0.11.0", "0.11.1"), win64 = c("0.10.0", "0.11.0", "0.11.1") ) @@ -51,6 +53,35 @@ mock_binman_app_dir <- function(...) { "some.dir" } +mock_processx_process <- R6::R6Class( + "process_test", + public = list( + initialize = function(...) {}, + is_alive = function() TRUE, + test = "hello" + ) +) + +mock_processx_process_fail <- R6::R6Class( + "process_test", + public = list( + initialize = function(...) {}, + is_alive = function() FALSE + ) +) + +mock_generic_check <- function(...) { + list(platform = "some.plat") +} + +mock_generic_ver <- function(...) { + list(path = "some.path") +} + +mock_base_Sys.info_windows <- function(...) { + structure("Windows", .Names = "sysname") +} + mock_subprocess_spawn_process <- function(...) { "hello" } @@ -75,3 +106,4 @@ mock_subprocess_process_read_utils <- function(...) { mock_generic_start_log <- function(...) { list(stdout = "super duper", stderr = "no error here") } + diff --git a/tests/testthat/test-assertions.R b/tests/testthat/test-assertions.R index aa2da1b..2e64e0c 100644 --- a/tests/testthat/test-assertions.R +++ b/tests/testthat/test-assertions.R @@ -1,5 +1,3 @@ -context("test-assertions") - test_that("assertionsWork", { expect_error(assertthat::assert_that(is_list("")), "is not a list") expect_error( diff --git a/tests/testthat/test-chrome.R b/tests/testthat/test-chrome.R index b4898fe..5cf3e46 100644 --- a/tests/testthat/test-chrome.R +++ b/tests/testthat/test-chrome.R @@ -1,36 +1,43 @@ -context("chrome") - normalizePath <- function(...) base::normalizePath(...) list.files <- function(...) base::list.files(...) test_that("canCallChrome", { - with_mock( - `binman::process_yaml` = binman_process_yaml, - `binman::list_versions` = mock_binman_list_versions_chrome, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_chrome, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = mock_generic_start_log, - `wdman:::infun_read` = function(...) { + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + infun_read = function(...) { "infun" }, - { - cDrv <- chrome() - retCommand <- chrome(retcommand = TRUE) - expect_identical(cDrv$output(), "infun") - expect_identical(cDrv$error(), "infun") - logOut <- cDrv$log()[["stdout"]] - logErr <- cDrv$log()[["stderr"]] - expect_identical(logOut, "super duper") - expect_identical(logErr, "no error here") - expect_identical(cDrv$stop(), "stopped") - } - ) - expect_identical(cDrv$process, "hello") + kill_process = mock_subprocess_process_kill, + ) + + cDrv <- chrome() + retCommand <- chrome(retcommand = TRUE) + expect_identical(cDrv$output(), "infun") + expect_identical(cDrv$error(), "infun") + logOut <- cDrv$log()[["stdout"]] + logErr <- cDrv$log()[["stderr"]] + expect_identical(logOut, "super duper") + expect_identical(logErr, "no error here") + expect_identical(cDrv$stop(), "stopped") + expect_identical(cDrv$process$test, "hello") expect_identical( retCommand, "some.path --port=4567 --url-base=wd/hub --verbose" @@ -38,59 +45,73 @@ test_that("canCallChrome", { }) test_that("chrome_verErrorWorks", { - with_mock( - `binman::list_versions` = mock_binman_list_versions_chrome, - expect_error( - wdman:::chrome_ver("linux64", "noversion"), - "doesnt match versions" - ) + local_mocked_bindings( + list_versions = mock_binman_list_versions_chrome, + ) + + expect_error( + wdman:::chrome_ver("linux64", "noversion"), + "doesnt match versions" ) }) test_that("pickUpErrorFromReturnCode", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_chrome, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_chrome, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = function(...) { - "some error" - }, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = mock_generic_start_log, - { - expect_error( - chrome(version = "2.24"), - "Chromedriver couldn't be started" - ) - } + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process_fail, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + ) + + expect_error( + chrome(), + "Chromedriver couldn't be started" ) }) test_that("pickUpErrorFromPortInUse", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_chrome, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_chrome, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = function(...) { + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { list(stderr = "Address already in use") }, - { - expect_error( - chrome(version = "2.24"), - "Chrome Driver signals port" - ) - } + kill_process = mock_subprocess_process_kill + ) + + expect_error( + chrome(), + "Chrome Driver signals port" ) }) diff --git a/tests/testthat/test-gecko.R b/tests/testthat/test-gecko.R index e117da0..9332e42 100644 --- a/tests/testthat/test-gecko.R +++ b/tests/testthat/test-gecko.R @@ -1,36 +1,43 @@ -context("gecko") - normalizePath <- function(...) base::normalizePath(...) list.files <- function(...) base::list.files(...) test_that("canCallGecko", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_gecko, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_gecko, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = mock_generic_start_log, - `wdman:::infun_read` = function(...) { + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + infun_read = function(...) { "infun" }, - { - gDrv <- gecko() - retCommand <- gecko(retcommand = TRUE) - expect_identical(gDrv$output(), "infun") - expect_identical(gDrv$error(), "infun") - logOut <- gDrv$log()[["stdout"]] - logErr <- gDrv$log()[["stderr"]] - expect_identical(logOut, "super duper") - expect_identical(logErr, "no error here") - expect_identical(gDrv$stop(), "stopped") - } - ) - expect_identical(gDrv$process, "hello") + kill_process = mock_subprocess_process_kill, + ) + + gDrv <- gecko() + retCommand <- gecko(retcommand = TRUE) + expect_identical(gDrv$output(), "infun") + expect_identical(gDrv$error(), "infun") + logOut <- gDrv$log()[["stdout"]] + logErr <- gDrv$log()[["stderr"]] + expect_identical(logOut, "super duper") + expect_identical(logErr, "no error here") + expect_identical(gDrv$stop(), "stopped") + expect_identical(gDrv$process$test, "hello") expect_identical( retCommand, "some.path --port=4567 --log=info" @@ -38,59 +45,73 @@ test_that("canCallGecko", { }) test_that("gecko_verErrorWorks", { - with_mock( - `binman::list_versions` = mock_binman_list_versions_gecko, - expect_error( - wdman:::gecko_ver("linux64", "noversion"), - "doesnt match versions" - ) + local_mocked_bindings( + list_versions = mock_binman_list_versions_gecko, + ) + + expect_error( + wdman:::gecko_ver("linux64", "noversion"), + "doesnt match versions" ) }) test_that("pickUpErrorFromReturnCode", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_gecko, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_gecko, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = function(...) { - "some error" - }, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = mock_generic_start_log, - { - expect_error( - gecko(version = "0.11.0"), - "Geckodriver couldn't be started" - ) - } + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process_fail, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + ) + + expect_error( + gecko(), + "Geckodriver couldn't be started" ) }) test_that("pickUpErrorFromPortInUse", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_gecko, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_gecko, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = function(...) { - list(stderr = "Address in use") + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { + list(stderr = "Address already in use") }, - { - expect_error( - gecko(version = "0.11.0"), - "Gecko Driver signals port" - ) - } + kill_process = mock_subprocess_process_kill + ) + + expect_error( + gecko(), + "Gecko Driver signals port" ) }) diff --git a/tests/testthat/test-iedriver.R b/tests/testthat/test-iedriver.R index 0d8b153..bb1ae4e 100644 --- a/tests/testthat/test-iedriver.R +++ b/tests/testthat/test-iedriver.R @@ -1,103 +1,137 @@ -context("iedriver") - normalizePath <- function(...) base::normalizePath(...) list.files <- function(...) base::list.files(...) Sys.info <- function(...) base::Sys.info(...) test_that("canCallIEDriver", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_iedriver, - `binman::app_dir` = mock_binman_app_dir, + skip_on_os(c("mac", "linux")) + + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_iedriver, + app_dir = mock_binman_app_dir, + .package = "binman" + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_kill` = mock_subprocess_process_kill, Sys.info = function(...) { structure("Windows", .Names = "sysname") }, - `wdman:::generic_start_log` = mock_generic_start_log, - `wdman:::infun_read` = function(...) { + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + infun_read = function(...) { "infun" }, - { - ieDrv <- iedriver() - retCommand <- iedriver(retcommand = TRUE) - expect_identical(ieDrv$output(), "infun") - expect_identical(ieDrv$error(), "infun") - logOut <- ieDrv$log()[["stdout"]] - logErr <- ieDrv$log()[["stderr"]] - expect_identical(logOut, "super duper") - expect_identical(logErr, "no error here") - expect_identical(ieDrv$stop(), "stopped") - } - ) - expect_identical(ieDrv$process, "hello") + kill_process = mock_subprocess_process_kill, + ) + + ieDrv <- iedriver() + retCommand <- iedriver(retcommand = TRUE) + expect_identical(ieDrv$output(), "infun") + expect_identical(ieDrv$error(), "infun") + logOut <- ieDrv$log()[["stdout"]] + logErr <- ieDrv$log()[["stderr"]] + expect_identical(logOut, "super duper") + expect_identical(logErr, "no error here") + expect_identical(ieDrv$stop(), "stopped") + expect_identical(ieDrv$process$test, "hello") expect_true(grepl("some.path /port=4567 /log-level=FATAL", retCommand)) }) + test_that("iedriver_verErrorWorks", { - with_mock( - `binman::list_versions` = mock_binman_list_versions_iedriver, - expect_error( - wdman:::ie_ver("linux64", "noversion"), - "doesnt match versions" - ) + local_mocked_bindings( + list_versions = mock_binman_list_versions_iedriver, + .package = "binman" + ) + + expect_error( + wdman:::ie_ver("linux64", "noversion"), + "doesnt match versions" ) }) + test_that("pickUpErrorFromReturnCode", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_iedriver, - `binman::app_dir` = mock_binman_app_dir, + skip_on_os(c("mac", "linux")) + + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_iedriver, + app_dir = mock_binman_app_dir, + .package = "binman" + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = function(...) { - "some error" - }, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = mock_generic_start_log, Sys.info = function(...) { structure("Windows", .Names = "sysname") }, - { - expect_error( - iedriver(version = "3.0.0"), - "iedriver couldn't be started" - ) - } + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process_fail, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + ) + + expect_error( + iedriver(), + "iedriver couldn't be started" ) }) + test_that("pickUpErrorFromPortInUse", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_iedriver, - `binman::app_dir` = mock_binman_app_dir, + skip_on_os(c("mac", "linux")) + + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_iedriver, + app_dir = mock_binman_app_dir, + .package = "binman" + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = function(...) { - list(stderr = "Address in use") - }, Sys.info = function(...) { structure("Windows", .Names = "sysname") }, - { - expect_error( - iedriver(version = "3.0.0"), - "IE Driver signals port" - ) - } + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { + list(stderr = "Address already in use") + }, + kill_process = mock_subprocess_process_kill + ) + + expect_error( + iedriver(), + "IE Driver signals port" ) }) diff --git a/tests/testthat/test-phantom.R b/tests/testthat/test-phantom.R index 3859c39..51d7386 100644 --- a/tests/testthat/test-phantom.R +++ b/tests/testthat/test-phantom.R @@ -1,37 +1,42 @@ -context("phantom") - normalizePath <- function(...) base::normalizePath(...) list.files <- function(...) base::list.files(...) - test_that("canCallPhantomJS", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_phantomjs, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_phantomjs, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = mock_generic_start_log, - `wdman:::infun_read` = function(...) { + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + infun_read = function(...) { "infun" }, - { - pDrv <- phantomjs(version = "latest") - retCommand <- phantomjs(version = "latest", retcommand = TRUE) - expect_identical(pDrv$output(), "infun") - expect_identical(pDrv$error(), "infun") - logOut <- pDrv$log()[["stdout"]] - logErr <- pDrv$log()[["stderr"]] - expect_identical(logOut, "super duper") - expect_identical(logErr, "no error here") - expect_identical(pDrv$stop(), "stopped") - } - ) - expect_identical(pDrv$process, "hello") + kill_process = mock_subprocess_process_kill, + ) + pDrv <- phantomjs(version = "latest") + retCommand <- phantomjs(version = "latest", retcommand = TRUE) + expect_identical(pDrv$output(), "infun") + expect_identical(pDrv$error(), "infun") + logOut <- pDrv$log()[["stdout"]] + logErr <- pDrv$log()[["stderr"]] + expect_identical(logOut, "super duper") + expect_identical(logErr, "no error here") + expect_identical(pDrv$stop(), "stopped") + expect_identical(pDrv$process$test, "hello") expect_identical( retCommand, "some.path --webdriver=4567 --webdriver-loglevel=INFO" @@ -39,59 +44,70 @@ test_that("canCallPhantomJS", { }) test_that("phantom_verErrorWorks", { - with_mock( - `binman::list_versions` = mock_binman_list_versions_phantomjs, - expect_error( - wdman:::phantom_ver("linux64", "noversion"), - "doesnt match versions" - ) + local_mocked_bindings( + list_versions = mock_binman_list_versions_phantomjs, + ) + expect_error( + wdman:::phantom_ver("linux64", "noversion"), + "doesnt match versions" ) }) test_that("pickUpErrorFromReturnCode", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_phantomjs, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_phantomjs, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = function(...) { - "some error" - }, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = mock_generic_start_log, - { - expect_error( - phantomjs(version = "2.1.1"), - "PhantomJS couldn't be started" - ) - } + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process_fail, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + ) + expect_error( + phantomjs(), + "PhantomJS couldn't be started" ) }) test_that("pickUpErrorFromPortInUse", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_phantomjs, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_phantomjs, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = function(...) { + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { list(stdout = "GhostDriver - main.fail.*sourceURL") }, - { - expect_error( - phantomjs(version = "2.1.1"), - "PhantomJS signals port" - ) - } + kill_process = mock_subprocess_process_kill + ) + expect_error( + phantomjs(version = "2.1.1"), + "PhantomJS signals port" ) }) diff --git a/tests/testthat/test-selenium.R b/tests/testthat/test-selenium.R index 2005b81..b7aab50 100644 --- a/tests/testthat/test-selenium.R +++ b/tests/testthat/test-selenium.R @@ -1,71 +1,54 @@ -context("selenium") - normalizePath <- function(...) base::normalizePath(...) list.files <- function(...) base::list.files(...) Sys.info <- function(...) base::Sys.info(...) Sys.which <- function(...) base::Sys.which(...) test_that("canCallSelenium", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_selenium, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_selenium, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = mock_generic_start_log, - `wdman:::infun_read` = function(...) { + Sys.info = mock_base_Sys.info_windows, + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + infun_read = function(...) { "infun" }, - Sys.info = function(...) { - structure("Windows", .Names = "sysname") - }, - # CHROME - `wdman:::chrome_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::chrome_ver` = function(...) { - list(path = "some.path") - }, - # GECKO - `wdman:::gecko_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::gecko_ver` = function(...) { - list(path = "some.path") - }, - # PHANTOMJS - `wdman:::phantom_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::phantom_ver` = function(...) { - list(path = "some.path") - }, - # INTERNET EXPLORER - `wdman:::ie_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::ie_ver` = function(...) { - list(path = "some.path") - }, - { - selServ <- selenium(iedrver = "latest") - retCommand <- selenium(iedrver = "latest", retcommand = TRUE) - expect_identical(selServ$output(), "infun") - expect_identical(selServ$error(), "infun") - logOut <- selServ$log()[["stdout"]] - logErr <- selServ$log()[["stderr"]] - expect_identical(logOut, "super duper") - expect_identical(logErr, "no error here") - expect_identical(selServ$stop(), "stopped") - } + kill_process = mock_subprocess_process_kill, + chrome_check = mock_generic_check, + chrome_ver = mock_generic_ver, + gecko_check = mock_generic_check, + gecko_ver = mock_generic_ver, + phantom_check = mock_generic_check, + phantom_ver = mock_generic_ver, + ie_check = mock_generic_check, + ie_ver = mock_generic_ver, ) - expect_identical(selServ$process, "hello") + + selServ <- selenium(iedrver = "latest") + retCommand <- selenium(iedrver = "latest", retcommand = TRUE) + expect_identical(selServ$output(), "infun") + expect_identical(selServ$error(), "infun") + logOut <- selServ$log()[["stdout"]] + logErr <- selServ$log()[["stderr"]] + expect_identical(logOut, "super duper") + expect_identical(logErr, "no error here") + expect_identical(selServ$stop(), "stopped") + expect_identical(selServ$process$test, "hello") exRet <- "-Dwebdriver.chrome.driver='some.path' " %+% "-Dwebdriver.gecko.driver='some.path' " %+% "-Dphantomjs.binary.path='some.path' " %+% @@ -79,178 +62,143 @@ test_that("canCallSelenium", { }) test_that("errorIfJavaNotFound", { - with_mock( + local_mocked_bindings( Sys.which = function(...) { "" }, - expect_error(selenium(), "PATH to JAVA not found") + .package = "base" ) + + expect_error(selenium(), "PATH to JAVA not found") }) test_that("errorIfVersionNotFound", { - with_mock( + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_selenium, + ) + local_mocked_bindings( Sys.which = function(...) { "im here" }, - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_selenium, - expect_error( - selenium(version = "nothere"), - "version requested doesnt match versions available" - ) + .package = "base" + ) + + expect_error( + selenium(version = "nothere"), + "version requested doesnt match versions available" ) }) test_that("pickUpErrorFromReturnCode", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_selenium, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_selenium, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = function(...) { - "some error" - }, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = mock_generic_start_log, - Sys.info = function(...) { - structure("Windows", .Names = "sysname") - }, - # CHROME - `wdman:::chrome_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::chrome_ver` = function(...) { - list(path = "some.path") - }, - # GECKO - `wdman:::gecko_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::gecko_ver` = function(...) { - list(path = "some.path") - }, - # PHANTOMJS - `wdman:::phantom_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::phantom_ver` = function(...) { - list(path = "some.path") - }, - # INTERNET EXPLORER - `wdman:::ie_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::ie_ver` = function(...) { - list(path = "some.path") - }, - expect_error( - selenium(version = "3.0.1", iedrver = "latest"), - "Selenium server couldn't be started" - ) + Sys.info = mock_base_Sys.info_windows, + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process_fail, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = mock_generic_start_log, + chrome_check = mock_generic_check, + chrome_ver = mock_generic_ver, + gecko_check = mock_generic_check, + gecko_ver = mock_generic_ver, + phantom_check = mock_generic_check, + phantom_ver = mock_generic_ver, + ie_check = mock_generic_check, + ie_ver = mock_generic_ver, + ) + + expect_error( + selenium(version = "3.0.1", iedrver = "latest"), + "Selenium server couldn't be started" ) }) test_that("pickUpErrorFromPortInUse", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_selenium, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_selenium, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `subprocess::process_kill` = mock_subprocess_process_kill, - `wdman:::generic_start_log` = function(...) { + Sys.info = mock_base_Sys.info_windows, + .package = "base" + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { list(stderr = "Address already in use") }, - Sys.info = function(...) { - structure("Windows", .Names = "sysname") - }, - # CHROME - `wdman:::chrome_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::chrome_ver` = function(...) { - list(path = "some.path") - }, - # GECKO - `wdman:::gecko_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::gecko_ver` = function(...) { - list(path = "some.path") - }, - # PHANTOMJS - `wdman:::phantom_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::phantom_ver` = function(...) { - list(path = "some.path") - }, - # INTERNET EXPLORER - `wdman:::ie_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::ie_ver` = function(...) { - list(path = "some.path") - }, - expect_error(selenium(), "Selenium server signals port") + kill_process = mock_subprocess_process_kill, + chrome_check = mock_generic_check, + chrome_ver = mock_generic_ver, + gecko_check = mock_generic_check, + gecko_ver = mock_generic_ver, + phantom_check = mock_generic_check, + phantom_ver = mock_generic_ver, + ie_check = mock_generic_check, + ie_ver = mock_generic_ver, ) + + expect_error(selenium(), "Selenium server signals port") }) test_that("pickUpWarningOnNoStderr", { - with_mock( - `binman::process_yaml` = function(...) {}, - `binman::list_versions` = mock_binman_list_versions_selenium, - `binman::app_dir` = mock_binman_app_dir, + local_mocked_bindings( + process_yaml = binman_process_yaml, + list_versions = mock_binman_list_versions_selenium, + app_dir = mock_binman_app_dir, + ) + local_mocked_bindings( normalizePath = mock_base_normalizePath, list.files = mock_base_list.files, - `subprocess::spawn_process` = mock_subprocess_spawn_process, - `subprocess::process_return_code` = - mock_subprocess_process_return_code, - `subprocess::process_read` = - mock_subprocess_process_read_selenium, - `wdman:::generic_start_log` = - function(...) { - list(stdout = character(), stderr = character()) - }, - Sys.info = function(...) { - structure("Windows", .Names = "sysname") - }, - # CHROME - `wdman:::chrome_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::chrome_ver` = function(...) { - list(path = "some.path") - }, - # GECKO - `wdman:::gecko_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::gecko_ver` = function(...) { - list(path = "some.path") - }, - # PHANTOMJS - `wdman:::phantom_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::phantom_ver` = function(...) { - list(path = "some.path") - }, - # INTERNET EXPLORER - `wdman:::ie_check` = function(...) { - list(platform = "some.plat") - }, - `wdman:::ie_ver` = function(...) { - list(path = "some.path") - }, - expect_warning(selenium(), "No output to stderr yet detected") + Sys.info = mock_base_Sys.info_windows, + .package = "base", + ) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" ) + local_mocked_bindings( + process = mock_processx_process, + .package = "processx" + ) + local_mocked_bindings( + generic_start_log = function(...) { + list(stdout = character(), stderr = character()) + }, + chrome_check = mock_generic_check, + chrome_ver = mock_generic_ver, + gecko_check = mock_generic_check, + gecko_ver = mock_generic_ver, + phantom_check = mock_generic_check, + phantom_ver = mock_generic_ver, + ie_check = mock_generic_check, + ie_ver = mock_generic_ver, + ) + + expect_warning(selenium(), "No output to stderr yet detected") }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index dd7ab84..15c2dd7 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,57 +1,43 @@ -context("utils") - test_that("canCallInfun_read", { - with_mock( - `subprocess::process_read` = function(handle, pipe, ...) { + local_mocked_bindings( + read_pipes = function(pipe, ...) { out <- list() - if (pipe %in% c(subprocess::PIPE_STDOUT)) { + if (pipe %in% c("stdout")) { return("stdout here") } - if (pipe %in% c(subprocess::PIPE_STDERR)) { + if (pipe %in% c("stderr")) { return("stderr here") } - if (pipe %in% c(subprocess::PIPE_BOTH)) { + if (pipe %in% c("both")) { return(list(stdout = "stdout here", stderr = "stderr here")) } }, - `wdman:::read_pipes` = function(pipe, ...) { - out <- list() - if (pipe %in% c(subprocess::PIPE_STDOUT)) { - return("stdout here") - } - if (pipe %in% c(subprocess::PIPE_STDERR)) { - return("stderr here") - } - if (pipe %in% c(subprocess::PIPE_BOTH)) { - return(list(stdout = "stdout here", stderr = "stderr here")) - } - }, - { - testenv <- new.env() - ifout <- wdman:::infun_read( - handle = "", - pipe = subprocess::PIPE_STDOUT, - env = testenv, outfile = "", - errfile = "" - ) - iferr <- wdman:::infun_read( - handle = "", - pipe = subprocess::PIPE_STDERR, - env = testenv, outfile = "", - errfile = "" - ) - ifboth <- wdman:::infun_read( - handle = "", - pipe = subprocess::PIPE_BOTH, - env = testenv, outfile = "", - errfile = "" - ) - expect_identical(ifboth, list( - stdout = "stdout here", - stderr = "stderr here" - )) - } + .package = "wdman" + ) + testenv <- new.env() + ifout <- wdman:::infun_read( + handle = "", + pipe = "stdout", + env = testenv, outfile = "", + errfile = "" ) + iferr <- wdman:::infun_read( + handle = "", + pipe = "stderr", + env = testenv, outfile = "", + errfile = "" + ) + ifboth <- wdman:::infun_read( + handle = "", + pipe = "both", + env = testenv, outfile = "", + errfile = "" + ) + expect_identical(ifboth, list( + stdout = "stdout here", + stderr = "stderr here" + )) + expect_identical(ifout, "stdout here") expect_identical(iferr, "stderr here") expect_identical(ifboth, list( @@ -63,14 +49,15 @@ test_that("canCallInfun_read", { rm(testenv) }) + test_that("canCallGeneric_start_log", { - with_mock( - `subprocess::process_read` = mock_subprocess_process_read_utils, - `wdman:::read_pipes` = mock_subprocess_process_read_utils, - out <- generic_start_log("", - poll = 1500L, outfile = "", - errfile = "" - ) + local_mocked_bindings( + read_pipes = mock_subprocess_process_read_utils, + .package = "wdman" + ) + out <- generic_start_log("", + poll = 1500L, outfile = "", + errfile = "" ) expect_identical(out, list(stdout = character(), stderr = character())) }) @@ -83,10 +70,10 @@ test_that("canRead_pipes", { write(c("world", "i am err"), errfile) env <- list(stdout = "hello", stderr = "world") bothres <- read_pipes(env, outfile, errfile, timeout = 20) - outres <- read_pipes(env, outfile, errfile, subprocess::PIPE_STDOUT, + outres <- read_pipes(env, outfile, errfile, "stdout", timeout = 20 ) - errres <- read_pipes(env, outfile, errfile, subprocess::PIPE_STDERR, + errres <- read_pipes(env, outfile, errfile, "stderr", timeout = 20 ) expect_identical(bothres, list(stdout = "i am out", stderr = "i am err")) @@ -94,20 +81,32 @@ test_that("canRead_pipes", { expect_identical(errres, "i am err") }) + test_that("canWindows_spawn_tofile", { outfile <- tempfile(fileext = ".txt") errfile <- tempfile(fileext = ".txt") - with_mock( - `subprocess::spawn_process` = function(command, ...) { - readLines(command) - }, - out <- windows_spawn_tofile("hello", "world", outfile, errfile) + local_mocked_bindings( + check_bindings = function(...) {}, + .package = "testthat" + ) + local_mocked_bindings( + process = R6::R6Class( + "process_test", + public = list( + initialize = function(command, ...) { + self$res <- readLines(command) + }, + res = list() + ) + ), + .package = "processx" ) + out <- windows_spawn_tofile("hello", "world", outfile, errfile) exRes <- paste(c( shQuote("hello"), "world", ">", shQuote(outfile), "2>", shQuote(errfile) ), collapse = " " ) - expect_identical(out, exRes) + expect_identical(out$res, exRes) }) From a4c1d7eb1938ea8a9e922f8cdb9e6199619af00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20V=C3=B6lkle?= Date: Wed, 11 Oct 2023 13:38:08 +0200 Subject: [PATCH 2/3] fix java_check if runtime missing (#37) --- R/selenium.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/selenium.R b/R/selenium.R index 106a335..027c050 100644 --- a/R/selenium.R +++ b/R/selenium.R @@ -142,6 +142,10 @@ java_check <- function() { if (identical(unname(javapath), "")) { stop("PATH to JAVA not found. Please check JAVA is installed.") } + java_version <- suppressWarnings(system2(Sys.which("java"), "-version", stdout = TRUE, stderr = TRUE)) + if (!is.null(attr(java_version, "status"))) { + stop(paste(java_version, collapse = "\n")) + } javapath } From 47e590548f7370f0d4f54a1cd025193dde5d7e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20V=C3=B6lkle?= Date: Wed, 11 Oct 2023 13:57:33 +0200 Subject: [PATCH 3/3] Fix missing java runtime (#38) * fix java_check if runtime missing * fix mock of java_check --- R/selenium.R | 2 +- tests/testthat/test-selenium.R | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/R/selenium.R b/R/selenium.R index 027c050..687b755 100644 --- a/R/selenium.R +++ b/R/selenium.R @@ -142,7 +142,7 @@ java_check <- function() { if (identical(unname(javapath), "")) { stop("PATH to JAVA not found. Please check JAVA is installed.") } - java_version <- suppressWarnings(system2(Sys.which("java"), "-version", stdout = TRUE, stderr = TRUE)) + java_version <- suppressWarnings(system2(javapath, "-version", stdout = TRUE, stderr = TRUE)) if (!is.null(attr(java_version, "status"))) { stop(paste(java_version, collapse = "\n")) } diff --git a/tests/testthat/test-selenium.R b/tests/testthat/test-selenium.R index b7aab50..ce2b7d9 100644 --- a/tests/testthat/test-selenium.R +++ b/tests/testthat/test-selenium.R @@ -78,10 +78,9 @@ test_that("errorIfVersionNotFound", { list_versions = mock_binman_list_versions_selenium, ) local_mocked_bindings( - Sys.which = function(...) { + java_check = function(...) { "im here" }, - .package = "base" ) expect_error(