Skip to content

Commit

Permalink
Add variables $moduleDir and `$moduleTestDir
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Aug 31, 2023
1 parent 8e3fc42 commit 42fb4b2
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 78 deletions.
16 changes: 15 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 @@ -25,7 +25,7 @@ public abstract class AbstractTest implements ITest {
public static final String FILE_PARAMS = "params.json";

public static final String FILE_WORKFLOW_JSON = "workflow.json";

public static final String FILE_FUNCTION_JSON = "function.json";

public static final String DIRECTORY_WORK = "work";
Expand All @@ -44,6 +44,10 @@ public abstract class AbstractTest implements ITest {

public File workDir;

public File moduleDir;

public File moduleTestDir;

public File baseDir = new File(System.getProperty("user.dir"));

public File projectDir = new File(System.getProperty("user.dir"));
Expand Down Expand Up @@ -97,6 +101,16 @@ public void setup(File testDirectory) throws IOException {

}

@Override
public void execute() throws Throwable {
if (parent.getScript() != null) {
moduleDir = new File(parent.getScript()).getAbsoluteFile().getParentFile();
}
if (parent.getFilename() != null) {
moduleTestDir = new File(parent.getDirectory()).getAbsoluteFile();
}
}

public File initDirectory(String name, File root, String... childs) throws IOException {

String path = FileUtil.path(root.getAbsolutePath(), FileUtil.path(childs));
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public abstract class AbstractTestSuite implements ITestSuite {

private String script = null;

private String name;

private String profile = null;
Expand All @@ -29,14 +31,30 @@ public abstract class AbstractTestSuite implements ITestSuite {
private File homeDirectory = new File(Config.DEFAULT_HOME);

private List<String> tags = new Vector<String>();

@Override
public void configure(Config config) {
autoSort = config.isAutoSort();
options = config.getOptions();
homeDirectory = new File(config.getWorkDir());
}

public void script(String script) {
this.script = script;
}

public String getScript() {
if (script != null && isRelative(script)) {
return makeAbsolute(script);
} else {
return script;
}
}

public void setScript(String script) {
this.script = script;
}

public void name(String name) {
this.name = name;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/askimed/nf/test/lang/ParamsMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class ParamsMap extends HashMap<String, Object> {

public String workDir;

public String moduleDir;

public String moduleTestDir;

public void setBaseDir(File baseDir) {
this.baseDir = baseDir.getAbsolutePath();
put("baseDir", this.baseDir);
Expand All @@ -55,6 +59,18 @@ public void setWorkDir(File workDir) {
put("workDir", this.workDir);
}

public void setModuleDir(File moduleDir) {
if (moduleDir != null) {
this.moduleDir = moduleDir.getAbsolutePath();
put("moduleDir", this.moduleDir);
}
}

public void setModuleTestDir(File moduleTestDir) {
this.moduleTestDir = moduleTestDir.getAbsolutePath();
put("moduleTestDir", this.moduleTestDir);
}

public void load(String filename) throws CompilationFailedException, ClassNotFoundException, IOException {
load(new File(filename));
}
Expand Down Expand Up @@ -192,6 +208,10 @@ protected Map<String, Object> createNestedMap(Map<String, Object> map) {
nestedMap.put("projectDir", projectDir);
nestedMap.put("launchDir", launchDir);
nestedMap.put("workDir", workDir);
if (moduleDir != null) {
nestedMap.put("moduleDir", moduleDir);
}
nestedMap.put("moduleTestDir", moduleTestDir);
if (map != null) {
nestedMap.putAll(map);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/askimed/nf/test/lang/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class TestContext {
public File workDir;

public File outputDir;

public File moduleDir;

public File moduleTestDir;

public ITest test;

Expand All @@ -44,12 +48,16 @@ public void init(AbstractTest test) {
params.setLaunchDir(test.launchDir);
params.setWorkDir(test.workDir);
params.setOutputDir(test.outputDir);
params.setModuleDir(test.moduleDir);
params.setModuleTestDir(test.moduleTestDir);

this.baseDir = test.baseDir;
this.projectDir = test.baseDir;
this.launchDir = test.launchDir;
this.workDir = test.workDir;
this.outputDir = test.outputDir;
this.moduleDir = test.moduleDir;
this.moduleTestDir = test.moduleTestDir;
}

public ParamsMap getParams() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public void when(@DelegatesTo(value = FunctionTest.class, strategy = Closure.DEL
@Override
public void execute() throws Throwable {

super.execute();

if (parent.getScript() != null) {

File script = new File(parent.getScript());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@

public class FunctionTestSuite extends AbstractTestSuite {

private String script = null;

private String function;

public void script(String script) {
this.script = script;
}

public void function(String function) {
this.function = function;
}
Expand All @@ -29,24 +23,12 @@ public void setFunction(String function) {
this.function = function;
}

public String getScript() {
if (script != null && isRelative(script)) {
return makeAbsolute(script);
} else {
return script;
}
}

public void setScript(String script) {
this.script = script;
}

public void test(String name,
@DelegatesTo(value = FunctionTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure)
throws IOException {

final FunctionTest test = new FunctionTest(this);
test.name(name);
test.name(name);
test.setup(getHomeDirectory());
closure.setDelegate(test);
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void then(@DelegatesTo(value = PipelineTest.class, strategy = Closure.DEL
@Override
public void execute() throws Throwable {

super.execute();

context.init(this);

if (setup != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,13 @@

public class PipelineTestSuite extends AbstractTestSuite {

private String script = "main.nf";

public void script(String script) {
this.script = script;
}

public String getScript() {
if (script != null && isRelative(script)) {
return makeAbsolute(script);
} else {
return script;
}
}

public void setScript(String script) {
this.script = script;
public PipelineTestSuite() {
name("main.nf");
}

public void test(String name,
@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) throws IOException {
@DelegatesTo(value = PipelineTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure)
throws IOException {

final PipelineTest test = new PipelineTest(this);
test.name(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void autoSort(boolean autoSort) {
@Override
public void execute() throws Throwable {

super.execute();

File script = new File(parent.getScript());

if (!script.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@

public class ProcessTestSuite extends AbstractTestSuite {

private String script = null;

private String process;

public void script(String script) {
this.script = script;
}

public void process(String process) {
this.process = process;
}
Expand All @@ -29,22 +23,11 @@ public String getProcess() {
return process;
}

public String getScript() {
if (script != null && isRelative(script)) {
return makeAbsolute(script);
} else {
return script;
}
}

public void setScript(String script) {
this.script = script;
}

public void test(String name,
@DelegatesTo(value = ProcessTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) throws IOException {
@DelegatesTo(value = ProcessTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure)
throws IOException {

final ProcessTest test = new ProcessTest(this);
final ProcessTest test = new ProcessTest(this);
test.name(name);
test.setup(getHomeDirectory());
closure.setDelegate(test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public void autoSort(boolean autoSort) {
@Override
public void execute() throws Throwable {

super.execute();


File script = new File(parent.getScript());

if (!script.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@

public class WorkflowTestSuite extends AbstractTestSuite {

private String script = null;

private String workflow;

public void script(String script) {
this.script = script;
}

public void workflow(String workflow) {
this.workflow = workflow;
}
Expand All @@ -29,22 +23,11 @@ public String getWorkflow() {
return workflow;
}

public String getScript() {
if (script != null && isRelative(script)) {
return makeAbsolute(script);
} else {
return script;
}
}

public void setScript(String script) {
this.script = script;
}

public void test(String name,
@DelegatesTo(value = WorkflowTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure) throws IOException {
@DelegatesTo(value = WorkflowTest.class, strategy = Closure.DELEGATE_ONLY) final Closure closure)
throws IOException {

final WorkflowTest test = new WorkflowTest(this);
final WorkflowTest test = new WorkflowTest(this);
test.name(name);
test.setup(getHomeDirectory());
closure.setDelegate(test);
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/askimed/nf/test/lang/ProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ public void testLoadGzip() throws Exception {

}

@Test
public void testLoadGzipWithModuleDir() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/process/gzip/tests/copy_gz.nf.test" });
assertEquals(0, exitCode);

}

@Test
public void testScriptWithRelativePath() throws Exception {

Expand Down
Loading

0 comments on commit 42fb4b2

Please sign in to comment.