-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathPipelineTest.java
More file actions
145 lines (108 loc) · 3.44 KB
/
PipelineTest.java
File metadata and controls
145 lines (108 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.askimed.nf.test.lang.pipeline;
import java.io.File;
import com.askimed.nf.test.core.AbstractTest;
import com.askimed.nf.test.lang.TestCode;
import com.askimed.nf.test.nextflow.NextflowCommand;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
public class PipelineTest extends AbstractTest {
private String name = "Unknown test";
private TestCode setup;
private TestCode cleanup;
private TestCode when;
private TestCode then;
private PipelineTestSuite parent;
private PipelineContext context;
public PipelineTest(PipelineTestSuite parent) {
super(parent);
this.parent = parent;
context = new PipelineContext(this);
}
public void name(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setup(
@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
setup = new TestCode(closure);
}
public void cleanup(
@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
cleanup = new TestCode(closure);
}
public void when(@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
when = new TestCode(closure);
}
public void expect(
@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
then = new TestCode(closure);
}
public void then(@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
then = new TestCode(closure);
}
@Override
public void execute() throws Throwable {
super.execute();
context.init(this);
if (setup != null) {
setup.execute(context);
}
if (when != null) {
when.execute(context);
}
context.evaluateParamsClosure();
if (isDebug()) {
System.out.println();
}
File traceFile = new File(metaDir, FILE_TRACE);
File outFile = new File(metaDir, FILE_STD_OUT);
File errFile = new File(metaDir, FILE_STD_ERR);
File logFile = new File(metaDir, FILE_NEXTFLOW_LOG);
File paramsFile = new File(metaDir, FILE_PARAMS);
String script = parent.getScript();
if (!script.startsWith("/") && !script.startsWith("./")) {
script = new File(script).getAbsolutePath();
}
// file not found. try as github location
if (!new File(script).exists()) {
script = parent.getScript();
}
NextflowCommand nextflow = new NextflowCommand();
nextflow.setScript(script);
nextflow.setParams(context.getParams());
for (String profile : parent.getProfiles()) {
nextflow.addProfile(profile);
}
File projectConfig = new File("nextflow.config");
if (projectConfig.exists()) {
nextflow.addConfig(projectConfig);
}
nextflow.addConfig(parent.getGlobalConfigFile());
nextflow.addConfig(parent.getLocalConfig());
nextflow.addConfig(getConfig());
if (isWithTrace()) {
nextflow.setTrace(traceFile);
}
nextflow.setOut(outFile);
nextflow.setErr(errFile);
nextflow.setDebug(isDebug());
nextflow.setLog(logFile);
nextflow.setLaunchDir(baseDir);
nextflow.setWorkDir(workDir);
nextflow.setParamsFile(paramsFile);
nextflow.setOptions(getOptions());
int exitCode = nextflow.execute();
context.getWorkflow().loadFromFolder(metaDir);
context.getWorkflow().exitStatus = exitCode;
context.getWorkflow().success = (exitCode == 0);
context.getWorkflow().failed = (exitCode != 0);
then.execute(context);
}
public void cleanup() {
if (cleanup != null) {
cleanup.execute(context);
}
}
}