diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index d0e1e328..d815d50a 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -14,7 +14,8 @@ The `nf-test.config` file is a configuration file used to customize settings and | `withTrace` | Enable or disable tracing options during testing. Disable tracing if your containers don't include the `procps` tool. | `true` | | `autoSort` | Enable or disable sorted channels by default when running tests. | `true` | | `options` | Custom Nextflow command-line options to be applied when running tests. For example `"-dump-channels -stub-run"` | | -| `ignore` | List of filenames or patterns that should be ignored when building the dependency graph. For example: `ignore ['folder/**/*.nf', 'modules/module.nf']` | `` | +| `ignore` | List of filenames or patterns that should be ignored when building the dependency graph. For example: `ignore 'folder/**/*.nf', 'modules/module.nf'` | `` | +| `triggers` | List of filenames or patterns that should be trigger a full test run. For example: `triggers 'nextflow.config', 'test-data/**/*'` | `` | | `requires` | Can be used to specify the minimum required version of nf-test. Requires nf-test > 0.9.0 | `` | Here's an example of what an `nf-test.config` file could look like: diff --git a/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java b/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java index 712ca384..b5138ba6 100644 --- a/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java @@ -71,7 +71,7 @@ public Integer execute() throws Exception { DependencyResolver resolver = new DependencyResolver(new File(new File("").getAbsolutePath())); if (config != null) { - resolver.buildGraph(config.getIgnore()); + resolver.buildGraph(config.getIgnore(), config.getTriggers()); } else { resolver.buildGraph(); } diff --git a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java index 79a32a8b..0b00765b 100644 --- a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java @@ -213,7 +213,7 @@ public Integer execute() throws Exception { if (findRelatedTests) { - resolver.buildGraph(config.getIgnore()); + resolver.buildGraph(config.getIgnore(), config.getTriggers()); scripts = resolver.findRelatedTestsByFiles(testPaths); System.out.println("Found " + scripts.size() + " related test(s)"); if (scripts.isEmpty()) { @@ -229,7 +229,7 @@ public Integer execute() throws Exception { } else { if (config != null) { - resolver.buildGraph(config.getIgnore()); + resolver.buildGraph(config.getIgnore(), config.getTriggers()); } else { resolver.buildGraph(); } 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 effa0196..f836c9f1 100644 --- a/src/main/java/com/askimed/nf/test/config/Config.java +++ b/src/main/java/com/askimed/nf/test/config/Config.java @@ -1,9 +1,7 @@ package com.askimed.nf.test.config; import java.io.File; -import java.util.List; -import java.util.Vector; -import java.util.Map; +import java.util.*; import com.askimed.nf.test.App; import com.askimed.nf.test.nextflow.NextflowCommand; @@ -52,6 +50,8 @@ public class Config { private Map requires = null; + private List triggers = new Vector(); + public void testsDir(String testsDir) { this.testsDir = testsDir; } @@ -160,14 +160,42 @@ public List getIgnore() { return ignore; } - public void ignore(List ignores) { - this.ignore.addAll(ignores); + public void ignore(List ignores) { + for (Object ignore: ignores) { + this.ignore.add(ignore.toString()); + } } public void ignore(String ignore) { this.ignore.add(ignore); } + public void ignore(String ... ignore) { + this.ignore.addAll(Arrays.asList(ignore)); + } + + public void setTriggers(List triggers) { + this.triggers = triggers; + } + + public List getTriggers() { + return triggers; + } + + public void triggers(List triggers) { + for (Object trigger: triggers) { + this.triggers.add(trigger.toString()); + } + } + + public void triggers(String ... triggers) { + this.triggers.addAll(Arrays.asList(triggers)); + } + + public void trigger(String trigger) { + this.triggers.add(trigger); + } + public void stage(Closure closure) { closure.setDelegate(stageBuilder); closure.setResolveStrategy(Closure.DELEGATE_ONLY); diff --git a/src/main/java/com/askimed/nf/test/lang/dependencies/DependencyResolver.java b/src/main/java/com/askimed/nf/test/lang/dependencies/DependencyResolver.java index 001a5bac..2198d1ba 100644 --- a/src/main/java/com/askimed/nf/test/lang/dependencies/DependencyResolver.java +++ b/src/main/java/com/askimed/nf/test/lang/dependencies/DependencyResolver.java @@ -16,6 +16,8 @@ public class DependencyResolver { private DependencyGraph graph = new DependencyGraph(); + private List triggerPatterns = new Vector(); + private boolean followingDependencies = false; private static Logger log = LoggerFactory.getLogger(DependencyResolver.class); @@ -89,6 +91,13 @@ public List findRelatedTestsByFiles(List files) throws Exception { public List findRelatedTestsByFiles(File ... files) throws Exception { + for (File file: files) { + if (matches2(file.toPath(), triggerPatterns)) { + log.info("File " + file.getAbsolutePath() + " triggers full test run."); + return findAllTests(); + } + } + Set results = new HashSet(); long time0 = System.currentTimeMillis(); @@ -149,16 +158,20 @@ private Set findRelatedTestsByFile(File file, boolean followingDependencie public void buildGraph() throws Exception { - buildGraph(new Vector()); + buildGraph(new Vector(), new Vector()); } public void buildGraph(String ... ignoreGlobs) throws Exception { List list = new Vector<>(); Collections.addAll(list, ignoreGlobs); - buildGraph(list); + buildGraph(list, new Vector<>()); } - public void buildGraph(List ignoreGlobs) throws Exception { + public void buildGraph(List ignoreGlobs, List triggerPatterns) throws Exception { + + for (String glob: triggerPatterns) { + this.triggerPatterns.add(pathMatcher("glob:" + baseDir.getAbsolutePath() + "/" + glob)); + } List ignorePatterns = new Vector(); ignorePatterns.add(fileToPathMatcher(".nf-test/**")); @@ -230,6 +243,7 @@ public TestFilePattern fileToPathMatcher(File file) { public PathMatcher pathMatcher(String pattern) { + System.out.println(pattern); return FileSystems.getDefault().getPathMatcher(pattern); } @@ -243,4 +257,15 @@ public TestFilePattern matches(Path path, List ignorePatterns) return null; } + public boolean matches2(Path path, List ignorePatterns) { + PathMatcher pathMatcher; + for (PathMatcher pattern : ignorePatterns) { + if (pattern.matches(path)) { + return true; + } + } + return false; + } + + }