From 59c242307021a7f327090868861123f4cd96ce0c Mon Sep 17 00:00:00 2001 From: Theo Nakfoor Date: Fri, 27 Sep 2024 00:51:46 -0700 Subject: [PATCH] Updated ListTestsCommand.java to print a structured map of test names and associated tags rather than an arbitrary list of tags for the whole project when calling 'list --tags'. --- .../nf/test/commands/ListTestsCommand.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) 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 b5138ba6..8d0d0524 100644 --- a/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java @@ -137,25 +137,29 @@ public int listTests(List testSuits, OutputFormat format) throws Thr public int listTags(List testSuits, OutputFormat format) throws Throwable { - Set tags = new HashSet(); + Map>> tests = new HashMap<>(); for (ITestSuite testSuite : testSuits) { - tags.addAll(testSuite.getTags()); + Set tagList = new HashSet<>(); + tagList.addAll(testSuite.getTags()); for (ITest test : testSuite.getTests()) { - tags.addAll(test.getTags()); + tagList.addAll(test.getTags()); } + Map> tags = new HashMap<>(); + tags.put("tags", tagList); + tests.put(testSuite.getName(), tags); } switch (format) { case JSON: case json: - printTagsAsJson(tags); + printTagsAsJson(tests); break; case CSV: case csv: - printTagsAsCsv(tags); + printTagsAsCsv(tests); break; default: - printTagsPretty(tags); + printTagsPretty(tests); break; } @@ -215,17 +219,23 @@ private void printTestsPretty(List testSuits) { System.out.println(); } - private void printTagsAsJson(Set tags) { + private void printTagsAsJson(Map>> tags) { System.out.println(JsonOutput.toJson(tags)); } - private void printTagsAsCsv(Set tags) { - System.out.println(String.join(",", tags)); + private void printTagsAsCsv(Map>> tags) { + for (Map.Entry>> entry : tags.entrySet()) { + System.out.print(entry.getKey() + ","); + for(String tag : entry.getValue().get("tags")) { + System.out.print(tag + ","); + } + System.out.println(); + } } - private void printTagsPretty(Set tags) { - for (String tag : tags) { - System.out.println(tag); + private void printTagsPretty(Map>> tags) { + for (Map.Entry>> entry : tags.entrySet()) { + System.out.println("Test: " + entry.getKey() + " Tags:" + entry.getValue().get("tags")); } }