Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #25 #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cache: packages

pandoc: false

#before_script:
# - make tests
before_script:
- make tests

r_github_packages:
- jimhester/covr
Expand Down
11 changes: 11 additions & 0 deletions R/CxxFlags.R
Original file line number Diff line number Diff line change
@@ -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))
}
47 changes: 47 additions & 0 deletions R/wrap_examples.R
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 0 additions & 2 deletions tests/testthat/test-pkg_examples.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source("wrap_examples.R")

context('RcppProgressExample sequential\n')

.test_sequential <- function() {
Expand Down