summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--test/files/run/t3829.scala32
4 files changed, 68 insertions, 54 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)
diff --git a/test/files/run/t3829.scala b/test/files/run/t3829.scala
index a7d03f34eb..780a6a95b7 100644
--- a/test/files/run/t3829.scala
+++ b/test/files/run/t3829.scala
@@ -6,33 +6,35 @@ object Test {
val map = immutable.Map(1 -> 2, 3 -> 4)
assert(map.get(0) == None)
+ // Since r24255 defaultMap.get(x) returns None rather than
+ // using the default, so these mostly use apply.
val defmap = map.withDefaultValue(-1)
- assert(defmap.get(0) == Some(-1))
+ assert(defmap(0) == -1)
assert(defmap.size == 2)
assert(defmap.iterator.size == 2)
- assert(defmap.empty.get(0) == Some(-1))
- assert((defmap + (2 -> 3)).get(0) == Some(-1))
- assert((defmap + (2 -> 3)).get(1) == Some(2))
- assert((defmap + (2 -> 3)).get(2) == Some(3))
- assert((defmap - 1).get(0) == Some(-1))
- assert((defmap - 1).get(1) == Some(-1))
- assert((defmap - 1).get(3) == Some(4))
+ assert(defmap.empty(0) == -1)
+ assert((defmap + (2 -> 3))(0) == -1)
+ assert((defmap + (2 -> 3))(1) == 2)
+ assert((defmap + (2 -> 3))(2) == 3)
+ assert((defmap - 1)(0) == -1)
+ assert((defmap - 1)(1) == -1)
+ assert((defmap - 1)(3) == 4)
val mutmap = mutable.Map(1 -> 2, 2 -> 3)
assert(mutmap.get(0) == None)
val defmutmap = mutmap.withDefaultValue(-1)
- assert(defmutmap.get(0) == Some(-1))
- assert(defmutmap.get(3) == Some(-1))
+ assert(defmutmap(0) == -1)
+ assert(defmutmap(3) == -1)
mutmap += 3 -> 4
- assert(defmutmap.get(3) == Some(4))
- assert(defmutmap.get(1) == Some(2))
+ assert(defmutmap(3) == 4)
+ assert(defmutmap(1) == 2)
mutmap -= 1
- assert(defmutmap.get(1) == Some(-1))
+ assert(defmutmap(1) == -1)
assert(mutmap.get(1) == None)
defmutmap += 1 -> 2
- assert(defmutmap.get(1) == Some(2))
- assert(mutmap.get(1) == Some(2))
+ assert(defmutmap(1) == 2)
+ assert(mutmap(1) == 2)
}
}