Skip to content

Commit 6a4277a

Browse files
committed
Update tests
1 parent 73234b3 commit 6a4277a

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

tests/testthat/test-utils-projects.R

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,70 +122,73 @@ test_that("is_running_quarto_project() detects environment variables", {
122122
QUARTO_PROJECT_ROOT = "",
123123
QUARTO_PROJECT_DIR = ""
124124
),
125-
expect_false(is_running_quarto_project())
125+
expect_null(get_running_project_root())
126126
)
127127

128128
withr::with_envvar(
129129
list(
130130
QUARTO_PROJECT_ROOT = "/some/path",
131131
QUARTO_PROJECT_DIR = ""
132132
),
133-
expect_true(is_running_quarto_project())
133+
expect_identical(get_running_project_root(), "/some/path")
134134
)
135135

136136
withr::with_envvar(
137137
list(
138138
QUARTO_PROJECT_ROOT = "",
139139
QUARTO_PROJECT_DIR = "/some/path"
140140
),
141-
expect_true(is_running_quarto_project())
141+
expect_identical(get_running_project_root(), "/some/path")
142142
)
143143

144144
withr::with_envvar(
145145
list(
146146
QUARTO_PROJECT_ROOT = "/path1",
147147
QUARTO_PROJECT_DIR = "/path2"
148148
),
149-
expect_true(is_running_quarto_project())
149+
expect_identical(get_running_project_root(), "/path1")
150150
)
151151
})
152152

153-
test_that("is_quarto_project() detects Quarto project files", {
153+
test_that("find_project_root() detects Quarto project files", {
154154
skip_if_no_quarto()
155155

156156
temp_dir <- withr::local_tempdir()
157-
expect_false(is_quarto_project(temp_dir))
157+
expect_null(find_project_root(temp_dir))
158158

159-
project_dir <- local_quarto_project(type = "default")
160-
expect_true(is_quarto_project(project_dir))
159+
project_dir <- local_quarto_project("test-project", type = "default")
160+
expect_match(
161+
find_project_root(project_dir),
162+
"quarto-tests-project-.*/test-project$"
163+
)
161164

162-
withr::local_dir(project_dir)
163-
expect_true(is_quarto_project())
165+
withr::with_dir(
166+
project_dir,
167+
expect_match(
168+
find_project_root(),
169+
"quarto-tests-project-.*/test-project$"
170+
)
171+
)
164172
})
165173

166-
test_that("is_quarto_project() works with _quarto.yaml", {
174+
test_that("find_project_root() works with _quarto.yaml", {
167175
temp_dir <- withr::local_tempdir()
168176

169177
quarto_yaml <- file.path(temp_dir, "_quarto.yaml")
170-
writeLines("project:", quarto_yaml)
178+
writeLines("project:\n type: default", quarto_yaml)
171179

172-
expect_true(is_quarto_project(temp_dir))
180+
expect_identical(find_project_root(temp_dir), xfun::normalize_path(temp_dir))
173181

174182
withr::local_dir(temp_dir)
175-
expect_true(is_quarto_project())
176-
})
183+
expect_identical(find_project_root(), xfun::normalize_path(temp_dir))
177184

178-
test_that("is_quarto_project() handles errors gracefully", {
179-
# Mock xfun::proj_root to throw an error
180-
local_mocked_bindings(
181-
proj_root = function(path = ".", rules = xfun::root_rules) {
182-
stop("Test error")
183-
},
184-
.package = "xfun"
185+
dir.create("subfolder")
186+
expect_identical(
187+
find_project_root("subfolder"),
188+
xfun::normalize_path(temp_dir)
185189
)
186-
187-
temp_dir <- withr::local_tempdir()
188-
expect_false(is_quarto_project(temp_dir))
190+
withr::local_dir("subfolder")
191+
expect_identical(find_project_root(), xfun::normalize_path(temp_dir))
189192
})
190193

191194
test_that("project_path() prioritizes environment variables over file detection", {

0 commit comments

Comments
 (0)