summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/detach-run/actor/ServerConsole.scala2
-rw-r--r--test/files/detach-run/basic/basic.scala2
-rw-r--r--test/files/neg/found-req-variance.scala4
-rw-r--r--test/files/neg/tailrec-2.scala6
-rw-r--r--test/files/neg/tcpoly_variance.check2
-rw-r--r--test/files/neg/tcpoly_variance.scala4
-rw-r--r--test/files/neg/tcpoly_variance_enforce.check4
-rw-r--r--test/files/neg/tcpoly_variance_enforce.scala4
-rw-r--r--test/files/run/lisp.scala14
-rw-r--r--test/files/scalacheck/process.scala160
10 files changed, 181 insertions, 21 deletions
diff --git a/test/files/detach-run/actor/ServerConsole.scala b/test/files/detach-run/actor/ServerConsole.scala
index d38725ddee..8ebd9d4c2e 100644
--- a/test/files/detach-run/actor/ServerConsole.scala
+++ b/test/files/detach-run/actor/ServerConsole.scala
@@ -48,7 +48,7 @@ trait ServerConsole extends Thread {
}
terminate()
println("Server exited ("+mkTimeString(currentTime - startTime)+")")
- system.exit(0)
+ sys.exit(0)
}
protected def trace(msg: String) {
diff --git a/test/files/detach-run/basic/basic.scala b/test/files/detach-run/basic/basic.scala
index c785bd6c7d..4d0fc2d933 100644
--- a/test/files/detach-run/basic/basic.scala
+++ b/test/files/detach-run/basic/basic.scala
@@ -24,7 +24,7 @@ object Test {
private var th = new Thread(this)
def start() { th.start(); Thread.sleep(1000) }
def run() { Server.main(Array(port.toString)) }
- def terminate() { Server.terminate(); system.exit(0) }
+ def terminate() { Server.terminate(); sys.exit(0) }
}
private class ClientThread(host: String, port: Int) extends Runnable {
diff --git a/test/files/neg/found-req-variance.scala b/test/files/neg/found-req-variance.scala
index c44d021fac..024b24c367 100644
--- a/test/files/neg/found-req-variance.scala
+++ b/test/files/neg/found-req-variance.scala
@@ -42,7 +42,7 @@ object Test {
object Functions {
object Set1 {
def f[T, R](x: FF1[T, R]) = ()
- def h[T, R] : FF1[T, R] = system.error("")
+ def h[T, R] : FF1[T, R] = sys.error("")
def ff1 = f[B, B](h[A, A]) // fail
def ff2 = f[B, B](h[B, A]) // fail
@@ -56,7 +56,7 @@ object Functions {
}
object Set2 {
def f[T, R](x: FF2[T, R]) = ()
- def h[T, R] : FF2[T, R] = system.error("")
+ def h[T, R] : FF2[T, R] = sys.error("")
def ff1 = f[B, B](h[A, A]) // suggest
def ff2 = f[B, B](h[B, A]) // suggest
diff --git a/test/files/neg/tailrec-2.scala b/test/files/neg/tailrec-2.scala
index 0d446364fd..342cd85323 100644
--- a/test/files/neg/tailrec-2.scala
+++ b/test/files/neg/tailrec-2.scala
@@ -17,10 +17,10 @@ class Bop4[+A](val element: A) extends Super[A] {
}
object Other {
- def f[T] : Bop4[T] = system.error("")
+ def f[T] : Bop4[T] = sys.error("")
}
object Bop {
- def m1[A] : Super[A] = system.error("")
- def m2[A] : Bop2[A] = system.error("")
+ def m1[A] : Super[A] = sys.error("")
+ def m2[A] : Bop2[A] = sys.error("")
} \ No newline at end of file
diff --git a/test/files/neg/tcpoly_variance.check b/test/files/neg/tcpoly_variance.check
index dfe48f9544..0695fa09a1 100644
--- a/test/files/neg/tcpoly_variance.check
+++ b/test/files/neg/tcpoly_variance.check
@@ -1,5 +1,5 @@
tcpoly_variance.scala:6: error: overriding method str in class A of type => m[java.lang.Object];
method str has incompatible type
- override def str: m[String] = system.error("foo") // since x in m[x] is invariant, ! m[String] <: m[Object]
+ override def str: m[String] = sys.error("foo") // since x in m[x] is invariant, ! m[String] <: m[Object]
^
one error found
diff --git a/test/files/neg/tcpoly_variance.scala b/test/files/neg/tcpoly_variance.scala
index 04846e81d8..4b9bd50e08 100644
--- a/test/files/neg/tcpoly_variance.scala
+++ b/test/files/neg/tcpoly_variance.scala
@@ -1,7 +1,7 @@
class A[m[x]] {
- def str: m[Object] = system.error("foo")
+ def str: m[Object] = sys.error("foo")
}
class B[m[x]] extends A[m] {
- override def str: m[String] = system.error("foo") // since x in m[x] is invariant, ! m[String] <: m[Object]
+ override def str: m[String] = sys.error("foo") // since x in m[x] is invariant, ! m[String] <: m[Object]
}
diff --git a/test/files/neg/tcpoly_variance_enforce.check b/test/files/neg/tcpoly_variance_enforce.check
index 48025889fc..44b5b2c15c 100644
--- a/test/files/neg/tcpoly_variance_enforce.check
+++ b/test/files/neg/tcpoly_variance_enforce.check
@@ -36,10 +36,10 @@ object fcoll4_2 extends coll4[FooString, Any] // error
^
tcpoly_variance_enforce.scala:37: error: kinds of the type arguments (FooInvar) do not conform to the expected kinds of the type parameters (type m) in trait coll.
FooInvar's type parameters do not match type m's expected parameters: type x (in class FooInvar) is invariant, but type x is declared covariant
- def x: coll[FooInvar] = system.error("foo") // error
+ def x: coll[FooInvar] = sys.error("foo") // error
^
tcpoly_variance_enforce.scala:38: error: kinds of the type arguments (FooContra) do not conform to the expected kinds of the type parameters (type m) in trait coll.
FooContra's type parameters do not match type m's expected parameters: type x (in class FooContra) is contravariant, but type x is declared covariant
- def y: coll[FooContra] = system.error("foo") // error
+ def y: coll[FooContra] = sys.error("foo") // error
^
11 errors found
diff --git a/test/files/neg/tcpoly_variance_enforce.scala b/test/files/neg/tcpoly_variance_enforce.scala
index cbc8ad7c66..ddff0e9f94 100644
--- a/test/files/neg/tcpoly_variance_enforce.scala
+++ b/test/files/neg/tcpoly_variance_enforce.scala
@@ -34,8 +34,8 @@ object fcoll4_2 extends coll4[FooString, Any] // error
object test {
var ok: coll[FooCov] = _
- def x: coll[FooInvar] = system.error("foo") // error
- def y: coll[FooContra] = system.error("foo") // error
+ def x: coll[FooInvar] = sys.error("foo") // error
+ def y: coll[FooContra] = sys.error("foo") // error
}
diff --git a/test/files/run/lisp.scala b/test/files/run/lisp.scala
index 3436594def..f3687ea1bb 100644
--- a/test/files/run/lisp.scala
+++ b/test/files/run/lisp.scala
@@ -20,7 +20,7 @@ class LispTokenizer(s: String) extends Iterator[String] {
do i = i + 1
while (!isDelimiter(s charAt i))
s.substring(start, i)
- } else system.error("premature end of string")
+ } else sys.error("premature end of string")
}
//############################################################################
@@ -102,7 +102,7 @@ object LispCaseClasses extends Lisp {
var indent: Int = 0
def lispError[a](msg: String): a =
- system.error("error: " + msg + "\n" + curexp);
+ sys.error("error: " + msg + "\n" + curexp);
trait Environment {
def lookup(n: String): Data;
@@ -201,7 +201,7 @@ object LispCaseClasses extends Lisp {
val ps: List[String] = toList(params) map {
case SYM(name) => name
- case _ => system.error("illegal parameter list");
+ case _ => sys.error("illegal parameter list");
}
FUN(args => eval(expr, extendEnv(env, ps, args)))
@@ -237,7 +237,7 @@ object LispCaseClasses extends Lisp {
val it = new LispTokenizer(s);
def parseExpr(token: String): Data = {
if (token == "(") parseList
- else if (token == ")") system.error("unbalanced parentheses")
+ else if (token == ")") sys.error("unbalanced parentheses")
else if ('0' <= token.charAt(0) && token.charAt(0) <= '9')
NUM(token.toInt)
else if (token.charAt(0) == '\"' && token.charAt(token.length()-1)=='\"')
@@ -270,7 +270,7 @@ object LispAny extends Lisp {
var indent: Int = 0;
def lispError[a](msg: String): a =
- system.error("error: " + msg + "\n" + curexp);
+ sys.error("error: " + msg + "\n" + curexp);
trait Environment {
def lookup(n: String): Data;
@@ -392,7 +392,7 @@ object LispAny extends Lisp {
val ps: List[String] = asList(params) map {
case Symbol(name) => name
- case _ => system.error("illegal parameter list");
+ case _ => sys.error("illegal parameter list");
}
Lambda(args => eval(expr, extendEnv(env, ps, args)))
@@ -428,7 +428,7 @@ object LispAny extends Lisp {
val it = new LispTokenizer(s);
def parseExpr(token: String): Data = {
if (token == "(") parseList
- else if (token == ")") system.error("unbalanced parentheses")
+ else if (token == ")") sys.error("unbalanced parentheses")
//else if (Character.isDigit(token.charAt(0)))
else if (token.charAt(0).isDigit)
token.toInt
diff --git a/test/files/scalacheck/process.scala b/test/files/scalacheck/process.scala
new file mode 100644
index 0000000000..1e06c4669e
--- /dev/null
+++ b/test/files/scalacheck/process.scala
@@ -0,0 +1,160 @@
+/** process tests.
+ */
+
+import java.io.{ File, FileNotFoundException, IOException, InputStream, OutputStream, FileInputStream }
+import java.net.{ URI, URISyntaxException, URL }
+import org.scalacheck._
+import Prop._
+import sys.process._
+import scala.tools.nsc.io.{ File => SFile }
+
+/** This has scrounged bits of sbt to flesh it out enough to run.
+ */
+package processtest {
+
+ object exit
+ {
+ def fn(code: Int) = System.exit(code)
+ def main(args: Array[String]) = exit.fn(java.lang.Integer.parseInt(args(0)))
+ }
+ object cat
+ {
+ def main(args: Array[String])
+ {
+ try {
+ if (args.length == 0)
+ IO.transfer(System.in, System.out)
+ else
+ catFiles(args.toList)
+ exit.fn(0)
+ } catch {
+ case e =>
+ e.printStackTrace()
+ System.err.println("Error: " + e.toString)
+ exit.fn(1)
+ }
+ }
+ private def catFiles(filenames: List[String]): Option[String] = filenames match {
+ case head :: tail =>
+ val file = new File(head)
+ if (file.isDirectory)
+ throw new IOException("Is directory: " + file)
+ else if (file.exists) {
+ IO.transfer(file, System.out)
+ catFiles(tail)
+ }
+ else
+ throw new FileNotFoundException("No such file or directory: " + file)
+ case Nil => None
+ }
+ }
+ object echo
+ {
+ def main(args: Array[String])
+ {
+ System.out.println(args.mkString(" "))
+ }
+ }
+}
+
+object IO {
+ def transfer(in: InputStream, out: OutputStream): Unit = BasicIO.transferFully(in, out)
+ def transfer(in: File, out: OutputStream): Unit = BasicIO.transferFully(new FileInputStream(in), out)
+
+ def classLocation(cl: Class[_]): URL = {
+ val codeSource = cl.getProtectionDomain.getCodeSource
+ if(codeSource == null) sys.error("No class location for " + cl)
+ else codeSource.getLocation
+ }
+ def classLocationFile(cl: Class[_]): File = toFile(classLocation(cl))
+ def classLocation[T](implicit mf: Manifest[T]): URL = classLocation(mf.erasure)
+ def classLocationFile[T](implicit mf: Manifest[T]): File = classLocationFile(mf.erasure)
+
+ def toFile(url: URL) =
+ try { new File(url.toURI) }
+ catch { case _: URISyntaxException => new File(url.getPath) }
+}
+
+class ProcessSpecification extends Properties("Process I/O") {
+ implicit val exitCodeArb: Arbitrary[Array[Byte]] = Arbitrary(Gen.choose(0, 10) flatMap { size =>
+ Gen.resize(size, Arbitrary.arbArray[Byte].arbitrary)
+ })
+
+ /*property("Correct exit code") = forAll( (exitCode: Byte) => checkExit(exitCode))
+ property("#&& correct") = forAll( (exitCodes: Array[Byte]) => checkBinary(exitCodes)(_ #&& _)(_ && _))
+ property("#|| correct") = forAll( (exitCodes: Array[Byte]) => checkBinary(exitCodes)(_ #|| _)(_ || _))
+ property("### correct") = forAll( (exitCodes: Array[Byte]) => checkBinary(exitCodes)(_ ### _)( (x,latest) => latest))*/
+ property("Pipe to output file") = forAll( (data: Array[Byte]) => checkFileOut(data))
+ property("Pipe to input file") = forAll( (data: Array[Byte]) => checkFileIn(data))
+ property("Pipe to process") = forAll( (data: Array[Byte]) => checkPipe(data))
+
+ private def checkBinary(codes: Array[Byte])(reduceProcesses: (ProcessBuilder, ProcessBuilder) => ProcessBuilder)(reduceExit: (Boolean, Boolean) => Boolean) =
+ {
+ (codes.length > 1) ==>
+ {
+ val unsignedCodes = codes.map(unsigned)
+ val exitCode = unsignedCodes.map(code => Process(process("processtest.exit " + code))).reduceLeft(reduceProcesses) !
+ val expectedExitCode = unsignedCodes.map(toBoolean).reduceLeft(reduceExit)
+ toBoolean(exitCode) == expectedExitCode
+ }
+ }
+ private def toBoolean(exitCode: Int) = exitCode == 0
+ private def checkExit(code: Byte) =
+ {
+ val exitCode = unsigned(code)
+ (process("processtest.exit " + exitCode) !) == exitCode
+ }
+ private def checkFileOut(data: Array[Byte]) =
+ {
+ withData(data) { (temporaryFile, temporaryFile2) =>
+ val catCommand = process("processtest.cat " + temporaryFile.getAbsolutePath)
+ catCommand #> temporaryFile2
+ }
+ }
+ private def checkFileIn(data: Array[Byte]) =
+ {
+ withData(data) { (temporaryFile, temporaryFile2) =>
+ val catCommand = process("processtest.cat")
+ temporaryFile #> catCommand #> temporaryFile2
+ }
+ }
+ private def checkPipe(data: Array[Byte]) =
+ {
+ withData(data) { (temporaryFile, temporaryFile2) =>
+ val catCommand = process("processtest.cat")
+ temporaryFile #> catCommand #| catCommand #> temporaryFile2
+ }
+ }
+ private def temp() = SFile(File.createTempFile("processtest", ""))
+ private def withData(data: Array[Byte])(f: (File, File) => ProcessBuilder) =
+ {
+ val temporaryFile1 = temp()
+ val temporaryFile2 = temp()
+ try {
+ temporaryFile1 writeBytes data
+ val process = f(temporaryFile1.jfile, temporaryFile2.jfile)
+ ( process ! ) == 0 &&
+ {
+ val b1 = temporaryFile1.slurp()
+ val b2 = temporaryFile2.slurp()
+ b1 == b2
+ }
+ }
+ finally
+ {
+ temporaryFile1.delete()
+ temporaryFile2.delete()
+ }
+ }
+ private def unsigned(b: Byte): Int = ((b: Int) +256) % 256
+ private def process(command: String) = {
+ val thisClasspath = List(getSource[ScalaObject], getSource[IO.type], getSource[SourceTag]).mkString(File.pathSeparator)
+ "java -cp " + thisClasspath + " " + command
+ }
+ private def getSource[T : Manifest]: String =
+ IO.classLocationFile[T].getAbsolutePath
+}
+private trait SourceTag
+
+
+object Test extends ProcessSpecification { }