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