@@ -15,6 +15,22 @@ import spock.lang.Specification
15
15
*/
16
16
class OutputDslTest extends Specification {
17
17
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
+
18
34
def ' should publish workflow outputs' () {
19
35
given :
20
36
def root = Files . createTempDirectory(' test' )
@@ -40,16 +56,9 @@ class OutputDslTest extends Specification {
40
56
}
41
57
Global . session = session
42
58
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])
46
61
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)
53
62
def dsl = new OutputDsl ()
54
63
and :
55
64
SysEnv . push(NXF_FILE_ROOT : root. toString())
@@ -65,14 +74,7 @@ class OutputDslTest extends Specification {
65
74
}
66
75
}
67
76
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)
76
78
then :
77
79
outputDir. resolve(' foo/file1.txt' ). text == ' Hello'
78
80
outputDir. resolve(' barbar/file2.txt' ). text == ' world'
@@ -89,6 +91,43 @@ class OutputDslTest extends Specification {
89
91
root?. deleteDir()
90
92
}
91
93
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
+
92
131
def ' should set publish options in output declaration' () {
93
132
when :
94
133
def dsl1 = new OutputDsl.DeclareDsl ()
0 commit comments