Skip to content

Commit 0d95443

Browse files
som-snyttadriaanm
authored andcommitted
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.
1 parent c6ce617 commit 0d95443

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

src/partest/scala/tools/partest/nest/Runner.scala

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import scala.tools.nsc.util.{ ClassPath, FakePos, ScalaClassLoader, stackTraceSt
1616
import ClassPath.{ join, split }
1717
import scala.tools.scalap.scalax.rules.scalasig.ByteCode
1818
import scala.collection.{ mutable, immutable }
19-
import scala.sys.process._
19+
import scala.sys.process.Process
2020
import java.util.concurrent.{ Executors, TimeUnit, TimeoutException }
2121
import PartestDefaults.{ javaCmd, javacCmd }
2222
import scala.tools.scalap.Main.decompileScala
@@ -136,7 +136,7 @@ class Runner(val testFile: File, fileManager: FileManager) {
136136
outDir.getAbsolutePath,
137137
"-classpath",
138138
join(outDir.toString, CLASSPATH)
139-
) ++ files.map("" + _)
139+
) ++ files.map(_.getAbsolutePath)
140140

141141
pushTranscript(args mkString " ")
142142
val captured = StreamCapture(runCommand(args, logFile))
@@ -240,8 +240,51 @@ class Runner(val testFile: File, fileManager: FileManager) {
240240
false
241241
}
242242

243+
/** Filter the diff for conditional blocks.
244+
* The check file can contain lines of the form:
245+
* `#partest java7`
246+
* where the line contains a conventional flag name.
247+
* In the diff output, these lines have the form:
248+
* `> #partest java7`
249+
* Blocks which don't apply are filtered out,
250+
* and what remains is the desired diff.
251+
* Line edit commands such as `0a1,6` don't count
252+
* as diff, so return a nonempty diff only if
253+
* material diff output was seen.
254+
* Filtering the diff output (instead of every check
255+
* file) means that we only post-process a test that
256+
* might be failing, in the normal case.
257+
*/
258+
def diffilter(d: String) = {
259+
import scala.util.Properties.javaVersion
260+
val prefix = "#partest"
261+
val margin = "> "
262+
val leader = margin + prefix
263+
// use lines in block so labeled? Default to sure, go ahead.
264+
def retainOn(f: String) = f match {
265+
case "java7" => javaVersion startsWith "1.7"
266+
case "java6" => javaVersion startsWith "1.6"
267+
case _ => true
268+
}
269+
if (d contains prefix) {
270+
val sb = new StringBuilder
271+
var retain = true // use the current line
272+
var material = false // saw a line of diff
273+
for (line <- d.lines)
274+
if (line startsWith leader) {
275+
val rest = (line stripPrefix leader).trim
276+
retain = retainOn(rest)
277+
} else if (retain) {
278+
if (line startsWith margin) material = true
279+
sb ++= line
280+
sb ++= EOL
281+
}
282+
if (material) sb.toString else ""
283+
} else d
284+
}
285+
243286
def currentDiff = (
244-
if (checkFile.canRead) compareFiles(logFile, checkFile)
287+
if (checkFile.canRead) diffilter(compareFiles(logFile, checkFile))
245288
else compareContents(augmentString(file2String(logFile)).lines.toList, Nil)
246289
)
247290

@@ -566,6 +609,7 @@ class Runner(val testFile: File, fileManager: FileManager) {
566609
diffIsOk
567610
}
568611
def runScriptTest() = {
612+
import scala.sys.process._
569613
val (swr, wr) = newTestWriters()
570614

571615
val args = file2String(testFile changeExtension "args")

test/files/neg/javac-error.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#partest java6
2+
javac-error/J.java:2: method does not override or implement a method from a supertype
3+
@Override public void foo() { }
4+
^
5+
1 error
6+
#partest java7
7+
javac-error/J.java:2: error: method does not override or implement a method from a supertype
8+
@Override public void foo() { }
9+
^
10+
1 error

test/files/neg/javac-error.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfatal-warnings

test/files/neg/javac-error/J.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class J {
2+
@Override public void foo() { }
3+
4+
public void bar() { foo(); }
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/** The System Under Test.
3+
* We bail on the earlier round that generates the first error.
4+
*/
5+
class SUT extends J

0 commit comments

Comments
 (0)