-
Notifications
You must be signed in to change notification settings - Fork 37
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
Package Testing and Vignette Building Within Temporary Directory #108
Changes from all commits
3860f13
78a467a
a87c23b
01569f3
432b6ca
58a5854
65e7433
7141667
fbbadaf
60b536c
ddae8f8
12b6dc6
0f4e8c0
17beeab
4cfcb8b
40b3473
5e7c3b0
6453424
8228f3b
b40cef0
b65adfc
04a611c
d2dbe55
3d55c34
67bdfc0
caf2dcd
313bbd0
6bde9f8
2df7b25
f5896aa
c067181
bc05824
54406f7
4063569
1eb876e
5255c05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
|
||
# Misc files | ||
.Rhistory | ||
tests/testthat/Rplots.pdf | ||
**/.DS_Store | ||
|
||
# data files | ||
**/*.rds | ||
**/*.rda | ||
**/*.csv | ||
|
||
# build artifacts | ||
**/*.tar.gz | ||
pkgnet.Rcheck/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
# [Title] Build A Library For Testing | ||
# [DESC] Installs all packages necessary for testing into a another directory, | ||
# preferably a temporary directory. This function will throw a fatal error | ||
# if that installation fails. | ||
# [param] targetLibPath (string) path to the location of the new directory | ||
# [return] boolean TRUE | ||
.BuildTestLib <- function(targetLibPath){ | ||
|
||
### find PKGNET source dir within devtools::test(), R CMD CHECK, and vignette building | ||
# NOTE: this can be fragile. Uncomment the lines with "# [DEBUG]" and run test.sh | ||
# from the repo root if something goes wrong | ||
|
||
# [DEBUG] write("=========", 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) | ||
|
||
pkgnetSourcePath <- gsub('/pkgnet.Rcheck/tests/testthat$', replacement = '/pkgnet.Rcheck/00_pkg_src/pkgnet', x = getwd()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should circle back later (post merge), and see if there's a better way to do this as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I agree. One thing that I think would be useful is to figure out if we can move this whole file out of the package source code. maybe store it in |
||
pkgnetSourcePath <- gsub('/pkgnet.Rcheck/tests$', replacement = '/pkgnet.Rcheck/00_pkg_src/pkgnet', x = pkgnetSourcePath) | ||
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) | ||
|
||
# [DEBUG] write(paste0("pkgnet path: ", pkgnetSourcePath), file = "~/thing.txt", append = TRUE) | ||
# [DEBUG] write("=========", file = "~/thing.txt", append = TRUE) | ||
|
||
### packages to be built | ||
pkgList <- c( | ||
baseballstats = file.path(pkgnetSourcePath, "inst", "baseballstats") | ||
, sartre = file.path(pkgnetSourcePath, "inst", "sartre") | ||
, pkgnet = pkgnetSourcePath | ||
) | ||
|
||
### Install | ||
|
||
# Figure out where R is to avoid those weird warnings about | ||
# 'R' should not be used without a path -- see par. 1.6 of the manual. | ||
# | ||
# NOTE: R CMD CHECK comes with its own bundled "R" binary which doesn't | ||
# work the same way and causes that error. Just trust me on this. | ||
# | ||
# NOTE: "Sys.which()" would be the correct, portable way to do this but it | ||
# doesn't support matching ALL matches, so for now we'll make it work | ||
# on unix-alike operating systems and deal with Windows later | ||
# | ||
R_LOC <- system("which -a R", intern = TRUE) | ||
R_LOC <- R_LOC[!grepl("R_check_bin", R_LOC)][1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jayqi @bburns632 this part was the main culprit. Some other This thing I did here totally works (for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😱 |
||
|
||
# force install of SOURCE (not binary) in temporary directory for tests | ||
cmdstr <- sprintf( | ||
fmt = '"%s" CMD INSTALL -l "%s" %s' | ||
, R_LOC | ||
, targetLibPath | ||
, paste0(pkgList, collapse = " ") | ||
) | ||
|
||
exitCode <- system(command = cmdstr, intern = FALSE) | ||
|
||
if (exitCode != 0){ | ||
|
||
# Get the actual error text | ||
output <- system(command = cmdstr, intern = TRUE) | ||
stop(sprintf( | ||
"Installation of packages in .BuildTestLib failed! (exit code = %s)\n\n%s" | ||
, exitCode | ||
, paste0(output, collapse = " ... ") | ||
)) | ||
} | ||
|
||
return(invisible(TRUE)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
rm *.tar.gz | ||
rm ~/thing.txt | ||
R CMD BUILD . | ||
|
||
# Work outside of the source directory to avoid false | ||
# positives (i.e. test the tarball in isolation) | ||
mkdir -p ~/pkgnet_test_dir | ||
cp *.tar.gz ~/Desktop | ||
|
||
pushd ~/pkgnet_test_dir | ||
R CMD CHECK *.tar.gz --as-cran | ||
cat ~/thing.txt | ||
popd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
# 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. | ||
origLibPaths <- .libPaths() | ||
|
||
# Set the pkgnet library for testing to a temp directory | ||
Sys.setenv(PKGNET_TEST_LIB = tempdir()) | ||
|
||
# Set the libpaths for testing. | ||
# This has no effect to global libpaths since testing tests are conducted within a seperate enviornment. | ||
.libPaths(new = c( | ||
Sys.getenv('PKGNET_TEST_LIB') | ||
, origLibPaths | ||
)) | ||
|
||
# Install Fake Packages - For local testing if not already installed | ||
pkgnet:::.BuildTestLib( | ||
targetLibPath = Sys.getenv('PKGNET_TEST_LIB') | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍