From 46323d9c1d74bdc6053cd1db8084974004e512f7 Mon Sep 17 00:00:00 2001 From: wisberg Date: Mon, 2 Jun 2003 05:23:53 +0000 Subject: [PATCH] javarun attributes for interpreting error/output streams as errors, used only when forking --- .../testing/harness/bridge/JavaRun.java | 52 +++++++++++++++++-- .../aspectj/testing/xml/AjcSpecXmlReader.java | 4 +- .../testing/harness/bridge/AjcSpecTest.java | 2 + tests/ajcTestSuite.dtd | 2 + 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/testing/src/org/aspectj/testing/harness/bridge/JavaRun.java b/testing/src/org/aspectj/testing/harness/bridge/JavaRun.java index 43c5db4c9..76785b464 100644 --- a/testing/src/org/aspectj/testing/harness/bridge/JavaRun.java +++ b/testing/src/org/aspectj/testing/harness/bridge/JavaRun.java @@ -143,6 +143,13 @@ public class JavaRun implements IAjcRun { ClassLoader loader = null; URL[] urls = FileUtil.getFileURLs(libs); boolean completedNormally = false; + if (spec.outStreamIsError) { + // XXX implement same-vm stream snooping + // strictly speaking, also warn for errStream, but + // it is on by default (in same-VM, Tester controls; + // in other-vm stream-snooping controls) + MessageUtil.info(status, "unimplemented: stream-based error implemented in same vm"); + } Class targetClass = null; try { loader = new TestClassLoader(urls, dirs); @@ -281,7 +288,10 @@ public class JavaRun implements IAjcRun { commandLabel.append(Arrays.asList(controller.getCommand()).toString()); final ByteArrayOutputStream errSnoop = new ByteArrayOutputStream(); + final ByteArrayOutputStream outSnoop + = new ByteArrayOutputStream(); controller.setErrSnoop(errSnoop); + controller.setOutSnoop(outSnoop); controller.start(); // give it 3 minutes... long maxTime = System.currentTimeMillis() + 3 * 60 * 1000; @@ -305,10 +315,24 @@ public class JavaRun implements IAjcRun { } } if (0 < errSnoop.size()) { - MessageUtil.error(handler, errSnoop.toString()); - if (!doneFlag.failed) { - doneFlag.failed = true; - } + if (spec.errStreamIsError) { + MessageUtil.error(handler, errSnoop.toString()); + if (!doneFlag.failed) { + doneFlag.failed = true; + } + } else { + MessageUtil.info(handler, "Error stream: " + errSnoop.toString()); + } + } + if (0 < outSnoop.size()) { + if (spec.outStreamIsError) { + MessageUtil.error(handler, outSnoop.toString()); + if (!doneFlag.failed) { + doneFlag.failed = true; + } + } else { + MessageUtil.info(handler, "Output stream: " + outSnoop.toString()); + } } if (doneFlag.failed) { MessageUtil.info(handler, "other-vm command-line: " + commandLabel); @@ -409,6 +433,12 @@ public class JavaRun implements IAjcRun { /** if true, skip Tester setup (e.g., if Tester n/a) */ protected boolean skipTester; + /** if true, report text to output stream as error */ + protected boolean outStreamIsError; + + /** if true, report text to error stream as error */ + protected boolean errStreamIsError = true; + public Spec() { super(XMLNAME); setXMLNames(NAMES); @@ -428,6 +458,14 @@ public class JavaRun implements IAjcRun { this.className = className; } + public void setErrStreamIsError(boolean errStreamIsError) { + this.errStreamIsError = errStreamIsError; + } + + public void setOutStreamIsError(boolean outStreamIsError) { + this.outStreamIsError = outStreamIsError; + } + /** @param skip if true, then do not set up Tester */ public void setSkipTester(boolean skip) { skipTester = skip; @@ -467,6 +505,12 @@ public class JavaRun implements IAjcRun { if (null != javaVersion) { out.printAttribute("vm", javaVersion); } + if (outStreamIsError) { + out.printAttribute("outStreamIsError", "true"); + } + if (!errStreamIsError) { // defaults to true + out.printAttribute("errStreamIsError", "false"); + } super.writeAttributes(out); out.endAttributes(); if (!LangUtil.isEmpty(dirChanges)) { diff --git a/testing/src/org/aspectj/testing/xml/AjcSpecXmlReader.java b/testing/src/org/aspectj/testing/xml/AjcSpecXmlReader.java index 9736486c1..63d324149 100644 --- a/testing/src/org/aspectj/testing/xml/AjcSpecXmlReader.java +++ b/testing/src/org/aspectj/testing/xml/AjcSpecXmlReader.java @@ -395,7 +395,9 @@ public class AjcSpecXmlReader { jrunspec.addMessage((IMessage) null); // input s.b. interpretable by Boolean.valueOf(String) jrunspec.setSkipTester(true); - + jrunspec.setErrStreamIsError(true); + jrunspec.setOutStreamIsError(true); + DirChanges.Spec dcspec = new DirChanges.Spec(); dcspec.setAdded((String) null); dcspec.setRemoved((String) null); diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java index 2110fbe45..2c3c46e98 100644 --- a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java +++ b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java @@ -219,6 +219,8 @@ public class AjcSpecTest extends TestCase { assertEquals(l.className, r.className); assertEquals(l.javaVersion, r.javaVersion); assertEquals(l.skipTester, r.skipTester); + assertEquals(l.outStreamIsError, r.outStreamIsError); + assertEquals(l.errStreamIsError, r.errStreamIsError); } else if (c == IncCompilerRun.class) { IncCompilerRun.Spec l = ((IncCompilerRun) lhs).spec; IncCompilerRun.Spec r = ((IncCompilerRun) rhs).spec; diff --git a/tests/ajcTestSuite.dtd b/tests/ajcTestSuite.dtd index fd512974c..c0fdc49a7 100644 --- a/tests/ajcTestSuite.dtd +++ b/tests/ajcTestSuite.dtd @@ -33,6 +33,8 @@ + + -- 2.39.5