From 0e85c667cd761eb0ff2c759aae72f6adadfabe98 Mon Sep 17 00:00:00 2001 From: Aaron Petkau Date: Mon, 3 Jun 2024 16:10:23 -0500 Subject: [PATCH] Fixed up structure of returned empty tables --- modules/local/report.nf | 7 ++++--- tests/functions/report.nf.test | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/local/report.nf b/modules/local/report.nf index d61ae712..adf1fe77 100644 --- a/modules/local/report.nf +++ b/modules/local/report.nf @@ -813,8 +813,8 @@ def table_values(file_path, header_p, seperator, headers=null){ } else if (!header_p) { if (file_lines.size() == 0) { // headers were not in the file, and file size is 0, so return missing data based - // on passed headers - rows_list = headers.collectEntries { [(it): null] } + // on passed headers (i.e., single row of empty values) + rows_list = [headers.collectEntries { [(it): null] }] } else { // verify that passed headers and rows have same number def row_line = file_lines[0].replaceAll('(\n|\r\n)$', '') @@ -846,7 +846,8 @@ def table_values(file_path, header_p, seperator, headers=null){ if (file_lines.size() == 1) { // There is no row lines, only headers, so return missing data - rows_list = headers_from_file.collectEntries { [(it): null] } + // (single row of empty values) + rows_list = [headers_from_file.collectEntries { [(it): null] }] } else { // If there exists a row line, then make sure rows + headers match diff --git a/tests/functions/report.nf.test b/tests/functions/report.nf.test index baae3b66..2218c7d1 100644 --- a/tests/functions/report.nf.test +++ b/tests/functions/report.nf.test @@ -207,6 +207,7 @@ nextflow_function { } test("Test empty file"){ + tag "test_empty" when { function { @@ -223,9 +224,31 @@ nextflow_function { } then{ assert function.failed + assert function.stdout.any { it.contains("ERROR ~ Attempting to parse empty file") } } } + test("Test empty file pass header"){ + tag "test_empty_pass_header" + + when { + function { + """ + input[0] = file("$baseDir/tests/data/tables/empty.csv") + input[1] = false + input[2] = ',' + input[3] = ['header1', 'header2'] + """ + } + params { + outdir = "results" + } + } + then{ + assert function.success + assert function.result == ['0':['header1':'NoData', 'header2':'NoData']] + } + } test("Test more values than columns"){