1test_that("use_cpp11() requires a package", { 2 create_local_project() 3 expect_usethis_error(use_cpp11(), "not an R package") 4}) 5 6test_that("use_cpp11() creates files/dirs, edits DESCRIPTION and .gitignore", { 7 create_local_package() 8 use_roxygen_md() 9 10 local_interactive(FALSE) 11 with_mock( 12 # Required to pass the check re: whether cpp11 is installed 13 check_installed = function(pkg) TRUE, 14 check_cpp_register_deps = function() invisible(), 15 use_cpp11() 16 ) 17 18 expect_match(desc::desc_get("LinkingTo"), "cpp11") 19 expect_proj_dir("src") 20 21 ignores <- read_utf8(proj_path("src", ".gitignore")) 22 expect_true(all(c("*.o", "*.so", "*.dll") %in% ignores)) 23}) 24 25test_that("check_cpp_register_deps is silent if all installed, emits todo if not", { 26 withr::local_options(list(usethis.quiet = FALSE)) 27 28 with_mock( 29 get_cpp_register_deps = function() c("brio", "decor", "vctrs"), 30 is_installed = function(pkg) TRUE, 31 expect_silent( 32 check_cpp_register_deps() 33 ) 34 ) 35 36 with_mock( 37 get_cpp_register_deps = function() c("brio", "decor", "vctrs"), 38 is_installed = function(pkg) pkg == "brio", 39 expect_message( 40 check_cpp_register_deps(), 41 "Now install" 42 ) 43 ) 44}) 45