-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reformat coverage and move export to command * Add simple html coverage report * Fix coverage badge * Add basic documentation
- Loading branch information
Showing
8 changed files
with
289 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `coverage` command | ||
|
||
:octicons-tag-24: 0.9.0 | ||
|
||
## Usage | ||
|
||
``` | ||
nf-test coverage | ||
``` | ||
|
||
The `coverage` command prints information about the number of Nextflow files that are covered by a test. | ||
|
||
### Optional Arguments | ||
|
||
#### `--csv <filename>` | ||
Writes a coverage report in csv format. | ||
|
||
#### `--html <filename>` | ||
Writes a coverage report in html format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/com/askimed/nf/test/commands/CoverageCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.askimed.nf.test.commands; | ||
|
||
import com.askimed.nf.test.config.Config; | ||
import com.askimed.nf.test.lang.dependencies.Coverage; | ||
import com.askimed.nf.test.lang.dependencies.DependencyResolver; | ||
import com.askimed.nf.test.util.AnsiColors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Help.Visibility; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Command(name = "coverage") | ||
public class CoverageCommand extends AbstractCommand { | ||
|
||
private static final String SHARD_STRATEGY_ROUND_ROBIN = "round-robin"; | ||
|
||
@Option(names = { | ||
"--csv" }, description = "Write coverage results in csv format", required = false, showDefaultValue = Visibility.ALWAYS) | ||
private String csv = null; | ||
|
||
@Option(names = { | ||
"--html" }, description = "Write coverage results in html format", required = false, showDefaultValue = Visibility.ALWAYS) | ||
private String html = null; | ||
|
||
|
||
@Option(names = { "--config", | ||
"-c" }, description = "nf-test.config filename", required = false, showDefaultValue = Visibility.ALWAYS) | ||
private String configFilename = Config.FILENAME; | ||
|
||
private static Logger log = LoggerFactory.getLogger(CoverageCommand.class); | ||
|
||
@Override | ||
public Integer execute() throws Exception { | ||
|
||
List<File> scripts = new ArrayList<File>(); | ||
Config config = null; | ||
|
||
try { | ||
|
||
File defaultConfigFile = null; | ||
boolean defaultWithTrace = true; | ||
try { | ||
File configFile = new File(configFilename); | ||
if (configFile.exists()) { | ||
log.info("Load config from file {}...", configFile.getAbsolutePath()); | ||
config = Config.parse(configFile); | ||
} else { | ||
System.out.println(AnsiColors.yellow("Warning: This pipeline has no nf-test config file.")); | ||
log.warn("No nf-test config file found."); | ||
} | ||
|
||
} catch (Exception e) { | ||
|
||
System.out.println(AnsiColors.red("Error: Syntax errors in nf-test config file: " + e)); | ||
log.error("Parsing config file failed", e); | ||
return 2; | ||
|
||
} | ||
|
||
File baseDir = new File(new File("").getAbsolutePath()); | ||
DependencyResolver resolver = new DependencyResolver(baseDir); | ||
resolver.setFollowingDependencies(true); | ||
|
||
|
||
if (config != null) { | ||
resolver.buildGraph(config.getIgnore(), config.getTriggers()); | ||
} else { | ||
resolver.buildGraph(); | ||
} | ||
|
||
Coverage coverage = new Coverage(resolver).getAll(); | ||
if (csv != null) { | ||
coverage.exportAsCsv(csv); | ||
} else if (html != null) { | ||
coverage.exportAsHtml(html); | ||
} else { | ||
coverage.printDetails(); | ||
} | ||
|
||
return 0; | ||
|
||
} catch (Throwable e) { | ||
|
||
System.out.println(AnsiColors.red("Error: " + e));log.error("Running tests failed.", e); | ||
return 1; | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/askimed/nf/test/lang/dependencies/CoverageItemSorter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.askimed.nf.test.lang.dependencies; | ||
|
||
public class CoverageItemSorter implements java.util.Comparator<Coverage.CoverageItem> { | ||
|
||
@Override | ||
public int compare(Coverage.CoverageItem o1, Coverage.CoverageItem o2) { | ||
return o1.getFile().getAbsolutePath().compareTo(o2.getFile().getAbsolutePath()); | ||
} | ||
} |
Oops, something went wrong.