diff --git a/.travis.yml b/.travis.yml index 8632337..cf31064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ cache: packages pandoc: false -#before_script: -# - make tests +before_script: + - make tests r_github_packages: - jimhester/covr diff --git a/R/CxxFlags.R b/R/CxxFlags.R new file mode 100644 index 0000000..f83fdc5 --- /dev/null +++ b/R/CxxFlags.R @@ -0,0 +1,11 @@ +CxxFlags <- function() +{ + path <- tools::file_path_as_absolute(base::system.file("include", package = "RcppProgress")) + if (.Platform$OS.type == "windows") { + path <- base::normalizePath(path) + if (grepl(" ", path, fixed = TRUE)) + path <- utils::shortPathName(path) + path <- gsub("\\\\", "/", path) + } + cat(paste0("-I", path)) +} \ No newline at end of file diff --git a/R/wrap_examples.R b/R/wrap_examples.R new file mode 100644 index 0000000..3c88208 --- /dev/null +++ b/R/wrap_examples.R @@ -0,0 +1,47 @@ +load_my_example_pkg <- function(pkg, recompile = TRUE, ...) { + if (!requireNamespace("devtools", quietly = TRUE)) { + stop("Package devtools must be installed to run unit tests.", + call. = FALSE) + } + path <- system.file(file.path('examples', pkg), package = 'RcppProgress') + devtools::load_all(path, quiet = TRUE, recompile = recompile, ...) +} + +get_function_from_pkg <- function(pkg, fun) { + get(fun, getNamespace(pkg)) +} + +test_sequential <- function(max = 100, nb = 1000, display_progress= TRUE, ...) { + pkg <- 'RcppProgressExample' + load_my_example_pkg(pkg, ...) + fun <- get_function_from_pkg(pkg, 'test_sequential') + fun(max, nb, display_progress) +} + +# R wrapper for the example function #2 +test_multithreaded <- function(max = 100, nb = 1000, threads = 0, + display_progress = TRUE, ...) +{ + pkg <- 'RcppProgressExample' + load_my_example_pkg(pkg, ...) + fun <- get_function_from_pkg(pkg, 'test_multithreaded') + fun(max, nb, threads, display_progress) +} + +amardillo_multithreaded <- function(max = 100, nb = 1000, threads = 0, + display_progress = TRUE, ...) +{ + testthat::skip_if_not_installed('RcppArmadillo') + pkg <- 'RcppProgressArmadillo' + load_my_example_pkg(pkg, ...) + fun <- get_function_from_pkg(pkg, 'test_multithreaded') + fun(max, nb, threads, display_progress) +} + +eta_progress_bar <- function(max = 100, nb = 1000, display_progress = TRUE) +{ + pkg <- 'RcppProgressETA' + load_my_example_pkg(pkg) + fun <- get_function_from_pkg(pkg, 'test_sequential') + fun(max, nb, display_progress) +} \ No newline at end of file diff --git a/tests/testthat/test-pkg_examples.R b/tests/testthat/test-pkg_examples.R index 6e0c5b1..f7d12dc 100644 --- a/tests/testthat/test-pkg_examples.R +++ b/tests/testthat/test-pkg_examples.R @@ -1,5 +1,3 @@ -source("wrap_examples.R") - context('RcppProgressExample sequential\n') .test_sequential <- function() {