Skip to content

Commit c380293

Browse files
Centralize normalizePath usage in tests to avoid Windows/Mac build failures
1 parent 94d7b3d commit c380293

10 files changed

Lines changed: 54 additions & 65 deletions

tests/testthat/helper-paths.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
norm_path <- function(path, mustWork = FALSE) {
2+
if (is.null(path)) return(NULL)
3+
4+
out <- normalizePath(path, winslash = "/", mustWork = mustWork)
5+
if (.Platform$OS.type == "unix") {
6+
private_var <- startsWith(out, "/private/var/")
7+
out[private_var] <- sub("^/private", "", out[private_var])
8+
}
9+
temp_alias <- grepl("/T/Rtmp", out, fixed = TRUE)
10+
if (any(temp_alias)) {
11+
out[temp_alias] <- sub("/T/(Rtmp[^/]+)", "/T//\\1", out[temp_alias], perl = TRUE)
12+
}
13+
out
14+
}
15+
16+
expect_path_identical <- function(actual, expected, mustWork = TRUE) {
17+
testthat::expect_identical(
18+
norm_path(actual, mustWork = mustWork),
19+
norm_path(expected, mustWork = mustWork)
20+
)
21+
}

tests/testthat/test-construct_bids_filename.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ test_that("get_fmriprep_outputs resolves cohort-qualified bold and non-spatial d
116116

117117
outputs <- get_fmriprep_outputs(in_file)
118118

119-
expect_identical(outputs$bold, normalizePath(in_file))
120-
expect_identical(outputs$brain_mask, normalizePath(brain_mask))
121-
expect_identical(outputs$confounds, normalizePath(confounds))
122-
expect_identical(outputs$melodic_mix, normalizePath(melodic_mix))
119+
expect_path_identical(outputs$bold, in_file)
120+
expect_path_identical(outputs$brain_mask, brain_mask)
121+
expect_path_identical(outputs$confounds, confounds)
122+
expect_path_identical(outputs$melodic_mix, melodic_mix)
123123
expect_identical(outputs$prefix, "sub-03_task-emo1_dir-AP_run-02")
124124
})

tests/testthat/test-flywheel-setup.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ test_that("setup_compute_environment prompts for Flywheel path when CLI is absen
8787

8888
result <- setup_compute_environment(scfg, fields = "compute_environment/flywheel")
8989

90-
expect_identical(
91-
normalizePath(result$compute_environment$flywheel, winslash = "/", mustWork = TRUE),
92-
normalizePath(fw_path, winslash = "/", mustWork = TRUE)
93-
)
90+
expect_path_identical(result$compute_environment$flywheel, fw_path)
9491
expect_true(any(grepl("not found on your PATH", prompts, fixed = TRUE)))
9592
})

tests/testthat/test-postprocess-scratch.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
norm_path <- function(path, mustWork = FALSE) {
2-
out <- normalizePath(path, winslash = "/", mustWork = mustWork)
3-
if (.Platform$OS.type == "unix" && startsWith(out, "/private/var/")) {
4-
out <- sub("^/private", "", out)
5-
}
6-
if (grepl("/T/Rtmp", out, fixed = TRUE)) {
7-
out <- sub("/T/(Rtmp[^/]+)", "/T//\\1", out, perl = TRUE)
8-
}
9-
out
10-
}
11-
121
test_that("postprocess_subject stages outputs in scratch workspace", {
132
tmp_dir <- norm_path(tempfile("pp-scratch-"), mustWork = FALSE)
143
dir.create(tmp_dir, recursive = TRUE, showWarnings = FALSE)

tests/testthat/test-prefetch-query-plan.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@ test_that("resolve_prefetch_query_plan returns parsed summary from plan step", {
2222
expect_true(any(grepl("MNI152NLin2009cAsym", cmd_args, fixed = TRUE)))
2323
expect_true("TEMPLATEFLOW_HOME" %in% names(env))
2424
expect_true("APPTAINERENV_TEMPLATEFLOW_HOME" %in% names(env))
25-
expect_identical(
26-
unname(env[["TEMPLATEFLOW_HOME"]]),
27-
normalizePath(tf_home, winslash = "/", mustWork = FALSE)
28-
)
29-
expect_identical(
30-
unname(env[["APPTAINERENV_TEMPLATEFLOW_HOME"]]),
31-
normalizePath(tf_home, winslash = "/", mustWork = FALSE)
32-
)
25+
expect_path_identical(unname(env[["TEMPLATEFLOW_HOME"]]), tf_home, mustWork = FALSE)
26+
expect_path_identical(unname(env[["APPTAINERENV_TEMPLATEFLOW_HOME"]]), tf_home, mustWork = FALSE)
3327

3428
summary_idx <- match("--summary-json", cmd_args)
3529
summary_file <- cmd_args[[summary_idx + 1L]]

tests/testthat/test-prefetch-templateflow-state-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test_that("prefetch overwrites stale success state with FAILED state on fetch fa
100100
state_file <- file.path(root, ".braingnomes_prefetch_state.dcf")
101101
writeLines(c(
102102
"status: COMPLETED",
103-
paste0("templateflow_home: ", normalizePath(root, winslash = "/", mustWork = FALSE)),
103+
paste0("templateflow_home: ", norm_path(root, mustWork = FALSE)),
104104
"spaces: MNI152NLin2009cAsym",
105105
"scheduler_job_id: old-job",
106106
"query_signature: oldsig"

tests/testthat/test-preflight-permissions.R

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ test_that("submit_prefetch_templates skips when cached state covers requested sp
426426
state_file <- get_prefetch_state_file(log_dir, tf_home)
427427
writeLines(c(
428428
"status: COMPLETED",
429-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
429+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
430430
"spaces: MNI152NLin2009cAsym MNI152NLin6Asym:res-2",
431431
"query_signature: sig-current"
432432
), state_file)
@@ -480,7 +480,7 @@ test_that("submit_prefetch_templates resubmits when state covers spaces but mani
480480
state_file <- get_prefetch_state_file(log_dir, tf_home)
481481
writeLines(c(
482482
"status: COMPLETED",
483-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
483+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
484484
"spaces: MNI152NLin2009cAsym",
485485
"query_signature: sig-current"
486486
), state_file)
@@ -535,7 +535,7 @@ test_that("submit_prefetch_templates ignores FAILED cached state from prior reru
535535
state_file <- get_prefetch_state_file(log_dir, tf_home)
536536
writeLines(c(
537537
"status: FAILED",
538-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
538+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
539539
"spaces: MNI152NLin2009cAsym",
540540
"scheduler_job_id: failed-job",
541541
"query_signature: sig-current"
@@ -596,7 +596,7 @@ test_that("submit_prefetch_templates resubmits when a new space is requested", {
596596
state_file <- get_prefetch_state_file(log_dir, tf_home)
597597
writeLines(c(
598598
"status: COMPLETED",
599-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
599+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
600600
"spaces: MNI152NLin2009cAsym",
601601
"query_signature: sig-old"
602602
), state_file)
@@ -640,8 +640,8 @@ test_that("submit_prefetch_templates resubmits when a new space is requested", {
640640
expect_equal(result, "99991")
641641
expect_true("prefetch_state_file" %in% names(captured_env))
642642
expect_equal(
643-
normalizePath(captured_env[["prefetch_state_file"]], winslash = "/", mustWork = FALSE),
644-
normalizePath(state_file, winslash = "/", mustWork = FALSE)
643+
norm_path(captured_env[["prefetch_state_file"]], mustWork = FALSE),
644+
norm_path(state_file, mustWork = FALSE)
645645
)
646646
})
647647

@@ -670,7 +670,7 @@ test_that("submit_prefetch_templates resubmits when cached manifest drifts after
670670
job_id = "job-drift",
671671
status = "COMPLETED",
672672
output_manifest = jsonlite::toJSON(list(
673-
output_dir = normalizePath(tf_home, winslash = "/", mustWork = TRUE),
673+
output_dir = norm_path(tf_home, mustWork = TRUE),
674674
captured_at = "2026-03-01T00:00:00Z",
675675
query_signature = "sig-current",
676676
file_count = 1L,
@@ -685,7 +685,7 @@ test_that("submit_prefetch_templates resubmits when cached manifest drifts after
685685

686686
writeLines(c(
687687
"status: COMPLETED",
688-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
688+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
689689
"spaces: MNI152NLin2009cAsym",
690690
"scheduler_job_id: job-drift",
691691
"query_signature: sig-current"
@@ -744,7 +744,7 @@ test_that("submit_prefetch_templates resubmits when copied state file references
744744
state_file <- get_prefetch_state_file(log_dir, tf_home)
745745
writeLines(c(
746746
"status: COMPLETED",
747-
paste0("templateflow_home: ", normalizePath(previous_tf_home, winslash = "/", mustWork = FALSE)),
747+
paste0("templateflow_home: ", norm_path(previous_tf_home, mustWork = FALSE)),
748748
"spaces: MNI152NLin2009cAsym",
749749
"scheduler_job_id: copied-job",
750750
"query_signature: sig-current"
@@ -806,7 +806,7 @@ test_that("submit_prefetch_templates migrates legacy state file into logs and re
806806
new_state_file <- get_prefetch_state_file(log_dir, tf_home)
807807
writeLines(c(
808808
"status: COMPLETED",
809-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
809+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
810810
"spaces: MNI152NLin2009cAsym",
811811
"scheduler_job_id: migrated-job",
812812
"query_signature: sig-current"
@@ -865,14 +865,14 @@ test_that("submit_prefetch_templates prefers logs-based state when both state lo
865865
new_state_file <- get_prefetch_state_file(log_dir, tf_home)
866866
writeLines(c(
867867
"status: FAILED",
868-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
868+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
869869
"spaces: MNI152NLin2009cAsym",
870870
"scheduler_job_id: legacy-job",
871871
"query_signature: sig-current"
872872
), legacy_state_file)
873873
writeLines(c(
874874
"status: COMPLETED",
875-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
875+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
876876
"spaces: MNI152NLin2009cAsym",
877877
"scheduler_job_id: logs-job",
878878
"query_signature: sig-current"
@@ -930,7 +930,7 @@ test_that("submit_prefetch_templates stops when legacy state cannot be removed a
930930
legacy_state_file <- get_legacy_prefetch_state_file(tf_home)
931931
writeLines(c(
932932
"status: COMPLETED",
933-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
933+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
934934
"spaces: MNI152NLin2009cAsym",
935935
"query_signature: sig-current"
936936
), legacy_state_file)
@@ -985,7 +985,7 @@ test_that("submit_prefetch_templates warns when legacy state cannot be removed b
985985
legacy_state_file <- get_legacy_prefetch_state_file(tf_home)
986986
writeLines(c(
987987
"status: COMPLETED",
988-
paste0("templateflow_home: ", normalizePath(tf_home, winslash = "/", mustWork = FALSE)),
988+
paste0("templateflow_home: ", norm_path(tf_home, mustWork = FALSE)),
989989
"spaces: MNI152NLin2009cAsym",
990990
"query_signature: sig-current"
991991
), legacy_state_file)
@@ -1099,7 +1099,7 @@ test_that("prefetch_manifest_verified requires exact files and matching query si
10991099
writeLines("csf", file_b)
11001100

11011101
manifest_json <- jsonlite::toJSON(list(
1102-
output_dir = normalizePath(tf_home, winslash = "/", mustWork = TRUE),
1102+
output_dir = norm_path(tf_home, mustWork = TRUE),
11031103
captured_at = "2026-03-01T00:00:00Z",
11041104
query_signature = "sig-required",
11051105
file_count = 2L,
@@ -1222,8 +1222,8 @@ test_that("setup_project_directories primes check_cache with writable dirs", {
12221222
setup_project_directories(scfg, check_cache = cache)
12231223

12241224
# All created dirs should be primed in the cache
1225-
scratch_key <- normalizePath(scratch_dir, winslash = "/", mustWork = FALSE)
1226-
log_key <- normalizePath(log_dir, winslash = "/", mustWork = FALSE)
1225+
scratch_key <- norm_path(scratch_dir, mustWork = FALSE)
1226+
log_key <- norm_path(log_dir, mustWork = FALSE)
12271227

12281228
expect_true(exists(scratch_key, envir = cache, inherits = FALSE))
12291229
expect_true(exists(log_key, envir = cache, inherits = FALSE))
@@ -1288,7 +1288,7 @@ test_that("setup_project_directories warns and remediates unwritable directories
12881288
)
12891289

12901290
# proj_dir should be in cache (it was writable)
1291-
proj_key <- normalizePath(proj_dir, winslash = "/", mustWork = FALSE)
1291+
proj_key <- norm_path(proj_dir, mustWork = FALSE)
12921292
expect_true(exists(proj_key, envir = cache))
12931293
})
12941294

tests/testthat/test-run_bids_validation.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,10 @@ test_that("submit_bids_validation routes relative outfile under log directory",
123123

124124
expect_equal(job_id, "777")
125125
expect_true("outfile" %in% names(captured_env))
126-
expect_equal(
126+
expect_path_identical(
127127
captured_env[["outfile"]],
128-
normalizePath(
129-
file.path(scfg$metadata$log_directory, "bids_validation_project.html"),
130-
winslash = "/",
131-
mustWork = FALSE
132-
)
128+
file.path(scfg$metadata$log_directory, "bids_validation_project.html"),
129+
mustWork = FALSE
133130
)
134131
})
135132

tests/testthat/test-run_fsl_command.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ test_that("run_fsl_command falls back to feat path when FSLDIR is unset", {
6969
use_lgr = FALSE
7070
)
7171
expect_equal(as.numeric(rc), 0)
72-
expect_identical(
73-
normalizePath(Sys.getenv("FSLDIR"), winslash = "/", mustWork = FALSE),
74-
normalizePath(fake_fsldir, winslash = "/", mustWork = FALSE)
75-
)
72+
expect_path_identical(Sys.getenv("FSLDIR"), fake_fsldir, mustWork = FALSE)
7673
})
7774

7875
test_that("run_fsl_command accepts singularity FSLDIR that is host-invisible", {

tests/testthat/test-save_project_config.R

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test_that("load_project records the YAML source path", {
77
yaml::write_yaml(list(a = 1), yaml_path)
88

99
cfg <- load_project(yaml_path, validate = FALSE)
10-
expect_identical(attr(cfg, "yaml_file"), normalizePath(yaml_path, winslash = "/", mustWork = TRUE))
10+
expect_path_identical(attr(cfg, "yaml_file"), yaml_path)
1111
})
1212

1313
test_that("save_project_config uses stored YAML path", {
@@ -24,10 +24,7 @@ test_that("save_project_config uses stored YAML path", {
2424

2525
result <- save_project_config(scfg)
2626
expect_true(file.exists(yaml_path))
27-
expect_identical(
28-
normalizePath(attr(result, "yaml_file"), winslash = "/", mustWork = TRUE),
29-
normalizePath(yaml_path, winslash = "/", mustWork = TRUE)
30-
)
27+
expect_path_identical(attr(result, "yaml_file"), yaml_path)
3128
})
3229

3330
test_that("save_project_config updates YAML path when file argument supplied", {
@@ -43,10 +40,7 @@ test_that("save_project_config updates YAML path when file argument supplied", {
4340

4441
result <- save_project_config(scfg, file = new_yaml)
4542
expect_true(file.exists(new_yaml))
46-
expect_identical(
47-
normalizePath(attr(result, "yaml_file"), winslash = "/", mustWork = TRUE),
48-
normalizePath(new_yaml, winslash = "/", mustWork = TRUE)
49-
)
43+
expect_path_identical(attr(result, "yaml_file"), new_yaml)
5044
})
5145

5246
test_that("validate_char normalizes blank fmriprep output_spaces to NULL", {

0 commit comments

Comments
 (0)