Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 66 additions & 25 deletions tests/filterNextflowOutput/main.nf
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
include { FASTQC } from './modules/local/fastqc'

params.failure = false
params.outdir = "results"
params.failure = false
params.outdir = "results"
params.monochrome_logs = false

workflow {

colors = getColors(params.monochrome_logs)

input = channel.of(
'sample_1',
'sample_2',
Expand All @@ -27,20 +32,20 @@ workflow {
// Print a complex nf-core/pipeline logo (ie SAREK for example)
log.info(
"""
\033[2m----------------------------------------------------\033[0m-
\033[0;32m,--.\033[0;30m/\033[0;32m,-.\033[0m
\033[0;34m ___ __ __ __ ___ \033[0;32m/,-._.--~\'\033[0m
\033[0;34m |\\ | |__ __ / ` / \\ |__) |__ \033[0;33m} {\033[0m
\033[0;34m | \\| | \\__, \\__/ | \\ |___ \033[0;32m\\`-._,-`-,\033[0m
\033[0;32m`._,._,\'\033[0m

\033[0;37m ____\033[0m
\033[0;37m .´ _ `.\033[0m
\033[0;37m / \033[0;32m|\\\033[0m`-_ \\\033[0m \033[0;34m __ __ ___ \033[0m
\033[0;37m | \033[0;32m| \\\033[0m `-|\033[0m \033[0;34m|__` /\\ |__) |__ |__/\033[0m
\033[0;37m \\ \033[0;32m| \\\033[0m /\033[0m \033[0;34m.__| /¯¯\\ | \\ |___ | \\\033[0m
\033[0;37m `\033[0;32m|\033[0m____\033[0;32m\\\033[0m´\033[0m
-\033[2m----------------------------------------------------\033[0m-
${colors.dim}----------------------------------------------------${colors.reset}-
${colors.green},--.${colors.black}/${colors.green},-.${colors.reset}
${colors.blue} ___ __ __ __ ___ ${colors.green}/,-._.--~\'${colors.reset}
${colors.blue} |\\ | |__ __ / ` / \\ |__) |__ ${colors.yellow}} {${colors.reset}
${colors.blue} | \\| | \\__, \\__/ | \\ |___ ${colors.green}\\`-._,-`-,${colors.reset}
${colors.green}`._,._,\'${colors.reset}

${colors.white} ____${colors.reset}
${colors.white} .´ _ `.${colors.reset}
${colors.white} / ${colors.green}|\\${colors.reset}`-_ \\${colors.reset} ${colors.blue} __ __ ___ ${colors.reset}
${colors.white} | ${colors.green}| \\${colors.reset} `-|${colors.reset} ${colors.blue}|__` /\\ |__) |__ |__/${colors.reset}
${colors.white} \\ ${colors.green}| \\${colors.reset} /${colors.reset} ${colors.blue}.__| /¯¯\\ | \\ |___ | \\${colors.reset}
${colors.white} `${colors.green}|${colors.reset}____${colors.green}\\${colors.reset}´${colors.reset}
-${colors.dim}----------------------------------------------------${colors.reset}-
nf-core/pipeline1 1.0dev
nf-core/pipeline2 1.0
nf-core/pipeline3 1.1.0dev
Expand Down Expand Up @@ -69,17 +74,53 @@ runName[true]: ${workflow.runName}
log.info("outdir : ${params.outdir}")

println("println message")
log.info("\033[0;34mlog.info message\033[0m")
log.warn("\033[0;33mlog.warn message\033[0m")
log.error("\033[0;31mlog.error message\033[0m")
log.info("${colors.blue}log.info message${colors.reset}")
log.warn("${colors.yellow}log.warn message${colors.reset}")
log.error("${colors.red}log.error message${colors.reset}")

println("println with path: ${test_file}")
log.info("\033[0;34mlog.info with path: ${test_file}\033[0m")
log.warn("\033[0;33mlog.warn with path: ${test_file}\033[0m")
log.error("\033[0;31mlog.error with path: ${test_file}\033[0m")
log.info("${colors.blue}log.info with path: ${test_file}${colors.reset}")
log.warn("${colors.yellow}log.warn with path: ${test_file}${colors.reset}")
log.error("${colors.red}log.error with path: ${test_file}${colors.reset}")
if (params.failure) {
System.err.println("\033[1;31mSystem error with path: ${test_file}\033[0m")
System.err.println("\033[1;31mSystem error message\033[0m")
error("\033[1;31mError with path: ${test_file}\033[0m")
System.err.println("${colors.bred}System error with path: ${test_file}${colors.reset}")
System.err.println("${colors.bred}System error message${colors.reset}")
error("${colors.bred}Error with path: ${test_file}${colors.reset}")
}
}

def getColors(monochrome_logs = true) {

def colorsDict = [:]

// Reset / Meta
colorsDict['reset'] = monochrome_logs ? '' : "\033[0m"
colorsDict['bold'] = monochrome_logs ? '' : "\033[1m"
colorsDict['dim'] = monochrome_logs ? '' : "\033[2m"
colorsDict['underlined'] = monochrome_logs ? '' : "\033[4m"
colorsDict['blink'] = monochrome_logs ? '' : "\033[5m"
colorsDict['reverse'] = monochrome_logs ? '' : "\033[7m"
colorsDict['hidden'] = monochrome_logs ? '' : "\033[8m"

// Regular Colors
colorsDict['black'] = monochrome_logs ? '' : "\033[0;30m"
colorsDict['red'] = monochrome_logs ? '' : "\033[0;31m"
colorsDict['green'] = monochrome_logs ? '' : "\033[0;32m"
colorsDict['yellow'] = monochrome_logs ? '' : "\033[0;33m"
colorsDict['blue'] = monochrome_logs ? '' : "\033[0;34m"
colorsDict['purple'] = monochrome_logs ? '' : "\033[0;35m"
colorsDict['cyan'] = monochrome_logs ? '' : "\033[0;36m"
colorsDict['white'] = monochrome_logs ? '' : "\033[0;37m"

// Bold
colorsDict['bblack'] = monochrome_logs ? '' : "\033[1;30m"
colorsDict['bred'] = monochrome_logs ? '' : "\033[1;31m"
colorsDict['bgreen'] = monochrome_logs ? '' : "\033[1;32m"
colorsDict['byellow'] = monochrome_logs ? '' : "\033[1;33m"
colorsDict['bblue'] = monochrome_logs ? '' : "\033[1;34m"
colorsDict['bpurple'] = monochrome_logs ? '' : "\033[1;35m"
colorsDict['bcyan'] = monochrome_logs ? '' : "\033[1;36m"
colorsDict['bwhite'] = monochrome_logs ? '' : "\033[1;37m"

return colorsDict
}
41 changes: 41 additions & 0 deletions tests/filterNextflowOutput/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,47 @@ nextflow_pipeline {
}
}

test("Capture both stdout and stderr and keep ANSI codes - monochrome") {

tag 'ansi'
tag 'both'
tag 'stderr'
tag 'stdout'

when {
params {
monochrome_logs = true
}
}

then {
def filtered_stdout = filterNextflowOutput(workflow.stdout, keepAnsi: true)
def filtered_stderr = filterNextflowOutput(workflow.stderr, keepAnsi: true)

// Print the stdout
println "workflow.stdout [${workflow.stdout.size()}]:"
println workflow.stdout.join('\n')

// Print the filtered stdout
println "filtered_stdout: [${filtered_stdout.size()}]"
println filtered_stdout.join('\n')

// Print the stderr
println "workflow.stderr [${workflow.stderr.size()}]:"
println workflow.stderr.join('\n')

// Print the filtered stderr
println "filtered_stderr: [${filtered_stderr.size()}]"
println filtered_stderr.join('\n')

assert workflow.success
assert snapshot(
filterNextflowOutput(workflow.stdout, keepAnsi: true, ignore: ["Submitted process"]),
filterNextflowOutput(workflow.stderr, keepAnsi: true)?:"no stderr",
filterNextflowOutput(workflow.stdout + workflow.stderr, keepAnsi: true)
).match()
}
}

test("Capture both stdout and stderr and keep ANSI codes") {

Expand Down
121 changes: 115 additions & 6 deletions tests/filterNextflowOutput/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,119 @@
]
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "25.04.6"
"nf-test": "0.9.3",
"nextflow": "25.10.0"
},
"timestamp": "2025-09-05T09:42:24.347773785"
"timestamp": "2025-10-28T11:56:48.873208114"
},
"Capture both stdout and stderr and keep ANSI codes - monochrome": {
"content": [
[
"N E X T F L O W ~ version [VERSION]",
"Launching `[PATH]/tests/filterNextflowOutput/./main.nf` [RUN_NAME] DSL2 - revision: [REVISION]",
"-----------------------------------------------------",
" ,--./,-.",
" ___ __ __ __ ___ /,-._.--~'",
" |\\ | |__ __ / ` / \\ |__) |__ } {",
" | \\| | \\__, \\__/ | \\ |___ \\`-._,-`-,",
" `._,._,'",
" ____",
" .\u00b4 _ `.",
" / |\\`-_ \\ __ __ ___ ",
" | | \\ `-| |__` /\\ |__) |__ |__/",
" \\ | \\ / .__| /\u00af\u00af\\ | \\ |___ | \\",
" `|____\\\u00b4",
"------------------------------------------------------",
"nf-core/pipeline1 [VERSION]",
"nf-core/pipeline2 [VERSION]",
"nf-core/pipeline3 [VERSION]",
"nf-core/pipeline4 [VERSION]",
"container: [CONTAINER]",
"image: [CONTAINER]",
"virtualenv: [CONTAINER]",
"profile: test,[CONTAINER],[CONTAINER],[CONTAINER]",
"runName[false]: test_run_name",
"runName[false]: amazing_mercury",
"runName[false]: [amazing_mercury]",
"runName[true]: [RUN_NAME]",
"HOME : [PATH]",
"NXF_CACHE_DIR : null",
"NXF_CONDA_CACHEDIR : null",
"NXF_HOME : [PATH]",
"NXF_SINGULARITY_CACHEDIR : [PATH]",
"NXF_SINGULARITY_LIBRARYDIR: [PATH]",
"NXF_TEMP : null",
"NXF_WORK : null",
"userName : [USER]",
"outdir : results",
"println message",
"log.info message",
"println with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
"log.info with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
" -- Check '[PATH]/.nf-test/tests/[NFT_HASH]/meta/nextflow.log' file for details",
"ERROR ~ log.error message",
"ERROR ~ log.error with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
"WARN: log.warn message",
"WARN: log.warn with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt"
],
"no stderr",
[
"N E X T F L O W ~ version [VERSION]",
"Launching `[PATH]/tests/filterNextflowOutput/./main.nf` [RUN_NAME] DSL2 - revision: [REVISION]",
"-----------------------------------------------------",
" ,--./,-.",
" ___ __ __ __ ___ /,-._.--~'",
" |\\ | |__ __ / ` / \\ |__) |__ } {",
" | \\| | \\__, \\__/ | \\ |___ \\`-._,-`-,",
" `._,._,'",
" ____",
" .\u00b4 _ `.",
" / |\\`-_ \\ __ __ ___ ",
" | | \\ `-| |__` /\\ |__) |__ |__/",
" \\ | \\ / .__| /\u00af\u00af\\ | \\ |___ | \\",
" `|____\\\u00b4",
"------------------------------------------------------",
"nf-core/pipeline1 [VERSION]",
"nf-core/pipeline2 [VERSION]",
"nf-core/pipeline3 [VERSION]",
"nf-core/pipeline4 [VERSION]",
"container: [CONTAINER]",
"image: [CONTAINER]",
"virtualenv: [CONTAINER]",
"profile: test,[CONTAINER],[CONTAINER],[CONTAINER]",
"runName[false]: test_run_name",
"runName[false]: amazing_mercury",
"runName[false]: [amazing_mercury]",
"runName[true]: [RUN_NAME]",
"HOME : [PATH]",
"NXF_CACHE_DIR : null",
"NXF_CONDA_CACHEDIR : null",
"NXF_HOME : [PATH]",
"NXF_SINGULARITY_CACHEDIR : [PATH]",
"NXF_SINGULARITY_LIBRARYDIR: [PATH]",
"NXF_TEMP : null",
"NXF_WORK : null",
"userName : [USER]",
"outdir : results",
"println message",
"log.info message",
"println with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
"log.info with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
" -- Check '[PATH]/.nf-test/tests/[NFT_HASH]/meta/nextflow.log' file for details",
"ERROR ~ log.error message",
"ERROR ~ log.error with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
"WARN: log.warn message",
"WARN: log.warn with path: [PATH]/.nf-test/tests/[NFT_HASH]/results/test.txt",
"[NXF_HASH] Submitted process > FASTQC (sample_1)",
"[NXF_HASH] Submitted process > FASTQC (sample_2)",
"[NXF_HASH] Submitted process > FASTQC (sample_3)"
]
],
"meta": {
"nf-test": "0.9.3",
"nextflow": "25.10.0"
},
"timestamp": "2025-10-28T11:47:22.144274019"
},
"Capture both stdout and stderr and keep ANSI codes": {
"content": [
Expand Down Expand Up @@ -215,9 +324,9 @@
]
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "25.04.6"
"nf-test": "0.9.3",
"nextflow": "25.10.0"
},
"timestamp": "2025-09-05T09:42:26.74594254"
"timestamp": "2025-10-28T11:56:58.291151246"
}
}
9 changes: 3 additions & 6 deletions tests/getAllFilesFromDir/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ workflow {
def trace_timestamp = new java.util.Date().format('yyyy-MM-dd_HH-mm-ss')

// stable_content
channel
.of(
channel.of(
"""
I HAVE STABLE CONTENT
""".stripIndent().trim()
)
.collectFile(storeDir: "${params.outdir}/stable", name: 'stable_content.txt', sort: true, newLine: true)

// stable_name
channel
.of(
channel.of(
"""
I DO NOT HAVE STABLE CONTENT
${trace_timestamp}
Expand All @@ -22,8 +20,7 @@ workflow {
.collectFile(storeDir: "${params.outdir}/stable", name: 'stable_name.txt', sort: true, newLine: true)

// unstable_name
channel
.of(
channel.of(
"""
I DO NOT HAVE STABLE NAME
""".stripIndent().trim()
Expand Down
9 changes: 3 additions & 6 deletions tests/getRelativePath/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ workflow {
def trace_timestamp = new java.util.Date().format('yyyy-MM-dd_HH-mm-ss')

// stable_content
channel
.of(
channel.of(
"""
I HAVE STABLE CONTENT
""".stripIndent().trim()
)
.collectFile(storeDir: "${params.outdir}/stable", name: 'stable_content.txt', sort: true, newLine: true)

// stable_name
channel
.of(
channel.of(
"""
I DO NOT HAVE STABLE CONTENT
${trace_timestamp}
Expand All @@ -22,8 +20,7 @@ workflow {
.collectFile(storeDir: "${params.outdir}/stable", name: 'stable_name.txt', sort: true, newLine: true)

// unstable_name
channel
.of(
channel.of(
"""
I DO NOT HAVE STABLE NAME
""".stripIndent().trim()
Expand Down
1 change: 1 addition & 0 deletions tests/listToMD5/main.nf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
workflow TEST {

main:
def fill = "This needs to be filled in"
def lines = [
Expand Down
3 changes: 1 addition & 2 deletions tests/removeFromYamlMap/main.nf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
workflow {
channel
.of(
channel.of(
"""
Workflow:
Pipeline: 1.0.0
Expand Down
3 changes: 1 addition & 2 deletions tests/removeNextflowVersion/main.nf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
workflow {

channel
.of(
channel.of(
"""
Workflow:
Pipeline: 1.0.0
Expand Down
Loading