Skip to content

Commit

Permalink
Add csv format to list commands (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor authored Jan 27, 2024
1 parent 4b64b2b commit 7b0ce7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ public int listTests(OutputFormat format) throws Throwable {
case raw:
printTestsAsList(testSuits);
break;
case CSV:
case csv:
printTestsAsCsv(testSuits);
break;
default:
printTestsPretty(testSuits);
break;
Expand Down Expand Up @@ -326,6 +330,10 @@ public int listTags(OutputFormat format) throws Throwable {
case json:
printTagsAsJson(tags);
break;
case CSV:
case csv:
printTagsAsCsv(tags);
break;
default:
printTagsPretty(tags);
break;
Expand Down Expand Up @@ -357,6 +365,18 @@ private void printTestsAsList(List<ITestSuite> testSuits) {
}
}

private void printTestsAsCsv(List<ITestSuite> testSuits) {
List<String> tests = new Vector<String>();
int index = 0;
for (ITestSuite testSuite : testSuits) {
for (ITest test : testSuite.getTests()) {
tests.add(scripts.get(index).getAbsolutePath() + "@" + test.getHash().substring(0, 8));
}
index++;
}
System.out.println(String.join(",", tests));
}

private void printTestsPretty(List<ITestSuite> testSuits) {
int index = 0;
int count = 0;
Expand Down Expand Up @@ -385,6 +405,10 @@ private void printTagsAsJson(Set<String> tags) {
System.out.println(JsonOutput.toJson(tags));
}

private void printTagsAsCsv(Set<String> tags) {
System.out.println(String.join(",", tags));
}

private void printTagsPretty(Set<String> tags) {
for (String tag : tags) {
System.out.println(tag);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/askimed/nf/test/util/OutputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public enum OutputFormat {

PRETTY, RAW, JSON, pretty, raw, json
PRETTY, RAW, JSON, CSV, pretty, raw, json, csv

}

0 comments on commit 7b0ce7a

Please sign in to comment.