Skip to content

Commit

Permalink
Serialize null values in channel outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Jul 13, 2024
1 parent 7b11c33 commit d37ff62
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ include { ${include} } from '${script}'
// define custom rules for JSON that will be generated.
def jsonOutput =
new JsonGenerator.Options()
.excludeNulls() // Do not include fields with value null..
.addConverter(Path) { value -> value.toAbsolutePath().toString() } // Custom converter for Path. Only filename
.build()

def jsonWorkflowOutput = new JsonGenerator.Options().excludeNulls().build()


workflow {

Expand All @@ -43,6 +44,6 @@ workflow.onComplete {
errorMessage: workflow.errorMessage,
errorReport: workflow.errorReport
]
new File("\${params.nf_test_output}/workflow.json").text = jsonOutput.toJson(result)
new File("\${params.nf_test_output}/workflow.json").text = jsonWorkflowOutput.toJson(result)

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ include { ${process} } from '${script}'
// define custom rules for JSON that will be generated.
def jsonOutput =
new JsonGenerator.Options()
.excludeNulls() // Do not include fields with value null..
.addConverter(Path) { value -> value.toAbsolutePath().toString() } // Custom converter for Path. Only filename
.build()

def jsonWorkflowOutput = new JsonGenerator.Options().excludeNulls().build()


workflow {

Expand Down Expand Up @@ -83,6 +84,6 @@ workflow.onComplete {
errorMessage: workflow.errorMessage,
errorReport: workflow.errorReport
]
new File("\${params.nf_test_output}/workflow.json").text = jsonOutput.toJson(result)
new File("\${params.nf_test_output}/workflow.json").text = jsonWorkflowOutput.toJson(result)

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ include { ${workflow} } from '${script}'
// define custom rules for JSON that will be generated.
def jsonOutput =
new JsonGenerator.Options()
.excludeNulls() // Do not include fields with value null..
.addConverter(Path) { value -> value.toAbsolutePath().toString() } // Custom converter for Path. Only filename
.build()

def jsonWorkflowOutput = new JsonGenerator.Options().excludeNulls().build()

workflow {

Expand Down Expand Up @@ -83,6 +83,6 @@ workflow.onComplete {
errorMessage: workflow.errorMessage,
errorReport: workflow.errorReport
]
new File("\${params.nf_test_output}/workflow.json").text = jsonOutput.toJson(result)
new File("\${params.nf_test_output}/workflow.json").text = jsonWorkflowOutput.toJson(result)

}
9 changes: 9 additions & 0 deletions src/test/java/com/askimed/nf/test/lang/ProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public void testDisableAutoSortTestSuiteAndOverwrite() throws Exception {

}

@Test
public void testNullValuesInChannels() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/channels/null-values/return_null.nf.test" });
assertEquals(0, exitCode);

}

@Test
public void testWithNoOutputs() throws Exception {

Expand Down
8 changes: 8 additions & 0 deletions test-data/channels/null-values/return_null.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
process return_null {

output:
val null_list, emit: null_list

exec:
null_list = ["0", "1", "", null, "4"]
}
24 changes: 24 additions & 0 deletions test-data/channels/null-values/return_null.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
nextflow_process {

name "Test Process return_null"
script "./return_null.nf"
process "return_null"

test("Should run without failures") {

when {
params {}
process {}
}

then {
assert process.success

with(process.out) {
assert null_list == [["0", "1", "", null, "4"]]
}
}

}

}

0 comments on commit d37ff62

Please sign in to comment.