Skip to content

Commit 2411dd1

Browse files
committed
has_dirname -> has_basename
1 parent 6255965 commit 2411dd1

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export(find_rstudio_root_file)
1919
export(find_testthat_root_file)
2020
export(from_wd)
2121
export(get_root_desc)
22+
export(has_basename)
2223
export(has_dir)
23-
export(has_dirname)
2424
export(has_file)
2525
export(has_file_pattern)
2626
export(is.root_criterion)

R/has-file.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,22 @@ has_file_pattern <- function(pattern, contents = NULL, n = -1L) {
101101
}
102102

103103
#' @details
104-
#' The `has_dirname()` function constructs a criterion that checks if the
105-
#' [base::dirname()] has a specific name.
104+
#' The `has_basename()` function constructs a criterion that checks if the
105+
#' [base::basename()] of the root directory has a specific name,
106+
#' with support for case-insensitive file systems.
106107
#'
107108
#' @rdname root_criterion
108-
#' @param dirname A directory name, without subdirectories
109+
#' @param basename A directory name, without subdirectories
109110
#' @export
110-
has_dirname <- function(dirname, subdir = NULL) {
111-
force(dirname)
111+
has_basename <- function(basename, subdir = NULL) {
112+
force(basename)
112113

113114
testfun <- eval(bquote(function(path) {
114115
# Support case insensitive file systems.
115-
tolower(basename(path)) == tolower(.(dirname)) && dir.exists(file.path(dirname(path), .(dirname)))
116+
tolower(basename(path)) == tolower(.(basename)) && dir.exists(file.path(dirname(path), .(basename)))
116117
}))
117118

118-
desc <- paste0("directory name is `", dirname, "`")
119+
desc <- paste0("directory name is `", basename, "`")
119120

120121
root_criterion(testfun, desc, subdir = subdir)
121122
}
@@ -145,7 +146,7 @@ is_svn_root <- has_dir(".svn")
145146
is_vcs_root <- is_git_root | is_svn_root
146147

147148
#' @export
148-
is_testthat <- has_dirname("testthat", c("tests/testthat", "testthat"))
149+
is_testthat <- has_basename("testthat", c("tests/testthat", "testthat"))
149150

150151
#' @export
151152
from_wd <- root_criterion(function(path) TRUE, "from current working directory")

man/root_criterion.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-root.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test_that("has_dir", {
115115
)
116116
})
117117

118-
test_that("has_dirname", {
118+
test_that("has_basename", {
119119
wd <- normalizePath(getwd(), winslash = "/")
120120
hierarchy <- function(n = 0L) {
121121
do.call(file.path, list(wd, "hierarchy", "a", "b", "c")[seq_len(n + 1L)])
@@ -126,19 +126,19 @@ test_that("has_dirname", {
126126

127127
mockr::with_mock(
128128
is_root = function(x) x == stop_path,
129-
expect_equal(find_root(has_dirname("a"), path = path), hierarchy(2L)),
130-
expect_equal(find_root(has_dirname("b"), path = path), hierarchy(3L)),
129+
expect_equal(find_root(has_basename("a"), path = path), hierarchy(2L)),
130+
expect_equal(find_root(has_basename("b"), path = path), hierarchy(3L)),
131131
expect_equal(
132-
find_root_file("c", criterion = has_dirname("b"), path = path),
132+
find_root_file("c", criterion = has_basename("b"), path = path),
133133
file.path(hierarchy(3L), "c")
134134
),
135-
expect_equal(find_root(has_dirname("c"), path = path), hierarchy(4L)),
135+
expect_equal(find_root(has_basename("c"), path = path), hierarchy(4L)),
136136
expect_error(
137-
find_root(has_dirname("d"), path = path),
137+
find_root(has_basename("d"), path = path),
138138
"No root directory found.* is `.*`"
139139
),
140140
expect_error(
141-
find_root(has_dirname("rprojroot.Rproj"), path = path),
141+
find_root(has_basename("rprojroot.Rproj"), path = path),
142142
"No root directory found.* is `.*`"
143143
),
144144
TRUE

0 commit comments

Comments
 (0)