Skip to content

Commit

Permalink
Fix issue with outputDir and make reamining variables read only
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Oct 4, 2023
1 parent 393b7b8 commit 87c7f5e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/com/askimed/nf/test/lang/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
}

}
9 changes: 9 additions & 0 deletions src/test/java/com/askimed/nf/test/lang/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
36 changes: 36 additions & 0 deletions test-data/workflow/issue125/example_wf.nf
Original file line number Diff line number Diff line change
@@ -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
}
50 changes: 50 additions & 0 deletions test-data/workflow/issue125/example_wf.nf.test
Original file line number Diff line number Diff line change
@@ -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()
}
}
}

0 comments on commit 87c7f5e

Please sign in to comment.