Skip to content

Commit a2c4a23

Browse files
committed
Fix file detection and testing under WSL
1 parent 6daf429 commit a2c4a23

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

R/run.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ CmdStanRun <- R6::R6Class(
7676
},
7777
config_files = function(include_failed = FALSE) {
7878
files <- private$config_files_
79-
if (!length(files) || !any(file.exists(files))) {
79+
files_win_path <- sapply(private$config_files_, wsl_safe_path, revert = TRUE)
80+
if (!length(files) || !any(file.exists(files_win_path))) {
8081
stop(
8182
"No CmdStan config files found. ",
8283
"Set 'save_cmdstan_config=TRUE' when fitting the model.",
@@ -92,7 +93,8 @@ CmdStanRun <- R6::R6Class(
9293
},
9394
metric_files = function(include_failed = FALSE) {
9495
files <- private$metric_files_
95-
if (!length(files) || !any(file.exists(files))) {
96+
files_win_path <- sapply(private$metric_files_, wsl_safe_path, revert = TRUE)
97+
if (!length(files) || !any(file.exists(files_win_path))) {
9698
stop(
9799
"No metric files found. ",
98100
"Set 'save_metric=TRUE' when fitting the model.",

tests/testthat/test-model-output_dir.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,24 @@ test_that("all fitting methods work with output_dir", {
3333
# from the original tempdir(), so need to normalise both for comparison
3434
expect_equal(normalizePath(fit$runset$args$output_dir),
3535
normalizePath(method_dir))
36-
files <- list.files(method_dir, full.names = TRUE)
36+
files <- normalizePath(list.files(method_dir, full.names = TRUE))
3737
# in 2.34.0 we also save the config files for all methods and the metric
3838
# for sample
3939
if (cmdstan_version() < "2.34.0") {
4040
mult <- 1
4141
} else if (method == "sample") {
4242
mult <- 3
43-
expect_equal(repair_path(files[grepl("metric", files)]), fit$metric_files())
44-
expect_equal(repair_path(files[grepl("config", files)]), fit$config_files())
43+
expect_equal(files[grepl("metric", files)],
44+
normalizePath(sapply(fit$metric_files(), wsl_safe_path, revert = TRUE,
45+
USE.NAMES = FALSE)))
46+
expect_equal(files[grepl("config", files)],
47+
normalizePath(sapply(fit$config_files(), wsl_safe_path, revert = TRUE,
48+
USE.NAMES = FALSE)))
4549
} else {
4650
mult <- 2
47-
expect_equal(repair_path(files[grepl("config", files)]), fit$config_files())
51+
expect_equal(files[grepl("config", files)],
52+
normalizePath(sapply(fit$config_files(), wsl_safe_path, revert = TRUE,
53+
USE.NAMES = FALSE)))
4854
}
4955
expect_equal(length(list.files(method_dir)), mult * fit$num_procs())
5056

0 commit comments

Comments
 (0)