-
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
- Loading branch information
Showing
5 changed files
with
185 additions
and
20 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
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
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 = { "--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 { | ||
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()); | ||
} | ||
} |