Skip to content

Commit

Permalink
Add stage to testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Oct 8, 2023
1 parent 0924b55 commit cc3011d
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 44 deletions.
25 changes: 25 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,28 @@ In this example:

- The `symlink` directive creates a symlink named "original_data.txt" in the `meta` directory pointing to the file located at "data/original_data.txt."
- The `copy` directive copies the "config.yml" file from the "resources" directory to the `meta` directory.

### Testsuite

Furthermore, it is also possible to stage files that are specific to a single testsuite:

```
nextflow_workflow {
name "Test workflow HELLO_WORKFLOW"
script "./hello.nf"
workflow "HELLO_WORKFLOW"
stage {
symlink "test-assets/test.txt"
}
test("Should print out test file") {
expect {
assert workflow.success
}
}
}
```
2 changes: 0 additions & 2 deletions src/main/java/com/askimed/nf/test/config/Config.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.askimed.nf.test.config;

import java.io.File;
import java.util.List;
import java.util.Vector;

import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void setup(Config config, File testDirectory) throws IOException {
log.debug("Stage {} user provided files...", config.getStageBuilder().getPaths().size());
shareDirectories(config.getStageBuilder().getPaths(), metaDir);
}
shareDirectories(parent.getStageBuilder().getPaths(), metaDir);
} catch (Exception e) {
throw new IOException("Testcase setup failed: Directories could not be shared:\n" + e);
}
Expand Down Expand Up @@ -247,7 +248,7 @@ public void setWithTrace(boolean withTrace) {
public boolean isWithTrace() {
return withTrace;
}

protected void shareDirectories(List<FileStaging> directories, File stageDir) throws IOException {
for (FileStaging directory : directories) {
String metaDirectory = FileUtil.path(stageDir.getAbsolutePath(), directory.getPath());
Expand Down
13 changes: 13 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 @@ -5,6 +5,7 @@
import java.util.Vector;

import com.askimed.nf.test.config.Config;
import com.askimed.nf.test.config.StageBuilder;
import com.askimed.nf.test.lang.extensions.SnapshotFile;

import groovy.lang.Closure;
Expand Down Expand Up @@ -41,6 +42,8 @@ public abstract class AbstractTestSuite implements ITestSuite {

private List<NamedClosure> testClosures = new Vector<NamedClosure>();

private StageBuilder stageBuilder = new StageBuilder();

private Config config;

@Override
Expand Down Expand Up @@ -137,6 +140,16 @@ public String getOptions() {
return options;
}

public void stage(Closure closure) {
closure.setDelegate(stageBuilder);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.call();
}

public StageBuilder getStageBuilder() {
return stageBuilder;
}

@Override
public void setGlobalConfigFile(File globalConfig) {
this.globalConfig = globalConfig;
Expand Down
95 changes: 54 additions & 41 deletions src/test/java/com/askimed/nf/test/lang/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testWorkflowSucces() throws Exception {
assertEquals(0, exitCode);

}

@Test
public void testWorkflowWithRelativePath() throws Exception {

Expand All @@ -43,15 +43,15 @@ public void testWorkflowWithRelativePath() throws Exception {
assertEquals(0, exitCode);

}

@Test
public void testWorkflowUnamedOutputs() throws Exception {
public void testWorkflowUnamedOutputs() throws Exception {
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/unnamed/trial.unnamed.nf.test" });
assertEquals(0, exitCode);

}

@Test
public void testWorkflowAndSnapshot() throws Exception {

Expand All @@ -60,7 +60,7 @@ public void testWorkflowAndSnapshot() throws Exception {
assertEquals(0, exitCode);

}

@Test
public void testWorkflowWithNoOutputs() throws Exception {

Expand All @@ -83,91 +83,104 @@ public void testOverrideWorkflow() throws Exception {
public void testLibs() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/libs/hello.nf.test", "--lib", "lib" ,"--debug"});
int exitCode = app
.run(new String[] { "test", "test-data/workflow/libs/hello.nf.test", "--lib", "lib", "--debug" });
assertEquals(0, exitCode);

}

@Test
public void testParamsIssue34() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue34/trial.nf.test"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue34/trial.nf.test" });
assertEquals(0, exitCode);

}

@Test
public void testParamsIssue34Setup() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue34/trial.setup.nf.test"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue34/trial.setup.nf.test" });
assertEquals(0, exitCode);

}

@Test
public void testHangingWorkflowIssue57() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/hanging/meaningless_workflow.nf.test","--debug"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app
.run(new String[] { "test", "test-data/workflow/hanging/meaningless_workflow.nf.test", "--debug" });
assertEquals(0, exitCode);

}

@Test
public void testWorkflowNonUniqueFilenames() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/non-unique-filenames/main.nf.test"});
int exitCode = app.run(new String[] { "test", "test-data/workflow/non-unique-filenames/main.nf.test" });
assertEquals(0, exitCode);

}



@Test
public void testIssue125() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue125/example_wf.nf.test"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/issue125/example_wf.nf.test" });
assertEquals(0, exitCode);

}



@Test
public void testStagingWithoutMapping() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test"});
assertEquals(1, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test" });
assertEquals(1, exitCode);

}

@Test
public void testStagingWitMappingFolder() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config", "test-data/workflow/staging/nf-test.folder.config","--debug"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config",
"test-data/workflow/staging/nf-test.folder.config", "--debug" });
assertEquals(0, exitCode);

}

@Test
public void testStagingWitMappingFile() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config", "test-data/workflow/staging/nf-test.file.config"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config",
"test-data/workflow/staging/nf-test.file.config" });
assertEquals(0, exitCode);

}

@Test
public void testStagingWitMappingFileAndMode() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config", "test-data/workflow/staging/nf-test.file.mode.config"});
assertEquals(0, exitCode);
App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello.nf.test", "--config",
"test-data/workflow/staging/nf-test.file.mode.config" });
assertEquals(0, exitCode);

}

@Test
public void testStagingInTestsuite() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/staging/hello-stage.nf.test" });
assertEquals(0, exitCode);

}

}
19 changes: 19 additions & 0 deletions test-data/workflow/staging/hello-stage.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
nextflow_workflow {

name "Test workflow HELLO_WORKFLOW"

script "./hello.nf"
workflow "HELLO_WORKFLOW"

stage {
symlink "test-assets/test.txt"
}

test("Should print out test file") {
expect {
assert workflow.success
}

}

}
19 changes: 19 additions & 0 deletions test-data/workflow/staging/hello.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
process HELLO {

input:
file input

script:
"""
cat ${input}
"""

}

workflow HELLO_WORKFLOW {

HELLO(
file("${baseDir}/test-assets/test.txt")
)

}
15 changes: 15 additions & 0 deletions test-data/workflow/staging/hello.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
nextflow_workflow {

name "Test workflow HELLO_WORKFLOW"

script "./hello.nf"
workflow "HELLO_WORKFLOW"

test("Should print out test file") {
expect {
assert workflow.success
}

}

}

0 comments on commit cc3011d

Please sign in to comment.