From cc3011dcfa3d1b87fa9a1de35abaa6a46f9a86c7 Mon Sep 17 00:00:00 2001 From: Lukas Forer Date: Sun, 8 Oct 2023 09:38:27 +0200 Subject: [PATCH] Add `stage` to testsuite --- docs/docs/configuration.md | 25 +++++ .../com/askimed/nf/test/config/Config.java | 2 - .../askimed/nf/test/core/AbstractTest.java | 3 +- .../nf/test/core/AbstractTestSuite.java | 13 +++ .../askimed/nf/test/lang/WorkflowTest.java | 95 +++++++++++-------- .../workflow/staging/hello-stage.nf.test | 19 ++++ test-data/workflow/staging/hello.nf | 19 ++++ test-data/workflow/staging/hello.nf.test | 15 +++ 8 files changed, 147 insertions(+), 44 deletions(-) create mode 100644 test-data/workflow/staging/hello-stage.nf.test create mode 100644 test-data/workflow/staging/hello.nf create mode 100644 test-data/workflow/staging/hello.nf.test diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index 17828110..e5aadb8e 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -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 + } + } + +} +``` diff --git a/src/main/java/com/askimed/nf/test/config/Config.java b/src/main/java/com/askimed/nf/test/config/Config.java index aa80ae72..d8e7d375 100644 --- a/src/main/java/com/askimed/nf/test/config/Config.java +++ b/src/main/java/com/askimed/nf/test/config/Config.java @@ -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; diff --git a/src/main/java/com/askimed/nf/test/core/AbstractTest.java b/src/main/java/com/askimed/nf/test/core/AbstractTest.java index d539aeb0..3cc6e71d 100644 --- a/src/main/java/com/askimed/nf/test/core/AbstractTest.java +++ b/src/main/java/com/askimed/nf/test/core/AbstractTest.java @@ -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); } @@ -247,7 +248,7 @@ public void setWithTrace(boolean withTrace) { public boolean isWithTrace() { return withTrace; } - + protected void shareDirectories(List directories, File stageDir) throws IOException { for (FileStaging directory : directories) { String metaDirectory = FileUtil.path(stageDir.getAbsolutePath(), directory.getPath()); diff --git a/src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java b/src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java index 9722e0a1..3b7c7af2 100644 --- a/src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java +++ b/src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java @@ -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; @@ -41,6 +42,8 @@ public abstract class AbstractTestSuite implements ITestSuite { private List testClosures = new Vector(); + private StageBuilder stageBuilder = new StageBuilder(); + private Config config; @Override @@ -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; diff --git a/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java b/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java index 4b803d4b..bd009076 100644 --- a/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java +++ b/src/test/java/com/askimed/nf/test/lang/WorkflowTest.java @@ -34,7 +34,7 @@ public void testWorkflowSucces() throws Exception { assertEquals(0, exitCode); } - + @Test public void testWorkflowWithRelativePath() throws Exception { @@ -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 { @@ -60,7 +60,7 @@ public void testWorkflowAndSnapshot() throws Exception { assertEquals(0, exitCode); } - + @Test public void testWorkflowWithNoOutputs() throws Exception { @@ -83,35 +83,37 @@ 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); } @@ -119,55 +121,66 @@ public void testHangingWorkflowIssue57() throws Exception { 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); } + } diff --git a/test-data/workflow/staging/hello-stage.nf.test b/test-data/workflow/staging/hello-stage.nf.test new file mode 100644 index 00000000..9ebf10b8 --- /dev/null +++ b/test-data/workflow/staging/hello-stage.nf.test @@ -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 + } + + } + +} diff --git a/test-data/workflow/staging/hello.nf b/test-data/workflow/staging/hello.nf new file mode 100644 index 00000000..45ffc215 --- /dev/null +++ b/test-data/workflow/staging/hello.nf @@ -0,0 +1,19 @@ +process HELLO { + + input: + file input + + script: + """ + cat ${input} + """ + +} + +workflow HELLO_WORKFLOW { + + HELLO( + file("${baseDir}/test-assets/test.txt") + ) + +} \ No newline at end of file diff --git a/test-data/workflow/staging/hello.nf.test b/test-data/workflow/staging/hello.nf.test new file mode 100644 index 00000000..50c37914 --- /dev/null +++ b/test-data/workflow/staging/hello.nf.test @@ -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 + } + + } + +}