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

Fixed .BuildTestLib for covr #144

Merged
merged 1 commit into from
Dec 8, 2018
Merged
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
25 changes: 21 additions & 4 deletions R/testing_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# from the repo root if something goes wrong

# [DEBUG] write("=========", file = "~/thing.txt", append = TRUE)
# [DEBUG] write(paste0("target lib path: ", targetLibPath), file = "~/thing.txt", append = TRUE)
# [DEBUG] write(list.files(getwd(), recursive = TRUE), file = "~/thing.txt", append = TRUE)
# [DEBUG] write(paste0("working dir: ", getwd()), file = "~/thing.txt", append = TRUE)

Expand All @@ -20,18 +21,32 @@
pkgnetSourcePath <- gsub('/pkgnet.Rcheck/vign_test/pkgnet$', replacement = '/pkgnet.Rcheck/00_pkg_src/pkgnet', x = pkgnetSourcePath)
pkgnetSourcePath <- gsub('/pkgnet/vignettes$', replacement = '/pkgnet', x = pkgnetSourcePath)
pkgnetSourcePath <- gsub('pkgnet/tests/testthat', replacement = 'pkgnet', x = pkgnetSourcePath)
pkgnetSourcePath <- gsub('/pkgnet/pkgnet-tests/testthat', replacement = '/pkgnet', x = pkgnetSourcePath) # covr
pkgnetSourcePath <- gsub('/pkgnet/pkgnet-tests', replacement = '/pkgnet', x = pkgnetSourcePath) # covr

# [DEBUG] write(paste0("pkgnet path: ", pkgnetSourcePath), file = "~/thing.txt", append = TRUE)
# [DEBUG] write("=========", file = "~/thing.txt", append = TRUE)
# [DEBUG] write(list.files(pkgnetSourcePath, recursive = TRUE), file = "~/thing.txt", append = TRUE)

# Check if there is an inst directory in pkgnetSource.
# If there is an inst directory (because of raw package copy) then look in there
# for the test packages.
# Otherwise if not, it means that it's an installed package copy and the test
# packages are in the package root directory.
testPkgSourceDir <- ""
if ("inst" %in% list.files(pkgnetSourcePath)) {
testPkgSourceDir <- "inst"
}

### packages to be built
pkgList <- c(
baseballstats = file.path(pkgnetSourcePath, "inst", "baseballstats")
, sartre = file.path(pkgnetSourcePath, "inst", "sartre")
, milne = file.path(pkgnetSourcePath, "inst", "milne")
baseballstats = file.path(pkgnetSourcePath, testPkgSourceDir, "baseballstats")
, sartre = file.path(pkgnetSourcePath, testPkgSourceDir, "sartre")
, milne = file.path(pkgnetSourcePath, testPkgSourceDir, "milne")
, pkgnet = pkgnetSourcePath
)

# [DEBUG] write(paste0("Installing: ", paste(pkgList)), file = "~/thing.txt", append = TRUE)

### Install

# Figure out where R is to avoid those weird warnings about
Expand Down Expand Up @@ -71,5 +86,7 @@
))
}

# [DEBUG] write("=========", file = "~/thing.txt", append = TRUE)

return(invisible(TRUE))
}
8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ if (Sys.getenv('PKGNET_REBUILD')){
## travis checks.
## ******************************************************************************************

# [DEBUG] write("PKGNET_REBUILD triggered", file = "~/thing.txt", append = TRUE)

# record original libpaths in order to reset later.
# This should be unnecessary since tests are conducted within a seperate enviornment.
# It's done out of an abundance of caution.
Expand All @@ -39,6 +41,10 @@ if (Sys.getenv('PKGNET_REBUILD')){
targetLibPath = Sys.getenv('PKGNET_TEST_LIB')
)

# [DEBUG] write(paste0("PKGNET_TEST_LIB: ", Sys.getenv('PKGNET_TEST_LIB')), file = "~/thing.txt", append = TRUE)
# [DEBUG] write(list.files(Sys.getenv('PKGNET_TEST_LIB'), recursive = TRUE), file = "~/thing.txt", append = TRUE)


}

# This withr statement should be redundant.
Expand All @@ -57,6 +63,8 @@ if (Sys.getenv('PKGNET_REBUILD')){
## travis checks.
## ******************************************************************************************

# [DEBUG] write("PKGNET_REBUILD tear-down triggered", file = "~/thing.txt", append = TRUE)

# Uninstall Fake Packages From Test Library if Not Already Uninstalled
try(
utils::remove.packages(
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/setup_setTestEnv.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Check if the setup in testthat.R was already run
# [DEBUG] write("setup_setTestEnv.R triggered", file = "~/thing.txt", append = TRUE)

# record original libpaths in order to reset later.
# This should be unnecessary since tests are conducted within a seperate enviornment.
Expand All @@ -18,3 +20,7 @@ Sys.setenv(PKGNET_TEST_LIB = tempdir())
pkgnet:::.BuildTestLib(
targetLibPath = Sys.getenv('PKGNET_TEST_LIB')
)

# [DEBUG] write(paste0("PKGNET_TEST_LIB: ", Sys.getenv('PKGNET_TEST_LIB')), file = "~/thing.txt", append = TRUE)
# [DEBUG] write(list.files(Sys.getenv('PKGNET_TEST_LIB'), recursive = TRUE), file = "~/thing.txt", append = TRUE)

6 changes: 3 additions & 3 deletions tests/testthat/teardown_setTestEnv.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

# [DEBUG] write("teardown_setTestEnv.R triggered", file = "~/thing.txt", append = TRUE)

# Uninstall Fake Packages From Test Library if Not Already Uninstalled
try(
utils::remove.packages(
pkgs = c('baseballstats', 'sartre', 'milne', 'pkgnet')
, lib = Sys.getenv('PKGNET_TEST_LIB')
, lib = Sys.getenv('PKGNET_TEST_LIB')
)
)

Expand All @@ -14,4 +14,4 @@ try(
.libPaths(origLibPaths)

# Remove test libary path eviornment variable.
Sys.unsetenv('PKGNET_TEST_LIB')
Sys.unsetenv('PKGNET_TEST_LIB')