1context("Imports") 2 3test_that("Imported objects are copied to package environment", { 4 load_all("testNamespace") 5 # This package imports the whole 'compiler' package, bitops::bitAnd, and 6 # bitops::bitOr. 7 imp_env <- imports_env("testNamespace") 8 9 # cmpfun is exported from compiler, so it should be in imp_env 10 expect_identical(imp_env$cmpfun, compiler::cmpfun) 11 12 # cmpSpecial is NOT exported from compiler, so it should not be in imp_env 13 expect_true(exists("cmpSpecial", asNamespace("compiler"))) 14 expect_false(exists("cmpSpecial", imp_env)) 15 16 17 # 'bitAnd' is a single object imported specifically from bitops 18 expect_true(exists("bitAnd", imp_env)) 19 20 # 'bitFlip' is not imported from bitops 21 expect_false(exists("bitFlip", imp_env)) 22 23 unload("testNamespace") 24 25 # Suppress warning from compiler for R 3.4 and above 26 suppressWarnings(unload("compiler")) 27 28 unload("bitops") 29}) 30 31 32test_that("Imported objects are be re-exported", { 33 load_all("testNamespace", export_imports = FALSE) 34 # bitAnd is imported and re-exported 35 expect_identical(bitAnd, bitops::bitAnd) 36 # bitOr is imported but not re-exported 37 expect_false(exists("bitOr", .GlobalEnv)) 38 unload("testNamespace") 39 unload("compiler") 40 unload("bitops") 41 42 # Same as previous, but with export_all = FALSE 43 load_all("testNamespace", export_all = FALSE) 44 expect_identical(bitAnd, bitops::bitAnd) 45 expect_false(exists("bitOr", .GlobalEnv)) 46 unload("testNamespace") 47 unload("compiler") 48 unload("bitops") 49 50 # If exports_imports = TRUE all imports are exported 51 load_all("testNamespace", export_imports = TRUE) 52 expect_true(exists("bitOr", .GlobalEnv)) 53 54 # This is from the import(compiler) 55 expect_true(exists("compile", .GlobalEnv)) 56}) 57