Skip to content

Commit 7be6ff4

Browse files
Further attempt at path fixes in tests
1 parent af4ba8a commit 7be6ff4

2 files changed

Lines changed: 34 additions & 52 deletions

File tree

tests/testthat/test-aroma-success-reconciliation.R

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test_that("aroma sbatch reconciles non-zero exit with success token", {
22
skip_if(Sys.which("bash") == "", "bash is required for shell-script integration test")
3+
skip_on_os("windows")
34

45
resolve_pkg_file <- function(inst_rel, fallback_rel) {
56
inst_path <- system.file(inst_rel, package = "BrainGnomes")
@@ -31,15 +32,12 @@ test_that("aroma sbatch reconciles non-zero exit with success token", {
3132
mrproc_dir <- file.path(root, "fmriprep")
3233
scratch_dir <- file.path(root, "scratch")
3334
bin_dir <- file.path(root, "bin")
34-
r_home <- file.path(root, "R_HOME")
35-
r_bin <- file.path(r_home, "bin")
3635
out_dir <- file.path(mrproc_dir, "sub-01", "func")
3736
dir.create(log_dir, recursive = TRUE)
3837
dir.create(file.path(bids_dir, "sub-01"), recursive = TRUE)
3938
dir.create(out_dir, recursive = TRUE)
4039
dir.create(scratch_dir, recursive = TRUE)
4140
dir.create(bin_dir, recursive = TRUE)
42-
dir.create(r_bin, recursive = TRUE)
4341

4442
bold_file <- file.path(
4543
out_dir,
@@ -58,46 +56,39 @@ test_that("aroma sbatch reconciles non-zero exit with success token", {
5856

5957
file.create(bold_file)
6058
file.create(aroma_container)
61-
file.create(upd_job_status_path)
6259
file.create(sqlite_db)
6360
writeLines("stale fail marker", fail_file)
6461

65-
singularity_path <- file.path(bin_dir, "singularity")
6662
writeLines(
6763
c(
68-
"#!/usr/bin/env bash",
69-
"echo \"fMRIPost-AROMA finished successfully!\"",
70-
"exit 42"
64+
"args <- commandArgs(trailingOnly = TRUE)",
65+
"status <- NA_character_",
66+
"for (i in seq_along(args)) {",
67+
" if (identical(args[[i]], '--status') && i < length(args)) status <- args[[i + 1L]]",
68+
"}",
69+
"trace_file <- Sys.getenv('BG_TEST_STATUS_TRACE', unset = '')",
70+
"if (!is.na(status) && nzchar(trace_file)) {",
71+
" cat(status, file = trace_file, sep = '\\n', append = TRUE)",
72+
"}"
7173
),
72-
singularity_path
74+
upd_job_status_path
7375
)
74-
Sys.chmod(singularity_path, mode = "0755")
7576

76-
rscript_path <- file.path(r_bin, "Rscript")
77+
singularity_path <- file.path(bin_dir, "singularity")
7778
writeLines(
7879
c(
7980
"#!/usr/bin/env bash",
80-
"status=\"\"",
81-
"for ((i=1; i<=$#; i++)); do",
82-
" if [[ \"${!i}\" == \"--status\" ]]; then",
83-
" next=$((i+1))",
84-
" status=\"${!next}\"",
85-
" break",
86-
" fi",
87-
"done",
88-
"if [[ -n \"$BG_TEST_STATUS_TRACE\" && -n \"$status\" ]]; then",
89-
" echo \"$status\" >> \"$BG_TEST_STATUS_TRACE\"",
90-
"fi",
91-
"exit 0"
81+
"echo \"fMRIPost-AROMA finished successfully!\"",
82+
"exit 42"
9283
),
93-
rscript_path
84+
singularity_path
9485
)
95-
Sys.chmod(rscript_path, mode = "0755")
86+
Sys.chmod(singularity_path, mode = "0755")
9687

9788
env <- c(
9889
paste0("pkg_dir=", pkg_dir),
9990
paste0("PATH=", bin_dir, ":", Sys.getenv("PATH")),
100-
paste0("R_HOME=", r_home),
91+
paste0("R_HOME=", R.home()),
10192
paste0("BG_TEST_STATUS_TRACE=", status_trace),
10293
paste0("aroma_container=", aroma_container),
10394
paste0("loc_mrproc_root=", mrproc_dir),

tests/testthat/test-fmriprep-success-reconciliation.R

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test_that("fmriprep sbatch reconciles non-zero exit with success token", {
22
skip_if(Sys.which("bash") == "", "bash is required for shell-script integration test")
3+
skip_on_os("windows")
34

45
resolve_pkg_file <- function(inst_rel, fallback_rel) {
56
inst_path <- system.file(inst_rel, package = "BrainGnomes")
@@ -32,15 +33,12 @@ test_that("fmriprep sbatch reconciles non-zero exit with success token", {
3233
scratch_dir <- file.path(root, "scratch")
3334
templateflow_dir <- file.path(root, "templateflow")
3435
bin_dir <- file.path(root, "bin")
35-
r_home <- file.path(root, "R_HOME")
36-
r_bin <- file.path(r_home, "bin")
3736
dir.create(log_dir, recursive = TRUE)
3837
dir.create(file.path(bids_dir, "sub-01"), recursive = TRUE)
3938
dir.create(mrproc_dir, recursive = TRUE)
4039
dir.create(scratch_dir, recursive = TRUE)
4140
dir.create(templateflow_dir, recursive = TRUE)
4241
dir.create(bin_dir, recursive = TRUE)
43-
dir.create(r_bin, recursive = TRUE)
4442

4543
fmriprep_container <- file.path(root, "fmriprep.sif")
4644
fs_license_file <- file.path(root, "fs_license.txt")
@@ -56,46 +54,39 @@ test_that("fmriprep sbatch reconciles non-zero exit with success token", {
5654

5755
file.create(fmriprep_container)
5856
file.create(fs_license_file)
59-
file.create(upd_job_status_path)
6057
file.create(sqlite_db)
6158
writeLines("stale fail marker", fail_file)
6259

63-
singularity_path <- file.path(bin_dir, "singularity")
6460
writeLines(
6561
c(
66-
"#!/usr/bin/env bash",
67-
"echo \"fMRIPrep finished successfully!\"",
68-
"exit 42"
62+
"args <- commandArgs(trailingOnly = TRUE)",
63+
"status <- NA_character_",
64+
"for (i in seq_along(args)) {",
65+
" if (identical(args[[i]], '--status') && i < length(args)) status <- args[[i + 1L]]",
66+
"}",
67+
"trace_file <- Sys.getenv('BG_TEST_STATUS_TRACE', unset = '')",
68+
"if (!is.na(status) && nzchar(trace_file)) {",
69+
" cat(status, file = trace_file, sep = '\\n', append = TRUE)",
70+
"}"
6971
),
70-
singularity_path
72+
upd_job_status_path
7173
)
72-
Sys.chmod(singularity_path, mode = "0755")
7374

74-
rscript_path <- file.path(r_bin, "Rscript")
75+
singularity_path <- file.path(bin_dir, "singularity")
7576
writeLines(
7677
c(
7778
"#!/usr/bin/env bash",
78-
"status=\"\"",
79-
"for ((i=1; i<=$#; i++)); do",
80-
" if [[ \"${!i}\" == \"--status\" ]]; then",
81-
" next=$((i+1))",
82-
" status=\"${!next}\"",
83-
" break",
84-
" fi",
85-
"done",
86-
"if [[ -n \"$BG_TEST_STATUS_TRACE\" && -n \"$status\" ]]; then",
87-
" echo \"$status\" >> \"$BG_TEST_STATUS_TRACE\"",
88-
"fi",
89-
"exit 0"
79+
"echo \"fMRIPrep finished successfully!\"",
80+
"exit 42"
9081
),
91-
rscript_path
82+
singularity_path
9283
)
93-
Sys.chmod(rscript_path, mode = "0755")
84+
Sys.chmod(singularity_path, mode = "0755")
9485

9586
env <- c(
9687
paste0("pkg_dir=", pkg_dir),
9788
paste0("PATH=", bin_dir, ":", Sys.getenv("PATH")),
98-
paste0("R_HOME=", r_home),
89+
paste0("R_HOME=", R.home()),
9990
paste0("BG_TEST_STATUS_TRACE=", status_trace),
10091
paste0("fmriprep_container=", fmriprep_container),
10192
paste0("loc_mrproc_root=", mrproc_dir),

0 commit comments

Comments
 (0)