Unverified Commit 2e257192 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] [docs] fix calculation of R test coverage (fixes #4919) (#4922)



* [R-package] [docs] fix calculation of R test coverage (fixes #4919)

* use quotes

* use in_covr() instead of env variable

* Update R-package/README.md
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* check that covr exists

* add covr to suggests

* use R_COVR environment variable

* Update R-package/tests/testthat/test_lgb.unloader.R
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
parent ac821f0c
...@@ -265,10 +265,12 @@ The example below shows how to generate code coverage for the R package on a mac ...@@ -265,10 +265,12 @@ The example below shows how to generate code coverage for the R package on a mac
```shell ```shell
# Install # Install
sh build-cran-package.sh sh build-cran-package.sh \
--no-build-vignettes
# Get coverage # Get coverage
Rscript -e " \ Rscript -e " \
library(covr);
coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE); coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE);
print(coverage); print(coverage);
covr::report(coverage, file = file.path(getwd(), 'coverage.html'), browse = TRUE); covr::report(coverage, file = file.path(getwd(), 'coverage.html'), browse = TRUE);
......
...@@ -2,7 +2,13 @@ VERBOSITY <- as.integer( ...@@ -2,7 +2,13 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1") Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
) )
CALCULATING_TEST_COVERAGE <- Sys.getenv("R_COVR", unset = "unset") != "unset"
test_that("lgb.unloader works as expected", { test_that("lgb.unloader works as expected", {
testthat::skip_if(
condition = CALCULATING_TEST_COVERAGE
, message = "lgb.unloader() tests are skipped when calculating test coverage"
)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
...@@ -24,6 +30,10 @@ test_that("lgb.unloader works as expected", { ...@@ -24,6 +30,10 @@ test_that("lgb.unloader works as expected", {
}) })
test_that("lgb.unloader finds all boosters and removes them", { test_that("lgb.unloader finds all boosters and removes them", {
testthat::skip_if(
condition = CALCULATING_TEST_COVERAGE
, message = "lgb.unloader() tests are skipped when calculating test coverage"
)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label) dtrain <- lgb.Dataset(train$data, label = train$label)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment