11test_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