Skip to content

Commit

Permalink
[R-package] [docs] fix calculation of R test coverage (fixes #4919) (#…
Browse files Browse the repository at this point in the history
…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: Nikita Titov <[email protected]>

* 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: Nikita Titov <[email protected]>

Co-authored-by: Nikita Titov <[email protected]>
  • Loading branch information
jameslamb and StrikerRUS authored Jan 5, 2022
1 parent ac821f0 commit 2e25719
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ The example below shows how to generate code coverage for the R package on a mac

```shell
# Install
sh build-cran-package.sh
sh build-cran-package.sh \
--no-build-vignettes

# Get coverage
Rscript -e " \
coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE);
library(covr);
coverage <- covr::package_coverage('./lightgbm_r', type = 'tests', quiet = FALSE);
print(coverage);
covr::report(coverage, file = file.path(getwd(), 'coverage.html'), browse = TRUE);
"
Expand Down
10 changes: 10 additions & 0 deletions R-package/tests/testthat/test_lgb.unloader.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ VERBOSITY <- as.integer(
Sys.getenv("LIGHTGBM_TEST_VERBOSITY", "-1")
)

CALCULATING_TEST_COVERAGE <- Sys.getenv("R_COVR", unset = "unset") != "unset"

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")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
Expand All @@ -24,6 +30,10 @@ test_that("lgb.unloader works as expected", {
})

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")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
Expand Down

0 comments on commit 2e25719

Please sign in to comment.