Skip to content

Commit

Permalink
Update for error/warning messages
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <[email protected]>

Signed-off-by: Peter Kriens <[email protected]>
  • Loading branch information
pkriens committed Jan 23, 2024
1 parent bc9ecf9 commit 0224ff1
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 257 deletions.
11 changes: 11 additions & 0 deletions aQute.libg/src/aQute/service/reporter/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public Location dup() {
l.length = length;
return l;
}

public void to(Location l) {
l.message = message;
l.line = line;
l.file = file;
l.context = context;
l.reference = reference;
l.methodName = methodName;
l.details = details;
l.length = length;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion aQute.libg/src/aQute/service/reporter/packageinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.2.0
version 1.3.0
58 changes: 44 additions & 14 deletions biz.aQute.bnd/test/aQute/bnd/main/TestBndMainBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package aQute.bnd.main;

import static aQute.libg.re.Catalog.caseInsenstive;
import static aQute.libg.re.Catalog.lit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -8,6 +10,8 @@
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -20,11 +24,11 @@
import aQute.bnd.main.testrules.WatchedTemporaryFolder;
import aQute.bnd.osgi.About;
import aQute.bnd.osgi.Jar;
import aQute.lib.strings.Strings;
import aQute.libg.re.RE;

public class TestBndMainBase {

private static final String WARNING_LINE = "(?m)^WARNING: .*$";

@Rule
public WatchedFolder folder = new WatchedTemporaryFolder();

Expand Down Expand Up @@ -130,26 +134,52 @@ protected void expectErrorContainsPattern(String regex) {
.containsPattern(regex);
}

final static RE WARNINGS_P = caseInsenstive(lit("Warnings"));
final static RE ERRORS_P = caseInsenstive(lit("Errors"));
final static RE SEPARATOR_P = caseInsenstive(lit("-------"));

protected void expectNoError(boolean ignoreWarnings, String... expects) {
String errors = capturedStdIO.getSystemErrContent();
List<String> lines = Strings.split("\\R", errors);
boolean skip = false;
line: for (Iterator<String> it = lines.iterator(); it.hasNext();) {
String line = it.next();
if (Strings.nonNullOrEmpty(Strings.trim(line))) {
it.remove();
continue;
}

if (ignoreWarnings) {
errors = errors.replaceAll(WARNING_LINE, "")
.trim();
}
if (expects != null) {
for (String expect : expects) {
assertThat(capturedStdIO.getSystemErrContent()).as("missing error")
.contains(expect);
errors = errors.replaceAll(expect, "")
.trim();
if (SEPARATOR_P.lookingAt(line)
.isPresent()) {
it.remove();
continue;
}
if (WARNINGS_P.lookingAt(line)
.isPresent()) {
skip = ignoreWarnings;
it.remove();
continue;
} else if (ERRORS_P.lookingAt(line)
.isPresent()) {
skip = false;
it.remove();
continue;
}
if (expects != null) {
for (String expect : expects) {
if (skip)
continue line;
skip = line.contains(expect);
}
}
if (skip)
it.remove();
}
assertEquals("non-empty error output", "", errors);
assertThat(lines).isEmpty();
}

protected void expectNoError() {
expectNoError(false);
expectNoError(true);
}

protected void expectJarEntry(Jar jar, String path) {
Expand Down
36 changes: 7 additions & 29 deletions biz.aQute.bndlib.tests/test/test/MacroTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ public void testRandom() {
@Test
public void testSuper() {
try (Processor top = new Processor();
Processor middle = new Processor(top);
Processor middle = new Processor(top);
Processor bottom = new Processor(middle)) {

top.setProperty("a", "top.a");
Expand Down Expand Up @@ -1770,35 +1770,13 @@ public void testWarning() {
p.setProperty("real", "true");
Macro m = new Macro(p);

m.process(" ${warning;xw;1;2;3 ${three}}");
m.process(" ${error;xe;1;2;3 ${three}}");
m.process(" ${warning;xw;w1;w2;w3 w${three}}");
m.process(" ${error;xe;e1;e2;e3 e${three}}");
m.process(" ${if;1;$<a>}");

assertTrue(p.getWarnings()
.get(0)
.endsWith("xw"), "xw");
assertTrue(p.getWarnings()
.get(1)
.endsWith("1"), "1");
assertTrue(p.getWarnings()
.get(2)
.endsWith("2"), "2");
assertTrue(p.getWarnings()
.get(3)
.endsWith("3 333"), "3 333");

assertTrue(p.getErrors()
.get(0)
.endsWith("xe"), "xw");
assertTrue(p.getErrors()
.get(1)
.endsWith("1"), "1");
assertTrue(p.getErrors()
.get(2)
.endsWith("2"), "2");
assertTrue(p.getErrors()
.get(3)
.endsWith("3 333"), "3 333");
assertThat(p.getWarnings()).containsExactly("xw", "w1", "w2", "w3 w333",
"No translation found for macro: a");
assertThat(p.getErrors()).containsExactly("xe", "e1", "e2", "e3 e333");
} catch (IOException e) {
fail(e);
}
Expand Down Expand Up @@ -1919,7 +1897,7 @@ public void testJoin() {
assertEquals("aa\nbb\ncc\ndd\nee\nff", m.process("${unescape;${sjoin;\\n;aa,bb,cc;dd,ee,ff}}"));
} catch (IOException e) {
fail(e);
}
}
}

@Test
Expand Down
Loading

0 comments on commit 0224ff1

Please sign in to comment.