summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-02-11 23:54:29 +0000
committerPaul Phillips <paulp@improving.org>2011-02-11 23:54:29 +0000
commit02fd6b6139dce48fffe46785fb6b588690885b26 (patch)
tree5f6aaa9806ca9536ccaa464452fc6a0265e3e58c /src
parent593256a6ecc799e10cd6079a61e713aede854106 (diff)
downloadscala-02fd6b6139dce48fffe46785fb6b588690885b26.tar.gz
scala-02fd6b6139dce48fffe46785fb6b588690885b26.tar.bz2
scala-02fd6b6139dce48fffe46785fb6b588690885b26.zip
I chased a lot of ghosts before finding the rea...
I chased a lot of ghosts before finding the real culprit for why partest failures have been unfailing. Process(Seq("bash", "-c", "exit 42")) ! // 42 Process(Seq("bash", "-c", "exit 42")) #> logFile ! // 0 That behavior is not yet fixed, but I altered partest not to use #> and fixed the test which should have been failing but wasn't. Closes #4227, no review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-unix.tmpl29
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala4
-rw-r--r--src/partest/scala/tools/partest/nest/Worker.scala57
3 files changed, 51 insertions, 39 deletions
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
index 92852cc5de..21b0bd7b39 100644
--- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
+++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
@@ -8,25 +8,29 @@
# PARTICULAR PURPOSE.
##############################################################################
-function onExit() {
- if [[ -n "$scaladebug" ]]; then
- echo "scala script runner trapped exit, running handler."
- fi
-
- local exit_status=${1:-$?}
+# Not sure what the right default is here: trying nonzero.
+SCALA_EXIT_STATUS=127
+REENABLE_ECHO=true
+function reenableEcho() {
+ REENABLE_ECHO=false
# reenable echo
case "$TERM" in
rxvt* | xterm* | screen*)
stty icanon echo
;;
esac
-
- exit $exit_status
}
-# install exit handler
-trap onExit EXIT
+function onExit() {
+ if $REENABLE_ECHO; then
+ reenableEcho
+ exit $SCALA_EXIT_STATUS
+ fi
+}
+
+# to reenable echo if we are interrupted before completing.
+trap onExit INT
cygwin=false;
case "`uname`" in
@@ -138,3 +142,8 @@ fi
-Denv.emacs="$EMACS" \
$CYGWIN_JLINE_TERMINAL \
@properties@ @class@ @toolflags@ "$@@"
+
+# record the exit status lest it be overwritten:
+# then reenable echo and propagate the code.
+SCALA_EXIT_STATUS=$?
+onExit
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index 3acb9b4c12..001b93d28f 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -84,9 +84,11 @@ object MainGenericRunner {
case "guess" => ScalaClassLoader.classExists(classpath, thingToRun)
}
- val result =
+ val result = try {
if (isObjectName) ObjectRunner.runAndCatch(classpath, thingToRun, command.arguments)
else ScriptRunner.runScriptAndCatch(settings, thingToRun, command.arguments)
+ }
+ catch { case ex => Left(ex) }
result match {
case Left(ex) => errorFn(ex)
diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala
index 5c6f8832f3..6e3491cfa2 100644
--- a/src/partest/scala/tools/partest/nest/Worker.scala
+++ b/src/partest/scala/tools/partest/nest/Worker.scala
@@ -275,26 +275,38 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
join(outDir.toString, CLASSPATH),
files mkString " "
)
- def fail(msg: String) = {
- SFile(output) appendAll msg
- false
- }
- try runCommand(cmd, output) match {
- case 0 => true
- case code => fail("javac failed with exit code " + code + "\n" + cmd + "\n")
- }
+
+ try runCommand(cmd, output)
catch exHandler(output, "javac command '" + cmd + "' failed:\n")
}
/** Runs command redirecting standard out and
* error out to output file.
*/
- def runCommand(command: String, output: File): Int = {
+ def runCommand(command: String, outFile: File): Boolean = {
NestUI.verbose("running command:\n"+command)
- (command #> output !)
+
+ // This is laboriously avoiding #> since it swallows exit failure code.
+ // To be revisited. XXX.
+ val out = new StringBuilder
+ val err = new StringBuilder
+ val errorLogger = ProcessLogger(x => err append (x + "\n"))
+ val pio = BasicIO(
+ false,
+ x => out append (x + "\n"),
+ Some(errorLogger)
+ )
+ val process = Process(command) run pio
+ val code = process.exitValue()
+ SFile(outFile) writeAll out.toString
+
+ (code == 0) || {
+ SFile(outFile).appendAll(command + " failed with code: " + code + "\n", err.toString)
+ false
+ }
}
- def execTest(outDir: File, logFile: File, classpathPrefix: String = "") {
+ def execTest(outDir: File, logFile: File, classpathPrefix: String = ""): Boolean = {
// check whether there is a ".javaopts" file
val argsFile = new File(logFile.getParentFile, fileBase + ".javaopts")
val argString = file2String(argsFile)
@@ -336,17 +348,6 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
)
) mkString " "
- // val errors = new StringBuilder
- // val errorLogger = ProcessLogger(errors append _)
- // NestUI.verbose("running command:\n"+command)
- // val code = (command #> output ! errorLogger)
- // if (code != 0 || isPartestDebug) {
- // SFile(logFile).appendAll(
- // "\nNon-zero exit code: " + code + ", appending stderr output.\n\n",
- // errors.toString
- // )
- // }
-
runCommand(cmd, logFile)
}
@@ -525,8 +526,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
runTestCommon(file, expectFailure = false)((logFile, outDir) => {
val dir = file.getParentFile
- execTest(outDir, logFile)
- diffCheck(compareOutput(dir, logFile))
+ execTest(outDir, logFile) && diffCheck(compareOutput(dir, logFile))
})
def runSpecializedTest(file: File): LogContext =
@@ -534,7 +534,7 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
val dir = file.getParentFile
// adding the instrumented library to the classpath
- execTest(outDir, logFile, PathSettings.srcSpecLib.toString)
+ execTest(outDir, logFile, PathSettings.srcSpecLib.toString) &&
diffCheck(compareOutput(dir, logFile))
})
@@ -828,9 +828,10 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
val ok = compileMgr.shouldCompile(List(testFile), kind, logFile)
NestUI.verbose("compilation of " + testFile + (if (ok) "succeeded" else "failed"))
if (ok) {
- execTest(outDir, logFile)
- NestUI.verbose(this+" finished running "+fileBase)
- diffCheck(compareOutput(dir, logFile))
+ execTest(outDir, logFile) && {
+ NestUI.verbose(this+" finished running "+fileBase)
+ diffCheck(compareOutput(dir, logFile))
+ }
}
LogContext(logFile, swr, wr)