Skip to content

Commit 4753a71

Browse files
committed
Cleaned up teardown
1 parent f7868cc commit 4753a71

4 files changed

Lines changed: 18 additions & 58 deletions

File tree

‎tests/testthat/helper-custom-expectations.R‎

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ expect_compilation <- function(mod, ...) {
1515
if(length(mod$exe_file()) == 0 || !file.exists(mod$exe_file())) {
1616
fail(sprint("Model executable '%s' does not exist after compilation.", mod$exe_file()))
1717
}
18-
if(!is.null(before_mtime) && mtime_check_enabled) {
18+
if(!is.null(before_mtime)) {
1919
after_mtime <- file.mtime(mod$exe_file())
2020
expect_gt(
2121
after_mtime,
@@ -135,43 +135,3 @@ expect_equal_ignore_order <- function(object, expected, ...) {
135135
}
136136

137137
expect_not_true <- function(...) expect_false(isTRUE(...))
138-
139-
transform_print_snapshot <- function(x) {
140-
vapply(x, function(line) {
141-
line <- trimws(line)
142-
if (!nzchar(line)) {
143-
return(line)
144-
}
145-
if (grepl("^variable\\b", line)) {
146-
return(gsub("\\s+", " ", line))
147-
}
148-
if (grepl("^# showing", line) ||
149-
grepl("^Can't find the following variable\\(s\\):", line)) {
150-
return(line)
151-
}
152-
sub("\\s+.*$", "", line)
153-
}, character(1))
154-
}
155-
156-
transform_unix_toolchain_snapshot <- function(x) {
157-
x <- gsub("A suitable C\\+\\+ compiler was not found\\..*", "C++ compiler missing.", x)
158-
x <- gsub("A C\\+\\+ compiler was not found\\..*", "C++ compiler missing.", x)
159-
gsub("The 'make' tool was not found\\..*", "make missing.", x)
160-
}
161-
162-
transform_r_version_snapshot <- function(x) {
163-
x <- gsub("Rtools[0-9]+", "Rtools<version>", x)
164-
gsub("R version [0-9]+\\.[0-9]+\\.[0-9]+", "R version <version>", x)
165-
}
166-
167-
capture_print_snapshot <- function(code) {
168-
code <- substitute(code)
169-
value <- NULL
170-
lines <- utils::capture.output(
171-
value <- rlang::eval_bare(code, parent.frame())
172-
)
173-
list(
174-
value = value,
175-
lines = transform_print_snapshot(lines)
176-
)
177-
}

‎tests/testthat/helper-models.R‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
local({
2-
stan_files <- dir(test_path("resources", "stan"), pattern = "\\.stan$", full.names = TRUE)
3-
exe_files <- cmdstanr:::cmdstan_ext(cmdstanr:::strip_ext(stan_files))
4-
existing_exe_files <- exe_files[file.exists(exe_files)]
5-
if (length(existing_exe_files) > 0) {
6-
unlink(existing_exe_files, force = TRUE)
7-
}
8-
})
9-
101
testing_data <- function(name) {
112
if (file.exists(test_path("resources", "data", paste0(name, ".data.rds")))) {
123
readRDS(test_path("resources", "data", paste0(name, ".data.rds")))

‎tests/testthat/setup.R‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cleanup_stan_artifacts <- function() {
2+
all_files_in_stan <- list.files(
3+
test_path("resources", "stan"),
4+
full.names = TRUE,
5+
recursive = TRUE
6+
)
7+
files_to_remove <- all_files_in_stan[!grepl("\\.stan$", all_files_in_stan)]
8+
9+
if (length(files_to_remove) > 0) {
10+
unlink(files_to_remove, force = TRUE)
11+
}
12+
13+
invisible(files_to_remove)
14+
}
15+
16+
cleanup_stan_artifacts()
17+
withr::defer(cleanup_stan_artifacts(), testthat::teardown_env())

‎tests/testthat/teardown-remove-files.R‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)