1context("Namespace") 2 3if (file.exists("../../00check.log")) { 4 # test was invoked by R CMD check -> package is already built 5 R_test_lib <- normalizePath("../..") 6 env <- paste0("R_LIBS=", R_test_lib, ":", Sys.getenv("R_LIBS")) 7} else { 8 # We're testing in the source directory -> need to build and install 9 R_test_lib <- file.path(tempdir(), "Rlib") 10 env <- "" 11 ## dir.create(R_test_lib) 12 ## on.exit(unlink(R_test_lib, recursive = TRUE)) 13 ## system2( 14 ## "R", 15 ## c("CMD install", 16 ## paste0("--library=", R_test_lib), 17 ## "--no-docs --no-help --no-demo --no-data --no-test-load", 18 ## normalizePath("../..")), 19 ## stdout = TRUE, stderr = TRUE) 20} 21 22do_Rscript <- function(expr) { 23 rscript <- sprintf("%s/bin/Rscript", Sys.getenv("R_HOME")) 24 paste( 25 system2(rscript, 26 args = c("--vanilla", "--default-packages=NULL", "-e", shQuote(expr)), 27 env = c("R_TESTS=", env), 28 stdout = TRUE, stderr = TRUE), 29 collapse = "\n") 30} 31 32test_that("methods is not attached", { 33 skip_on_cran() 34 skip_on_os("windows") 35 # Checking test assumptions. 36 # If this fails, namespace tests may not be needed anymore! 37 expect_match( 38 do_Rscript("'package:methods' %in% search()"), 39 "FALSE") 40}) 41 42test_that("lubridate:: calls work when methods is not attached", { 43 skip_on_cran() 44 skip_on_os("windows") 45 expect_match( # https://github.com/tidyverse/lubridate/issues/314 46 do_Rscript( 47 "lubridate::round_date(as.POSIXct('2017-10-03 03:01:13Z'), 'minute')"), 48 as.character(round_date(as.POSIXct('2017-10-03 03:01:13Z'), 'minute')), 49 fixed = TRUE) 50 expect_match( # https://github.com/tidyverse/lubridate/issues/407 51 do_Rscript("lubridate::days(1)"), 52 as.character(days(1)), 53 fixed = TRUE) 54 expect_match( # https://github.com/tidyverse/lubridate/issues/499 55 do_Rscript("lubridate::dhours(22)"), 56 as.character(dhours(22)), 57 fixed = TRUE) 58}) 59