Skip to content

Commit

Permalink
Run tests with a readonly library on CRAN (#221)
Browse files Browse the repository at this point in the history
* avoid writing test result to files when not FULL TEST SUITE

* avoid tests that write files in inst/unitTests when not FULL.TEST.SUITE

* fix path to test results when RCMDCHECK = "FALSE"

* shellcheck on the hash compare step

wrong directory, copy-paste from solution

* order must be by hash, put back *.jar filter

* use GITHUB_WORKSPACE variable instead of hardcoded path

* bump version number
  • Loading branch information
spoltier authored Apr 30, 2024
1 parent 38c4bb2 commit 3b50414
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ jobs:
if: always()
run: |
echo $(date)
cat tests/XLConnect_Unit_Tests.txt || true
cat inst/unitTests/resources/XLConnect_Unit_Tests.txt || true
git clean -fd "*xls*"
grep -i "0 errors, 0 failures" tests/XLConnect_Unit_Tests.txt
grep -i "0 errors, 0 failures" inst/unitTests/resources/XLConnect_Unit_Tests.txt
shell: bash
continue-on-error: true

Expand All @@ -215,7 +215,7 @@ jobs:
with:
name: ${{ matrix.config.os-name }}${{matrix.config.os-version}}-java${{ matrix.config.java }}-R${{ matrix.config.r-version }}-results
path: |
tests/XLConnect_Unit_Tests.*
inst/unitTests/resources/XLConnect_Unit_Tests.*
check/XLConnect.Rcheck/
!check/XLConnect.Rcheck/**/*.jar
!check/XLConnect.Rcheck/00_pkg_src/
Expand Down Expand Up @@ -248,12 +248,12 @@ jobs:
set -eux -o pipefail
XLC_JAR_PATH=$(Rscript -e "cat(.libPaths()[1])")/XLConnect/java
rm -f "$XLC_JAR_PATH"/XLConnect*
find "$XLC_JAR_PATH" -maxdepth 1 -type f -name "*.jar"|\
xargs -l sha512sum | sort | awk '{print $1}' > effective_hashes
find /home/runner/work/xlconnect/xlconnect/target/dependency/ -maxdepth 1 -type f -name "*.jar"|\
find "$XLC_JAR_PATH" -maxdepth 1 -type f -name "*.jar" -exec sha512sum {} + |\
sort | awk '{print $1}' > effective_hashes
find "$GITHUB_WORKSPACE"/target/dependency/ -maxdepth 1 -type f -name "*.jar" -exec sha512sum {} + |\
grep -v -E "poi-ooxml-lite|junit|hamcrest" |\
xargs -l sha512sum | sort | awk '{print $1}' > expected_hashes
sort | awk '{print $1}' > expected_hashes
cmp expected_hashes effective_hashes ||\
(echo "JARs are different!" && ls -la /home/runner/work/xlconnect/xlconnect/target/dependency/ &&\
(echo "JARs are different!" && ls -la "$GITHUB_WORKSPACE"/target/dependency/ &&\
ls -la "$XLC_JAR_PATH" &&\
exit 1)
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: XLConnect
Type: Package
Title: Excel Connector for R
Version: 1.0.9
Version: 1.0.10
Authors@R: c(person("Mirai Solutions GmbH", role = "aut",
email = "[email protected]"),
person("Martin", "Studer", role = "cre",
Expand Down
5 changes: 3 additions & 2 deletions inst/unitTests/runit.writeNamedRegionToFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

test.writeNamedRegionToFile <- function() {

if(getOption("FULL.TEST.SUITE")) {
# Create workbooks
file.xls <- "testWriteNamedRegionToFileWorkbook.xls"
file.xlsx <- "testWriteNamedRegionToFileWorkbook.xlsx"
Expand All @@ -50,7 +51,7 @@ test.writeNamedRegionToFile <- function() {
checkEquals(normalizeDataframe(df), res, check.attributes = FALSE, check.names = TRUE)
}

if(getOption("FULL.TEST.SUITE")) {

# built-in dataset mtcars (*.xls)
testDataFrame(file.xls, mtcars)
# built-in dataset mtcars (*.xlsx)
Expand Down Expand Up @@ -96,7 +97,6 @@ test.writeNamedRegionToFile <- function() {
testDataFrame(file.xls, swiss)
# built-in dataset swiss (*.xlsx)
testDataFrame(file.xlsx, swiss)
}

# custom test dataset
cdf <- data.frame(
Expand Down Expand Up @@ -161,4 +161,5 @@ test.writeNamedRegionToFile <- function() {

testClearNamedRegions(file.xls, cdf)
testClearNamedRegions(file.xlsx, cdf)
}
}
6 changes: 3 additions & 3 deletions inst/unitTests/runit.writeWorksheetToFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

test.writeWorksheetToFile <- function() {

if(getOption("FULL.TEST.SUITE")) {
# Create workbooks
file.xls <- "testWriteWorksheetToFileWorkbook.xls"
file.xlsx <- "testWriteWorksheetToFileWorkbook.xlsx"
Expand All @@ -51,7 +52,7 @@ test.writeWorksheetToFile <- function() {
checkEquals(normalizeDataframe(df), res, check.attributes = FALSE, check.names = TRUE)
}

if(getOption("FULL.TEST.SUITE")) {

# built-in dataset mtcars (*.xls)
testDataFrame(file.xls, mtcars)
# built-in dataset mtcars (*.xlsx)
Expand Down Expand Up @@ -97,7 +98,6 @@ test.writeWorksheetToFile <- function() {
testDataFrame(file.xls, swiss)
# built-in dataset swiss (*.xlsx)
testDataFrame(file.xlsx, swiss)
}

# custom test dataset
cdf <- data.frame(
Expand Down Expand Up @@ -139,5 +139,5 @@ test.writeWorksheetToFile <- function() {

testClearSheets(file.xls, cdf)
testClearSheets(file.xlsx, cdf)

}
}
13 changes: 8 additions & 5 deletions tests/run_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ runUnitTests <- function() {

# Print (summary) test protocol to stdout
printTextProtocol(TestResult, showDetails = FALSE)
# Write detailed test protocol to text file
printTextProtocol(TestResult, showDetails = TRUE, fileName = txtProtocol)
# Write HTML protocol
printHTMLProtocol(TestResult, fileName = htmlProtocol)
# only write results in FULL case, CRAN tries to run with readonly filesystem
if (getOption("FULL.TEST.SUITE")) {
# Write detailed test protocol to text file
printTextProtocol(TestResult, showDetails = TRUE, fileName = txtProtocol)
# Write HTML protocol
printHTMLProtocol(TestResult, fileName = htmlProtocol)
}

# Show HTML Test Protocol
if (interactive()) { browseURL(url = htmlProtocol) }
if (interactive() && getOption("FULL.TEST.SUITE")) { browseURL(url = htmlProtocol) }

## Return stop() to cause R CMD check stop in case of
## - failures i.e. FALSE to unit tests or
Expand Down

0 comments on commit 3b50414

Please sign in to comment.