From e5110f98752835034b54ceb4a41966ea6e655e66 Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Thu, 12 Dec 2024 11:15:23 -0500 Subject: [PATCH 1/3] add stub run test + catch exit code error --- modules/nf-neuro/betcrop/synthbet/main.nf | 11 ++++-- .../betcrop/synthbet/tests/main.nf.test | 36 +++++++++++++++++++ .../betcrop/synthbet/tests/main.nf.test.snap | 14 +++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/modules/nf-neuro/betcrop/synthbet/main.nf b/modules/nf-neuro/betcrop/synthbet/main.nf index b122b226..cbbeddeb 100644 --- a/modules/nf-neuro/betcrop/synthbet/main.nf +++ b/modules/nf-neuro/betcrop/synthbet/main.nf @@ -40,8 +40,6 @@ process BETCROP_SYNTHBET { def prefix = task.ext.prefix ?: "${meta.id}" """ - mri_synthstrip -h - touch ${prefix}__bet_image.nii.gz touch ${prefix}__brain_mask.nii.gz @@ -49,5 +47,14 @@ process BETCROP_SYNTHBET { "${task.process}": Freesurfer: \$(mri_convert -version | grep "freesurfer" | sed -E 's/.* ([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/') END_VERSIONS + + function handle_code () { + local code=\$? + ignore=( 1 ) + exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code) + } + trap 'handle_code' ERR + + mri_synthstrip -h """ } diff --git a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test index 6fae76ab..41579760 100644 --- a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test +++ b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test @@ -48,4 +48,40 @@ nextflow_process { ) } } + + test("betcrop - synthbet - stub-run") { + + setup { + run("LOAD_TEST_DATA", alias: "LOAD_DATA") { + script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" + process { + """ + input[0] = Channel.from( [ "freesurfer.zip" ] ) + input[1] = "test.load-test-data" + """ + } + } + } + + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory.map{ + test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/anat_image.nii.gz"), + [] + ] + } + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out.versions).match() } + ) + } + } } diff --git a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test.snap b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test.snap index 8be3fb46..94588233 100644 --- a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test.snap +++ b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test.snap @@ -1,4 +1,16 @@ { + "betcrop - synthbet - stub-run": { + "content": [ + [ + "versions.yml:md5,c639461870ca534b5105f61d672f740f" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.1" + }, + "timestamp": "2024-12-12T10:54:37.644838" + }, "betcrop - synthbet": { "content": [ { @@ -52,4 +64,4 @@ }, "timestamp": "2024-11-25T18:19:01.459548926" } -} +} \ No newline at end of file From 5dc334e0c55f4cceee2eb9d1847cc4c4f888ef3a Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Thu, 12 Dec 2024 11:54:02 -0500 Subject: [PATCH 2/3] add missing `options "-stub-run"` --- modules/nf-neuro/betcrop/synthbet/tests/main.nf.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test index 41579760..bb1e4765 100644 --- a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test +++ b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test @@ -51,6 +51,8 @@ nextflow_process { test("betcrop - synthbet - stub-run") { + options "-stub-run" + setup { run("LOAD_TEST_DATA", alias: "LOAD_DATA") { script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" From dca20370d97a69c6a91c80843f417206212568e6 Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Wed, 18 Dec 2024 14:49:18 -0500 Subject: [PATCH 3/3] remove spaces --- modules/nf-neuro/betcrop/synthbet/tests/main.nf.test | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test index bb1e4765..7e71d665 100644 --- a/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test +++ b/modules/nf-neuro/betcrop/synthbet/tests/main.nf.test @@ -14,7 +14,6 @@ nextflow_process { tag "subworkflows/load_test_data" test("betcrop - synthbet") { - setup { run("LOAD_TEST_DATA", alias: "LOAD_DATA") { script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" @@ -26,7 +25,6 @@ nextflow_process { } } } - when { process { """ @@ -40,7 +38,6 @@ nextflow_process { """ } } - then { assertAll( { assert process.success }, @@ -50,9 +47,7 @@ nextflow_process { } test("betcrop - synthbet - stub-run") { - options "-stub-run" - setup { run("LOAD_TEST_DATA", alias: "LOAD_DATA") { script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" @@ -64,7 +59,6 @@ nextflow_process { } } } - when { process { """ @@ -78,7 +72,6 @@ nextflow_process { """ } } - then { assertAll( { assert process.success },