Skip to content

Commit

Permalink
onAttach logic outsourced to make a testable call (#106)
Browse files Browse the repository at this point in the history
* onAttach logic outsourced to make a testable call

* codecov tuning
  • Loading branch information
jlacko authored Feb 8, 2025
1 parent 1dc3577 commit 4f16e06
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
# either: pull request to master opened
# either: pull request to master merged
pull_request:
types:
- opened
- merged
branches:
- master
# or: manual trigger from GitHub pages
Expand Down
19 changes: 17 additions & 2 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,26 @@
TRUE
}

# check the environment variable & report back

.onAttach <- function(libname, pkgname) {
#' Internal function - executes on load, and informs about state of the RCZECHIA_HOME environment variable
#'
#' The function takes no parameters; it serves the need to make the .onAttach code testable
#'
#' @keywords internal

.rhome_state <- function() {

home <- Sys.getenv("RCZECHIA_HOME")

if(home != "") packageStartupMessage("Using local RCzechia cache at ", home, appendLF = TRUE)

}


# check the environment variable & report back

.onAttach <- function(libname, pkgname) {

.rhome_state()

}
12 changes: 12 additions & 0 deletions man/dot-rhome_state.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/testthat/test-2-code-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ test_that("envir variable", {

expect_true(set_home((tempdir()))) # nastavení na tempdir projde

set_home((tempdir()))

expect_message(.rhome_state(), "Using local RCzechia cache at") # když je home nastaven, tak vyjde hláška

expect_true(unset_home()) # vysazení projde

if(envir_backup != "") Sys.setenv("RCZECHIA_HOME" = envir_backup) # obnovit hodnotu ze zálohy, pokud dává smysl
if(envir_backup != "") Sys.setenv("RCZECHIA_HOME" = envir_backup) # obnovit hodnotu ze zálohy, pokud dává smysl

})

Expand Down

0 comments on commit 4f16e06

Please sign in to comment.