Skip to content

Commit

Permalink
Add possibility to disable auto-sort for channels (#63)
Browse files Browse the repository at this point in the history
* Add possibility to disable sorted channels

* Fix typo in config properties

* Clean up code

* Add missing delete file

* Add autoSort to documentation

* Change order of items to ensure they are not sorted by default

* Remove duplicate code from tests
  • Loading branch information
lukfor authored Mar 27, 2023
1 parent 3c97e05 commit 4e77c7d
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 131 deletions.
10 changes: 6 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ config {
// run all test with the defined docker profile from the main nextflow.config
profile "docker"
// disable tracing options in case container does not include `procps` Linux tool.
withTrace = false
withTrace false
//disable sorted channels
autoSort false
}
```

Expand All @@ -49,20 +50,21 @@ nextflow_process {
script "main.nf"
process "my_process"
config "path/to/test/nextflow.config"
autoSort false
...
}
```

It is also possible to overwrite the `config` property for a specific test:
It is also possible to overwrite the `config` or `autoSort` property for a specific test:

```
nextflow_process {
test("my test") {
config "path/to/test/nextflow.config"
autoSort false
...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.askimed.nf.test.core.TestExecutionEngine;
import com.askimed.nf.test.core.reports.TapTestReportWriter;
import com.askimed.nf.test.core.reports.XmlReportWriter;
import com.askimed.nf.test.lang.TestSuiteBuilder;
import com.askimed.nf.test.plugins.PluginManager;
import com.askimed.nf.test.util.AnsiColors;

Expand Down Expand Up @@ -48,7 +49,7 @@ public class RunTestsCommand implements Callable<Integer> {
private String tap = null;

@Option(names = {
"--junitxml" }, description = "Write test results in Junit Xml Format", required = false, showDefaultValue = Visibility.ALWAYS)
"--junitxml" }, description = "Write test results in Junit Xml Format", required = false, showDefaultValue = Visibility.ALWAYS)
private String junitXml = null;

@Option(names = { "--update-snapshot",
Expand Down Expand Up @@ -96,7 +97,10 @@ public Integer call() throws Exception {
System.out.println("Found " + testPaths.size() + " files in test directory.");
}

TestSuiteBuilder.setConfig(config);

} else {
TestSuiteBuilder.setConfig(null);
System.out.println(AnsiColors.yellow("Warning: This pipeline has no nf-test config file."));
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/askimed/nf/test/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Config {

private boolean withTrace = true;

private boolean autoSort = true;

private PluginManager pluginManager = new PluginManager(PluginManager.FORCE_UPDATE);

private String configFile = DEFAULT_NEXTFLOW_CONFIG;
Expand Down Expand Up @@ -62,6 +64,10 @@ public String getProfile() {
}
}

public void withTrace(boolean withTrace) {
this.withTrace = withTrace;
}

public void setWithTrace(boolean withTrace) {
this.withTrace = withTrace;
}
Expand All @@ -70,6 +76,18 @@ public boolean isWithTrace() {
return withTrace;
}

public void setAutoSort(boolean autoSort) {
this.autoSort = autoSort;
}

public void autoSort(boolean autoSort) {
this.autoSort = autoSort;
}

public boolean isAutoSort() {
return autoSort;
}

public void libDir(String libDir) {
this.libDir = libDir;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public abstract class AbstractTest implements ITest {

private boolean updateSnapshot = false;

private boolean debug = false;

private boolean withTrace = true;

public AbstractTest() {

}
Expand Down Expand Up @@ -158,6 +162,28 @@ public ITestSuite getTestSuite() {
return suite;
}

public void debug(boolean debug) {
setDebug(debug);
}

@Override
public void setDebug(boolean debug) {
this.debug = debug;
}

public boolean isDebug() {
return debug;
}

@Override
public void setWithTrace(boolean withTrace) {
this.withTrace = withTrace;
}

public boolean isWithTrace() {
return withTrace;
}

protected void shareDirectories(String[] directories, String metaDir) throws IOException {
for (String directory : directories) {
File localDirectory = new File(directory);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import java.util.Vector;

import com.askimed.nf.test.config.Config;

public abstract class AbstractTestSuite implements ITestSuite {

private String name;
Expand All @@ -18,6 +20,13 @@ public abstract class AbstractTestSuite implements ITestSuite {

private String filename;

private boolean autoSort = true;

@Override
public void configure(Config config) {
autoSort = config.isAutoSort();
}

public void name(String name) {
this.name = name;
}
Expand Down Expand Up @@ -46,6 +55,15 @@ public String getProfile() {
return profile;
}

public void autoSort(boolean autoSort) {
this.autoSort = autoSort;
}

public boolean isAutoSort() {
return autoSort;
}


@Override
public void setGlobalConfigFile(File globalConfig) {
this.globalConfig = globalConfig;
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/askimed/nf/test/core/ITestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import java.io.File;
import java.util.List;

import com.askimed.nf.test.config.Config;

public interface ITestSuite {

public List<ITest> getTests();

public String getName();

public void setProfile(String profile);

public void setGlobalConfigFile(File config);

public void setFilename(String filename);

public String getFilename();


public void configure(Config config);

}
51 changes: 27 additions & 24 deletions src/main/java/com/askimed/nf/test/lang/TestSuiteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;

import com.askimed.nf.test.config.Config;
import com.askimed.nf.test.core.ITestSuite;
import com.askimed.nf.test.lang.function.FunctionTestSuite;
import com.askimed.nf.test.lang.pipeline.PipelineTestSuite;
Expand All @@ -18,56 +19,58 @@

public class TestSuiteBuilder {

static ITestSuite nextflow_pipeline(
@DelegatesTo(value = PipelineTestSuite.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
private static Config config = null;

final PipelineTestSuite suite = new PipelineTestSuite();
public static void setConfig(Config config) {
TestSuiteBuilder.config = config;
}

closure.setDelegate(suite);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();
public static ITestSuite nextflow_pipeline(final Closure closure) {

PipelineTestSuite suite = new PipelineTestSuite();
executeClosure(suite, closure);

return suite;

}

static ITestSuite nextflow_workflow(
@DelegatesTo(value = PipelineTestSuite.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {
public static ITestSuite nextflow_workflow(Closure closure) {

final WorkflowTestSuite suite = new WorkflowTestSuite();
WorkflowTestSuite suite = new WorkflowTestSuite();
executeClosure(suite, closure);

closure.setDelegate(suite);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();
return suite;

}

public static ITestSuite nextflow_process(Closure closure) {

ProcessTestSuite suite = new ProcessTestSuite();
executeClosure(suite, closure);

return suite;

}

static ITestSuite nextflow_process(
public static ITestSuite nextflow_function(
@DelegatesTo(value = PipelineTestSuite.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {

final ProcessTestSuite suite = new ProcessTestSuite();
FunctionTestSuite suite = new FunctionTestSuite();

closure.setDelegate(suite);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();
executeClosure(suite, closure);

return suite;

}

static ITestSuite nextflow_function(
@DelegatesTo(value = PipelineTestSuite.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) {

final FunctionTestSuite suite = new FunctionTestSuite();
private static void executeClosure(ITestSuite suite, Closure closure) {
if (config != null) {
suite.configure(config);
}

closure.setDelegate(suite);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();

return suite;

}

public static ITestSuite parse(File script) throws Exception {
Expand Down
31 changes: 8 additions & 23 deletions src/main/java/com/askimed/nf/test/lang/function/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public class FunctionTest extends AbstractTest {

private String function = null;

private boolean debug = false;

private boolean withTrace = true;

private TestCode setup;

private TestCode cleanup;
Expand Down Expand Up @@ -83,15 +79,6 @@ public void when(@DelegatesTo(value = FunctionTest.class, strategy = Closure.DEL
when = new TestCode(closure);
}

public void debug(boolean debug) {
setDebug(debug);
}

@Override
public void setDebug(boolean debug) {
this.debug = debug;
}

@Override
public void execute() throws Throwable {

Expand All @@ -105,19 +92,22 @@ public void execute() throws Throwable {
}

context.init(baseDir, outputDir.getAbsolutePath());

if (setup != null) {
setup.execute(context);
}


if (when != null) {
when.execute(context);
}

context.evaluateParamsClosure();
context.evaluateFunctionClosure();

if (isDebug()) {
System.out.println();
}

// Create workflow mock
File workflow = new File(metaDir, "mock.nf");
writeWorkflowMock(workflow);
Expand All @@ -137,12 +127,12 @@ public void execute() throws Throwable {
nextflow.addConfig(parent.getGlobalConfigFile());
nextflow.addConfig(parent.getLocalConfig());
nextflow.addConfig(getConfig());
if (withTrace) {
if (isWithTrace()) {
nextflow.setTrace(traceFile);
}
nextflow.setOut(outFile);
nextflow.setErr(errFile);
nextflow.setSilent(!debug);
nextflow.setSilent(!isDebug());
nextflow.setLog(logFile);
nextflow.setWork(workDir);
nextflow.setParamsFile(paramsFile);
Expand All @@ -160,7 +150,7 @@ public void execute() throws Throwable {
context.getWorkflow().exitStatus = exitCode;
context.getWorkflow().success = (exitCode == 0);
context.getWorkflow().failed = (exitCode != 0);
if (debug) {
if (isDebug()) {
System.out.println(AnsiText.padding("Output Channels:", 4));
context.getProcess().getOut().view();
}
Expand Down Expand Up @@ -207,9 +197,4 @@ protected void writeWorkflowMock(File file) throws IOException, CompilationFaile

}

@Override
public void setWithTrace(boolean withTrace) {
this.withTrace = withTrace;
}

}
Loading

0 comments on commit 4e77c7d

Please sign in to comment.