1test_that("use_rcpp() requires a package", { 2 create_local_project() 3 expect_usethis_error(use_rcpp(), "not an R package") 4}) 5 6test_that("use_rcpp() creates files/dirs, edits DESCRIPTION and .gitignore", { 7 pkg <- create_local_package() 8 use_roxygen_md() 9 10 use_rcpp() 11 expect_match(desc::desc_get("LinkingTo", pkg), "Rcpp") 12 expect_match(desc::desc_get("Imports", pkg), "Rcpp") 13 expect_proj_dir("src") 14 15 ignores <- read_utf8(proj_path("src", ".gitignore")) 16 expect_true(all(c("*.o", "*.so", "*.dll") %in% ignores)) 17}) 18 19test_that("use_rcpp_armadillo() creates Makevars files and edits DESCRIPTION", { 20 create_local_package() 21 use_roxygen_md() 22 23 local_interactive(FALSE) 24 with_mock( 25 # Required to pass the check re: whether RcppArmadillo is installed 26 check_installed = function(pkg) TRUE, 27 use_rcpp_armadillo() 28 ) 29 expect_match(desc::desc_get("LinkingTo"), "RcppArmadillo") 30 expect_proj_file("src", "Makevars") 31 expect_proj_file("src", "Makevars.win") 32}) 33 34test_that("use_rcpp_eigen() edits DESCRIPTION", { 35 create_local_package() 36 use_roxygen_md() 37 38 with_mock( 39 # Required to pass the check re: whether RcppEigen is installed 40 check_installed = function(pkg) TRUE, 41 use_rcpp_eigen() 42 ) 43 expect_match(desc::desc_get("LinkingTo"), "RcppEigen") 44}) 45 46test_that("use_src() doesn't message if not needed", { 47 create_local_package() 48 use_roxygen_md() 49 use_package_doc() 50 use_src() 51 52 withr::local_options(list(usethis.quiet = FALSE)) 53 54 expect_silent(use_src()) 55}) 56 57test_that("use_makevars() respects pre-existing Makevars", { 58 pkg <- create_local_package() 59 60 dir_create(proj_path("src")) 61 makevars_file <- proj_path("src", "Makevars") 62 makevars_win_file <- proj_path("src", "Makevars.win") 63 64 writeLines("USE_CXX = CXX11", makevars_file) 65 file_copy(makevars_file, makevars_win_file) 66 67 before_makevars_file <- read_utf8(makevars_file) 68 before_makevars_win_file <- read_utf8(makevars_win_file) 69 70 makevars_settings <- list( 71 "PKG_CXXFLAGS" = "-Wno-reorder" 72 ) 73 use_makevars(makevars_settings) 74 75 expect_identical(before_makevars_file, read_utf8(makevars_file)) 76 expect_identical(before_makevars_win_file, read_utf8(makevars_win_file)) 77}) 78 79test_that("use_makevars() creates Makevars files with appropriate configuration", { 80 pkg <- create_local_package() 81 82 makevars_settings <- list( 83 "CXX_STD" = "CXX11" 84 ) 85 use_makevars(makevars_settings) 86 87 makevars_content <- paste0(names(makevars_settings), " = ", makevars_settings) 88 89 expect_identical(makevars_content, read_utf8(proj_path("src", "Makevars"))) 90 expect_identical(makevars_content, read_utf8(proj_path("src", "Makevars.win"))) 91}) 92