Skip to content

Commit 039ad40

Browse files
authored
Fix false error in workflow output (#5982)
--------- Signed-off-by: Ben Sherman <[email protected]>
1 parent f06aaf6 commit 039ad40

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed

modules/nextflow/src/main/groovy/nextflow/script/OutputDsl.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ class OutputDsl {
5959

6060
// make sure every output was assigned
6161
for( final name : declarations.keySet() ) {
62-
if( name !in outputs )
62+
if( !outputs.containsKey(name) )
6363
throw new ScriptRuntimeException("Workflow output '${name}' was declared in the output block but not assigned in the workflow")
6464
}
6565

6666
for( final name : outputs.keySet() ) {
67-
if( name !in declarations )
67+
if( !declarations.containsKey(name) )
6868
throw new ScriptRuntimeException("Workflow output '${name}' was assigned in the workflow but not declared in the output block")
6969
}
7070

modules/nextflow/src/test/groovy/nextflow/script/OutputDslTest.groovy

+56-17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ import spock.lang.Specification
1515
*/
1616
class OutputDslTest extends Specification {
1717

18+
void assignOutput(Session session, String name, List values) {
19+
def ch = new DataflowQueue()
20+
values.each { v -> ch.bind(v) }
21+
ch.bind(Channel.STOP)
22+
session.outputs.put(name, ch)
23+
}
24+
25+
void await(OutputDsl dsl) {
26+
def now = System.currentTimeMillis()
27+
while( !dsl.complete ) {
28+
sleep 100
29+
if( System.currentTimeMillis() - now > 5_000 )
30+
throw new TimeoutException()
31+
}
32+
}
33+
1834
def 'should publish workflow outputs'() {
1935
given:
2036
def root = Files.createTempDirectory('test')
@@ -40,16 +56,9 @@ class OutputDslTest extends Specification {
4056
}
4157
Global.session = session
4258
and:
43-
def ch1 = new DataflowQueue()
44-
ch1.bind(file1)
45-
ch1.bind(Channel.STOP)
59+
assignOutput(session, 'foo', [file1])
60+
assignOutput(session, 'bar', [file2])
4661
and:
47-
def ch2 = new DataflowQueue()
48-
ch2.bind(file2)
49-
ch2.bind(Channel.STOP)
50-
and:
51-
session.outputs.put('foo', ch1)
52-
session.outputs.put('bar', ch2)
5362
def dsl = new OutputDsl()
5463
and:
5564
SysEnv.push(NXF_FILE_ROOT: root.toString())
@@ -65,14 +74,7 @@ class OutputDslTest extends Specification {
6574
}
6675
}
6776
dsl.apply(session)
68-
69-
def now = System.currentTimeMillis()
70-
while( !dsl.complete ) {
71-
sleep 100
72-
if( System.currentTimeMillis() - now > 5_000 )
73-
throw new TimeoutException()
74-
}
75-
77+
await(dsl)
7678
then:
7779
outputDir.resolve('foo/file1.txt').text == 'Hello'
7880
outputDir.resolve('barbar/file2.txt').text == 'world'
@@ -89,6 +91,43 @@ class OutputDslTest extends Specification {
8991
root?.deleteDir()
9092
}
9193

94+
def 'should accept empty output declaration'() {
95+
given:
96+
def root = Files.createTempDirectory('test')
97+
def outputDir = root.resolve('results')
98+
def workDir = root.resolve('work')
99+
def work1 = workDir.resolve('ab/1234'); Files.createDirectories(work1)
100+
def file1 = work1.resolve('file1.txt'); file1.text = 'Hello'
101+
and:
102+
def session = Mock(Session) {
103+
getOutputs() >> [:]
104+
getConfig() >> [:]
105+
getOutputDir() >> outputDir
106+
getWorkDir() >> workDir
107+
}
108+
Global.session = session
109+
and:
110+
assignOutput(session, 'foo', [file1])
111+
and:
112+
def dsl = new OutputDsl()
113+
and:
114+
SysEnv.push(NXF_FILE_ROOT: root.toString())
115+
116+
when:
117+
dsl.declare('foo') {
118+
}
119+
dsl.apply(session)
120+
await(dsl)
121+
then:
122+
outputDir.resolve('file1.txt').text == 'Hello'
123+
and:
124+
1 * session.notifyFilePublish(outputDir.resolve('file1.txt'), file1, null)
125+
126+
cleanup:
127+
SysEnv.pop()
128+
root?.deleteDir()
129+
}
130+
92131
def 'should set publish options in output declaration' () {
93132
when:
94133
def dsl1 = new OutputDsl.DeclareDsl()

0 commit comments

Comments
 (0)