diff --git a/src/main/java/com/askimed/nf/test/lang/TestContext.java b/src/main/java/com/askimed/nf/test/lang/TestContext.java index 0446a585..1853f5a3 100644 --- a/src/main/java/com/askimed/nf/test/lang/TestContext.java +++ b/src/main/java/com/askimed/nf/test/lang/TestContext.java @@ -83,7 +83,7 @@ public WorkflowMeta getWorkflow() { } public void setWorkflow(Workflow workflow) { - this.workflow = workflow; + throw new RuntimeException("Variable 'workflow' is read only"); } public Snapshot snapshot(Object... object) { @@ -94,4 +94,35 @@ public void loadParams(String filename) throws CompilationFailedException, Class params.load(filename); } + public void setOutputDir(String outputDir) { + // The 'outputDir' variable is read-only. If an update occurs within the + // 'params' closure, update the 'outputDir' key in the hashmap instead of + // modifying the variable itself. This fixes issue 125. + params.put("outputDir", outputDir); + } + + public void setBaseDir(String baseDir) { + throw new RuntimeException("Variable 'baseDir' is read only"); + } + + public void setLaunchDir(String launchDir) { + throw new RuntimeException("Variable 'launchDir' is read only"); + } + + public void setModuleDir(String moduleDir) { + throw new RuntimeException("Variable 'moduleDir' is read only"); + } + + public void setModuleTestDir(String moduleTestDir) { + throw new RuntimeException("Variable 'moduleTestDir' is read only"); + } + + public void setProjectDir(String projectDir) { + throw new RuntimeException("Variable 'projectDir' is read only"); + } + + public void setWorkDir(String workDir) { + throw new RuntimeException("Variable 'workDir' is read only"); + } + } diff --git a/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java b/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java index ef77974e..647d974b 100644 --- a/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java +++ b/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java @@ -124,4 +124,13 @@ public void testWorkflowNonUniqueFilenames() throws Exception { } + + @Test + public void testIssue125() throws Exception { + + App app = new App(); + int exitCode = app.run(new String[] { "test", "test-data/workflow/issue125/example_wf.nf.test"}); + assertEquals(0, exitCode); + + } } diff --git a/test-data/workflow/issue125/example_wf.nf b/test-data/workflow/issue125/example_wf.nf new file mode 100644 index 00000000..acadf03a --- /dev/null +++ b/test-data/workflow/issue125/example_wf.nf @@ -0,0 +1,36 @@ +process exampleProc { + + storeDir "${outputDir}/exampleProc" + input: + tuple( + val(outputDir), + val(localOutputDir), + ) + + output: + tuple( + val(outputDir), + path("example_output/example*.txt") + ) + + shell: + """ + mkdir -p !{localOutputDir} + touch "!{localOutputDir}/example1.txt" + touch "!{localOutputDir}/example2.txt" + """ +} + + +workflow PipeWf { + take: + inputCh + + main: + inputCh + | exampleProc + | set { outputCh } + + emit: + outputCh +} \ No newline at end of file diff --git a/test-data/workflow/issue125/example_wf.nf.test b/test-data/workflow/issue125/example_wf.nf.test new file mode 100644 index 00000000..7027b2a7 --- /dev/null +++ b/test-data/workflow/issue125/example_wf.nf.test @@ -0,0 +1,50 @@ + +nextflow_workflow { + + name "Test workflow" + script "./example_wf.nf" + workflow "PipeWf" + + // This example worked correctly in 0.7.3 but fails in 0.8.0 + test("Output will not exist in default outputDir") { + + when { + + params { + outputDir = "$outputDir" + localOutputDir = "example_output" + } + workflow { + """ + input[0] = Channel.of([params.outputDir,params.localOutputDir]) + """ + } + } + + then { + assert workflow.success + assert path("${outputDir}/exampleProc/example_output").exists() + } + } + + test("Output will exist in default outputDir") { + + when { + + params { + outDir = "$outputDir" + localOutputDir = "example_output" + } + workflow { + """ + input[0] = Channel.of([params.outDir,params.localOutputDir]) + """ + } + } + + then { + assert workflow.success + assert path("${outputDir}/exampleProc/example_output").exists() + } + } +} \ No newline at end of file