Permalink
Browse files

SI-6289 Paulptest demonstrating javac errors

This is Paul's test demonstrating that Javac errors are
correctly transcribed in the test transcript.

A gratuitous Scala class is added to a later round to
show that the test halts after the first error.

The runner must supply absolute paths to javac so that
absolute paths are reported in errors and stripped away
by partest.

The check file is differentiated for Java 6 and 7,
and partest's runner will now post-process the
`diff log check` to strip the diff which does not apply.
  • Loading branch information...
1 parent c6ce617 commit 0d954431ea8a75abfadbe198232fd39fff3ceeac @som-snytt som-snytt committed with adriaanm Mar 27, 2013
@@ -16,7 +16,7 @@ import scala.tools.nsc.util.{ ClassPath, FakePos, ScalaClassLoader, stackTraceSt
import ClassPath.{ join, split }
import scala.tools.scalap.scalax.rules.scalasig.ByteCode
import scala.collection.{ mutable, immutable }
-import scala.sys.process._
+import scala.sys.process.Process
import java.util.concurrent.{ Executors, TimeUnit, TimeoutException }
import PartestDefaults.{ javaCmd, javacCmd }
import scala.tools.scalap.Main.decompileScala
@@ -136,7 +136,7 @@ class Runner(val testFile: File, fileManager: FileManager) {
outDir.getAbsolutePath,
"-classpath",
join(outDir.toString, CLASSPATH)
- ) ++ files.map("" + _)
+ ) ++ files.map(_.getAbsolutePath)
pushTranscript(args mkString " ")
val captured = StreamCapture(runCommand(args, logFile))
@@ -240,8 +240,51 @@ class Runner(val testFile: File, fileManager: FileManager) {
false
}
+ /** Filter the diff for conditional blocks.
+ * The check file can contain lines of the form:
+ * `#partest java7`
+ * where the line contains a conventional flag name.
+ * In the diff output, these lines have the form:
+ * `> #partest java7`
+ * Blocks which don't apply are filtered out,
+ * and what remains is the desired diff.
+ * Line edit commands such as `0a1,6` don't count
+ * as diff, so return a nonempty diff only if
+ * material diff output was seen.
+ * Filtering the diff output (instead of every check
+ * file) means that we only post-process a test that
+ * might be failing, in the normal case.
+ */
+ def diffilter(d: String) = {
+ import scala.util.Properties.javaVersion
+ val prefix = "#partest"
+ val margin = "> "
+ val leader = margin + prefix
+ // use lines in block so labeled? Default to sure, go ahead.
+ def retainOn(f: String) = f match {
+ case "java7" => javaVersion startsWith "1.7"
+ case "java6" => javaVersion startsWith "1.6"
+ case _ => true
+ }
+ if (d contains prefix) {
+ val sb = new StringBuilder
+ var retain = true // use the current line
+ var material = false // saw a line of diff
+ for (line <- d.lines)
+ if (line startsWith leader) {
+ val rest = (line stripPrefix leader).trim
+ retain = retainOn(rest)
+ } else if (retain) {
+ if (line startsWith margin) material = true
+ sb ++= line
+ sb ++= EOL
+ }
+ if (material) sb.toString else ""
+ } else d
+ }
+
def currentDiff = (
- if (checkFile.canRead) compareFiles(logFile, checkFile)
+ if (checkFile.canRead) diffilter(compareFiles(logFile, checkFile))
else compareContents(augmentString(file2String(logFile)).lines.toList, Nil)
)
@@ -566,6 +609,7 @@ class Runner(val testFile: File, fileManager: FileManager) {
diffIsOk
}
def runScriptTest() = {
+ import scala.sys.process._
val (swr, wr) = newTestWriters()
val args = file2String(testFile changeExtension "args")
@@ -0,0 +1,10 @@
+#partest java6
+javac-error/J.java:2: method does not override or implement a method from a supertype
+ @Override public void foo() { }
+ ^
+1 error
+#partest java7
+javac-error/J.java:2: error: method does not override or implement a method from a supertype
+ @Override public void foo() { }
+ ^
+1 error
@@ -0,0 +1 @@
+-Xfatal-warnings
@@ -0,0 +1,5 @@
+public class J {
+ @Override public void foo() { }
+
+ public void bar() { foo(); }
+}
@@ -0,0 +1,5 @@
+
+/** The System Under Test.
+ * We bail on the earlier round that generates the first error.
+ */
+class SUT extends J

0 comments on commit 0d95443

Please sign in to comment.