Skip to content

Commit

Permalink
fix: env_exists empty argument
Browse files Browse the repository at this point in the history
  • Loading branch information
luciorq committed Nov 29, 2024
1 parent 7aa1ada commit aa1bb3d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Breaking changes

* `env_exists()` now error if no argument is supplied.

## New features

## Minor improvements and fixes
Expand Down
9 changes: 5 additions & 4 deletions R/env_exists.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Check If Environment Names Already exists
#' Check If Environment Already exists
#'
#' @inheritParams create_env
#' @return Boolean.
Expand All @@ -7,14 +7,15 @@
#' # Create the environment
#' condathis::create_env(
#' packages = "fastqc",
#' env_name = "fastqc_env"
#' env_name = "fastqc-env"
#' )
#' # Check if exists
#' condathis::env_exists("fastqc_env")
#' condathis::env_exists("fastqc-env")
#' #> [1] TRUE
#' }
#' @export
env_exists <- function(env_name = "condathis-env") {
env_exists <- function(env_name) {
rlang::check_required(env_name)
available_envs <- list_envs()
condathis_env_path <- env_name
if (isTRUE(condathis_env_path %in% available_envs)) {
Expand Down
10 changes: 5 additions & 5 deletions man/env_exists.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-env_exists.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("env_exists missing env_name", {
expect_error(env_exists())
expect_equal(env_exists(NULL), FALSE)
expect_equal(env_exists(NA), FALSE)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-list_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("list packages on absent environment", {
testthat::expect_error(
object = {
list_packages(env_name = "non-existing-env")
},
class = "condathis_list_packages_missing_env"
)
})

0 comments on commit aa1bb3d

Please sign in to comment.