Skip to content

Commit 98e8e4b

Browse files
phalleradriaanm
authored andcommitted
Fixed scala#581. Made script tester more robust.
1 parent 06bf1b5 commit 98e8e4b

File tree

2 files changed

+69
-36
lines changed

2 files changed

+69
-36
lines changed

scala/tools/partest/nest/ConsoleRunner.scala

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ class ConsoleRunner extends DirectRunner {
8989
NestUI.verbose("adding test file "+file)
9090
testFiles = file :: testFiles
9191
} else {
92-
NestUI.failure("File \"" + arg + "\" not found")
92+
NestUI.failure("File \"" + arg + "\" not found\n")
9393
System.exit(1)
9494
}
9595
} else if (out eq con) {
9696
val file = new File(arg)
9797
if (file.isFile || file.createNewFile)
9898
out = new PrintStream(new FileOutputStream(file))
9999
else {
100-
NestUI.failure("Result file \"" + arg + "\" not found")
100+
NestUI.failure("Result file \"" + arg + "\" not found\n")
101101
System.exit(1)
102102
}
103103
} else
@@ -162,24 +162,15 @@ class ConsoleRunner extends DirectRunner {
162162

163163
def runTests(kind: String, check: Boolean, msg: String): (Int, Int) = {
164164
if (check) {
165-
val kindFiles =
166-
if (!testFiles.isEmpty) {
167-
NestUI.verbose("testing "+testFiles)
168-
testFiles
169-
}
170-
else if (kind == "res") //TODO: is there a nicer way?
171-
fileManager.getFiles(kind, check, ".res")
172-
else
173-
fileManager.getFiles(kind, check)
165+
val kindFiles = if (kind == "res") //TODO: is there a nicer way?
166+
fileManager.getFiles(kind, check, ".res")
167+
else
168+
fileManager.getFiles(kind, check)
174169
if (!kindFiles.isEmpty) {
175170
NestUI.outline("\n"+msg+"\n")
176-
177171
runTestsForFiles(kindFiles, kind)
178-
179-
//val worker = new Worker
180-
//worker.runTests(kind, kindFiles)
181172
} else {
182-
NestUI.failure("test dir empty")
173+
NestUI.failure("test dir empty\n")
183174
(0, 0)
184175
}
185176
} else (0, 0)
@@ -189,6 +180,41 @@ class ConsoleRunner extends DirectRunner {
189180
* @return (success count, failure count)
190181
*/
191182
def testCheckAll(): (Int, Int) = {
183+
def runTestsFiles = if (!testFiles.isEmpty) {
184+
def absName(f: File): String = f.getAbsoluteFile.getCanonicalPath
185+
186+
def kindOf(f: File): String = {
187+
val firstName = absName(f)
188+
val filesPos = firstName.indexOf("files")
189+
if (filesPos == -1) {
190+
NestUI.failure("invalid test file: "+firstName+"\n")
191+
Predef.exit(1)
192+
} else {
193+
val k = firstName.substring(filesPos+6, filesPos+6+3)
194+
val short = if (k == "jvm") {
195+
if (firstName.substring(filesPos+6, filesPos+6+4) == "jvm5") "jvm5"
196+
else k
197+
} else k
198+
val shortKinds = List("pos", "neg", "run", "jvm", "jvm5", "res")
199+
if (shortKinds contains short) short
200+
else short match {
201+
case "sho" => "shootout"
202+
case "scr" => "script"
203+
}
204+
}
205+
}
206+
207+
val fstKind = kindOf(testFiles.head)
208+
NestUI.verbose("all test files expected to have kind "+fstKind)
209+
if (!testFiles.forall(kindOf(_) equals fstKind)) {
210+
NestUI.failure("test files have different kinds\n")
211+
Predef.exit(1)
212+
} else {
213+
NestUI.outline("\nTesting individual files\n")
214+
runTestsForFiles(testFiles, fstKind)
215+
}
216+
} else (0, 0)
217+
192218
if (runAll) { // run all tests
193219
posCheck = true
194220
negCheck = true
@@ -199,7 +225,8 @@ class ConsoleRunner extends DirectRunner {
199225
shootoutCheck = true
200226
scriptCheck = true
201227
}
202-
val results = List(runTests("pos", posCheck, "Testing compiler (on files whose compilation should succeed)"),
228+
val results = List(runTestsFiles,
229+
runTests("pos", posCheck, "Testing compiler (on files whose compilation should succeed)"),
203230
runTests("neg", negCheck, "Testing compiler (on files whose compilation should fail)"),
204231
runTests("run", runCheck, "Testing JVM backend"),
205232
runTests("jvm", jvmCheck, "Testing JVM backend"),

scala/tools/partest/nest/Worker.scala

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -609,25 +609,31 @@ class Worker(val fileManager: FileManager) extends Actor {
609609
" "+swriter.toString
610610
} else ""
611611

612-
val proc = Runtime.getRuntime.exec(file.getAbsolutePath+argString)
613-
val in = proc.getInputStream
614-
val err = proc.getErrorStream
615-
val writer = new PrintWriter(new FileWriter(logFile), true)
616-
val inApp = new StreamAppender(new BufferedReader(new InputStreamReader(in)),
617-
writer)
618-
val errApp = new StreamAppender(new BufferedReader(new InputStreamReader(err)),
619-
writer)
620-
val async = new Thread(errApp)
621-
async.start()
622-
inApp.run()
623-
async.join()
624-
625-
writer.close()
626-
627-
diff = compareOutput(file.getParentFile, fileBase, kind, logFile)
628-
if (!diff.equals("")) {
629-
NestUI.verbose("output differs from log file\n")
630-
succeeded = false
612+
try {
613+
val proc = Runtime.getRuntime.exec(file.getAbsolutePath+argString)
614+
val in = proc.getInputStream
615+
val err = proc.getErrorStream
616+
val writer = new PrintWriter(new FileWriter(logFile), true)
617+
val inApp = new StreamAppender(new BufferedReader(new InputStreamReader(in)),
618+
writer)
619+
val errApp = new StreamAppender(new BufferedReader(new InputStreamReader(err)),
620+
writer)
621+
val async = new Thread(errApp)
622+
async.start()
623+
inApp.run()
624+
async.join()
625+
626+
writer.close()
627+
628+
diff = compareOutput(file.getParentFile, fileBase, kind, logFile)
629+
if (!diff.equals("")) {
630+
NestUI.verbose("output differs from log file\n")
631+
succeeded = false
632+
}
633+
} catch { // *catch-all*
634+
case e: Exception =>
635+
NestUI.verbose("caught "+e)
636+
succeeded = false
631637
}
632638

633639
// delete log file only if test was successful

0 commit comments

Comments
 (0)