diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2006-09-21 16:37:57 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2006-09-21 16:37:57 +0000 |
commit | 9a45bd5bdb246e19912a46aed6a672d6119d428f (patch) | |
tree | f09b3d6d4838df7a8bc5481671dc189374b06db8 | |
parent | e40402803f660b58f8a019c7fcbda9e21c9c4250 (diff) | |
download | scala-9a45bd5bdb246e19912a46aed6a672d6119d428f.tar.gz scala-9a45bd5bdb246e19912a46aed6a672d6119d428f.tar.bz2 scala-9a45bd5bdb246e19912a46aed6a672d6119d428f.zip |
Added test for inner classes compatibility from...
Added test for inner classes compatibility from Java.
-rw-r--r-- | test/files/run/inner.check | 7 | ||||
-rw-r--r-- | test/files/run/inner.scala | 105 | ||||
-rwxr-xr-x | test/scalatest | 13 |
3 files changed, 122 insertions, 3 deletions
diff --git a/test/files/run/inner.check b/test/files/run/inner.check new file mode 100644 index 0000000000..230b1e2cdf --- /dev/null +++ b/test/files/run/inner.check @@ -0,0 +1,7 @@ +A.abc +1 +Hello +1 +1 +A.abc +Outer3: 1 2 3 diff --git a/test/files/run/inner.scala b/test/files/run/inner.scala new file mode 100644 index 0000000000..5fb1487341 --- /dev/null +++ b/test/files/run/inner.scala @@ -0,0 +1,105 @@ +//############################################################################ +// Test Java interaction with scala inner classes +//############################################################################ +// $Id: $ + +import java.io._; + +class A { + val abc = "A.abc"; + + protected class B(x: Int, y: String) { + Console.println(abc); Console.println(x); + Console.println(y); + } + + trait Itf { + def method1(x: Int): Int; + + trait Itf2 extends Itf { + def method2: Unit; + } + } + + trait PlainTrait { + def method1(x: Int): Int; + } + + class Impl(a: Int) extends Itf { + def method1(x: Int) = { + Console.println(x); + Console.println(a); + x + a + } + } + + class Impl2 extends Impl(1) with Itf#Itf2 { + def method2 = { + Console.println(abc); + } + } + + def newImpl: Itf = new Impl(1); + def newImpl2: Itf#Itf2 = new Impl2; + + class Outer1(arg1: Int) { + class Outer2(arg2: Int) { + class Outer3(arg3: Int) { + Console.println("Outer3: " + arg1 + " " + arg2 + " " + arg3); + } + } + } +} + +object Scalatest { + val outputdir = System.getProperty("scalatest.output", "inner-jvm.obj") + val scalalib = System.getProperty("scalatest.lib", "") + val classpath = outputdir + File.pathSeparator + scalalib + + def javac(src: String) = { + val tmpfilename = "tmpJavaInterraction.java"; + val tmpfile = new FileWriter(tmpfilename) + tmpfile.write(src) + tmpfile.close + exec("javac -d " + outputdir + " -cp " + classpath + " " + tmpfilename) + } + + /** Execute cmd, wait for the process to end and pipe it's output to stdout */ + def exec(cmd: String) = { + val proc = Runtime.getRuntime().exec(cmd); + val inp = new BufferedReader(new InputStreamReader(proc.getInputStream)) + val errp = new BufferedReader(new InputStreamReader(proc.getErrorStream)) + proc.waitFor() + while (inp.ready) Console.println(inp.readLine()) + while (errp.ready) Console.println(errp.readLine()) + } +} + + +object Test { + val program = """ +public class tmpJavaInterraction { + + public static void main(String[] args) { + A a = new A(); + A.B b = a.new B(1, "Hello"); + + A.Itf itf = a.newImpl(); + itf.method1(1); + + A.Itf.Itf2 itf2 = a.newImpl2(); + itf2.method2(); + + A.Outer1 o1 = a.new Outer1(1); + A.Outer1.Outer2 o2 = o1.new Outer2(2); + A.Outer1.Outer2.Outer3 or = o2.new Outer3(3); + } +} +""" + def main(args: Array[String]): Unit = { + Scalatest.javac(program) + Scalatest.exec("java -cp " + Scalatest.classpath + " tmpJavaInterraction"); + } +} + +//############################################################################ diff --git a/test/scalatest b/test/scalatest index ffbeb482b9..804495e677 100755 --- a/test/scalatest +++ b/test/scalatest @@ -225,7 +225,7 @@ test_run_jvm() { mkdir -p "$dstbase".obj && $SCALAC -d "$os_dstbase".obj "$@" "$os_srcbase".scala && classpath=`get_os_pathlist "$os_dstbase".obj:$CLASSPATH` && - $SCALA -classpath $classpath Test "jvm" && + $SCALA -Dscalatest.output=$dstbase.obj -Dscalatest.lib=$SCALA_LIB -classpath $classpath Test "jvm" && rm -rf "$dstbase".obj; } @@ -508,19 +508,26 @@ FILES_MSIL=""; FILES_SCRIPT=""; FILES_DIS=""; -QUICK="$PREFIX/build/quick/bin" +QUICK="$PREFIX/bin/quick/bin" +QUICK_LIB="$PREFIX/bin/quick/lib/library" + if [ -d "$PREFIX/dists" ]; then LATEST="$PREFIX/dists/latest/bin"; + LATEST_LIB="$PREFIX/dists/latest/lib/scala-library.jar"; elif [ -d "$PREFIX/build" ]; then LATEST="$QUICK"; + LATEST_LIB=$QUICK_LIB elif [ -d "$PREFIX/bin" ]; then LATEST="$PREFIX/bin"; + LATEST_LIB="$PREFIX/lib/scala-library.jar" else abort "Scala binaries could not be found"; fi; BIN_DIR="$LATEST/" # BIN_DIR should have a trailing / when needed, so that # it can also be set to the empty string +SCALA_LIB="$LATEST_LIB" + case `${JAVACMD:=java} \-version 2>&1 | head -1` in *1.5*) JAVA5="true";; *) JAVA5="false";; @@ -544,7 +551,7 @@ while [ $# -gt 0 ]; do --neg ) TEST_TYPE="neg"; shift 1;; --msil ) TEST_TYPE="msil"; shift 1;; --script ) TEST_TYPE="script"; shift 1;; - --quick ) BIN_DIR="$QUICK/"; shift 1;; + --quick ) BIN_DIR="$QUICK/"; SCALA_LIB=$QUICK_LIB; shift 1;; --installed ) BIN_DIR=""; shift 1;; --no-run ) NORUN="true"; shift 1;; --show-log ) SHOWLOG="true"; shift 1;; |