Skip to content

Commit e868fc1

Browse files
Merge pull request #516 from nextflow-io/nftest_bits
nf-test side quest
2 parents cf5f740 + 073cdf8 commit e868fc1

File tree

9 files changed

+1297
-0
lines changed

9 files changed

+1297
-0
lines changed

docs/side_quests/nf-test.md

Lines changed: 1121 additions & 0 deletions
Large diffs are not rendered by default.

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ nav:
1818
- hello_nextflow/04_hello_modules.md
1919
- hello_nextflow/05_hello_containers.md
2020
- hello_nextflow/06_hello_config.md
21+
- Side Quests:
22+
- side_quests/nf-test.md
2123
- hello_nextflow/survey.md
2224
- hello_nextflow/next_steps.md
2325
- Nextflow for Genomics:
@@ -173,6 +175,7 @@ plugins:
173175
- basic_training/orientation.md
174176
- advanced/index.md
175177
- advanced/orientation.md
178+
- side_quests/nf-test.md
176179
- i18n:
177180
docs_structure: suffix
178181
fallback_to_default: true

side-quests/nf-test/greetings.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hello
2+
Bonjour
3+
Holà

side-quests/nf-test/main.nf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env nextflow
2+
3+
/*
4+
* Pipeline parameters
5+
*/
6+
params.input_file = "greetings.csv"
7+
8+
/*
9+
* Use echo to print 'Hello World!' to standard out
10+
*/
11+
process sayHello {
12+
13+
publishDir 'results', mode: 'copy'
14+
15+
input:
16+
val greeting
17+
18+
output:
19+
path "${greeting}-output.txt"
20+
21+
script:
22+
"""
23+
echo '$greeting' > '$greeting-output.txt'
24+
"""
25+
}
26+
27+
/*
28+
* Use a text replace utility to convert the greeting to uppercase
29+
*/
30+
process convertToUpper {
31+
32+
publishDir 'results', mode: 'copy'
33+
34+
input:
35+
path input_file
36+
37+
output:
38+
path "UPPER-${input_file}"
39+
40+
script:
41+
"""
42+
cat '$input_file' | tr '[a-z]' '[A-Z]' > UPPER-${input_file}
43+
"""
44+
}
45+
46+
workflow {
47+
48+
// create a channel for inputs from a CSV file
49+
greeting_ch = Channel.fromPath(params.input_file).splitCsv().flatten()
50+
51+
// emit a greeting
52+
sayHello(greeting_ch)
53+
54+
// convert the greeting to uppercase
55+
convertToUpper(sayHello.out)
56+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
nextflow_process {
2+
3+
name "Test Process convertToUpper"
4+
script "main.nf"
5+
process "convertToUpper"
6+
7+
test("Should run without failures and produce correct output") {
8+
9+
when {
10+
params {
11+
// define parameters here. Example:
12+
// outdir = "tests/results"
13+
}
14+
process {
15+
"""
16+
input[0] = "${projectDir}/greetings.csv"
17+
"""
18+
}
19+
}
20+
21+
then {
22+
assert process.success
23+
assert snapshot(process.out).match()
24+
}
25+
26+
}
27+
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Should run without failures": {
3+
"content": [
4+
{
5+
"0": [
6+
"UPPER-greetings.csv:md5,f36624b0e040fa880e61fb1304b4b6b9"
7+
]
8+
}
9+
],
10+
"meta": {
11+
"nf-test": "0.9.2",
12+
"nextflow": "24.10.0"
13+
},
14+
"timestamp": "2025-02-19T11:57:20.215132756"
15+
}
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
nextflow_pipeline {
2+
3+
name "Test Workflow main.nf"
4+
script "main.nf"
5+
6+
test("Should run without failures") {
7+
8+
when {
9+
params {
10+
input_file = "${projectDir}/greetings.csv"
11+
}
12+
}
13+
14+
then {
15+
assert workflow.success
16+
assert workflow.trace.tasks().size() == 6
17+
}
18+
19+
}
20+
21+
test("Should produce correct output files") {
22+
23+
when {
24+
params {
25+
input_file = "${projectDir}/greetings.csv"
26+
}
27+
}
28+
29+
then {
30+
assert file("$launchDir/results/Bonjour-output.txt").exists()
31+
assert file("$launchDir/results/Hello-output.txt").exists()
32+
assert file("$launchDir/results/Holà-output.txt").exists()
33+
assert file("$launchDir/results/UPPER-Bonjour-output.txt").exists()
34+
assert file("$launchDir/results/UPPER-Hello-output.txt").exists()
35+
assert file("$launchDir/results/UPPER-Holà-output.txt").exists()
36+
}
37+
38+
}
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
nextflow_process {
2+
3+
name "Test Process sayHello"
4+
script "main.nf"
5+
process "sayHello"
6+
7+
test("Should run without failures and contain expected greeting") {
8+
when {
9+
params {
10+
// define parameters here
11+
}
12+
process {
13+
"""
14+
input[0] = "hello"
15+
"""
16+
}
17+
}
18+
19+
then {
20+
assert process.success
21+
assert path(process.out[0][0]).readLines().contains('hello')
22+
assert !path(process.out[0][0]).readLines().contains('HELLO')
23+
}
24+
}
25+
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
========================================================================================
3+
Nextflow config file for running tests
4+
========================================================================================
5+
*/

0 commit comments

Comments
 (0)