diff options
Diffstat (limited to 'test')
38 files changed, 528 insertions, 54 deletions
diff --git a/test/files/jvm/actmig-PinS.scala b/test/files/jvm/actmig-PinS.scala index 39f8f04b3b..30307f3737 100644 --- a/test/files/jvm/actmig-PinS.scala +++ b/test/files/jvm/actmig-PinS.scala @@ -1,5 +1,5 @@ import scala.actors._ -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } import scala.actors.Actor._ diff --git a/test/files/jvm/actmig-PinS_1.scala b/test/files/jvm/actmig-PinS_1.scala index 1fb50567b9..640684f728 100644 --- a/test/files/jvm/actmig-PinS_1.scala +++ b/test/files/jvm/actmig-PinS_1.scala @@ -1,5 +1,5 @@ import scala.actors._ -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } object SillyActor { diff --git a/test/files/jvm/actmig-PinS_2.scala b/test/files/jvm/actmig-PinS_2.scala index 46277efd43..761df6b5a7 100644 --- a/test/files/jvm/actmig-PinS_2.scala +++ b/test/files/jvm/actmig-PinS_2.scala @@ -1,5 +1,5 @@ import scala.actors.{ MigrationSystem, StashingActor, ActorRef, Props, Exit } -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } object SillyActor { diff --git a/test/files/jvm/actmig-PinS_3.scala b/test/files/jvm/actmig-PinS_3.scala index 321e99b1c2..de9788724d 100644 --- a/test/files/jvm/actmig-PinS_3.scala +++ b/test/files/jvm/actmig-PinS_3.scala @@ -1,5 +1,5 @@ import scala.actors.{ MigrationSystem, StashingActor, ActorRef, Terminated, Props } -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } diff --git a/test/files/jvm/actmig-public-methods_1.scala b/test/files/jvm/actmig-public-methods_1.scala index 7e5bc24210..4bbdc9a71f 100644 --- a/test/files/jvm/actmig-public-methods_1.scala +++ b/test/files/jvm/actmig-public-methods_1.scala @@ -3,7 +3,7 @@ import scala.actors.Actor._ import scala.actors._ import scala.util._ import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.concurrent.util.Duration +import scala.concurrent.duration.Duration import scala.actors.pattern._ object Test { diff --git a/test/files/jvm/actmig-react-receive.scala b/test/files/jvm/actmig-react-receive.scala index 8464a2af79..280582511f 100644 --- a/test/files/jvm/actmig-react-receive.scala +++ b/test/files/jvm/actmig-react-receive.scala @@ -3,7 +3,7 @@ import scala.actors.Actor._ import scala.actors.{ Actor, StashingActor, ActorRef, Props, MigrationSystem, PoisonPill } import java.util.concurrent.{ TimeUnit, CountDownLatch } import scala.collection.mutable.ArrayBuffer -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } object Test { diff --git a/test/files/jvm/duration-java/Test.java b/test/files/jvm/duration-java/Test.java index 1c53ccb266..94f3f83db8 100644 --- a/test/files/jvm/duration-java/Test.java +++ b/test/files/jvm/duration-java/Test.java @@ -1,4 +1,4 @@ -import scala.concurrent.util.Duration; +import scala.concurrent.duration.Duration; import java.util.*; import java.util.concurrent.TimeUnit; import static java.util.concurrent.TimeUnit.*; diff --git a/test/files/jvm/duration-tck.scala b/test/files/jvm/duration-tck.scala index 0947e84004..df1052fed3 100644 --- a/test/files/jvm/duration-tck.scala +++ b/test/files/jvm/duration-tck.scala @@ -1,11 +1,9 @@ /** * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> */ - -import scala.concurrent.util._ -import duration._ + +import scala.concurrent.duration._ import scala.reflect._ -import java.util.concurrent.TimeUnit._ import scala.tools.partest.TestUtil.intercept object Test extends App { @@ -39,7 +37,7 @@ object Test extends App { two / one mustBe 2 one + zero mustBe one one / 1000000 mustBe 1.micro - + // test infinities @@ -91,7 +89,7 @@ object Test extends App { minf.toUnit(MINUTES) mustBe Double.NegativeInfinity Duration.fromNanos(Double.PositiveInfinity) mustBe inf Duration.fromNanos(Double.NegativeInfinity) mustBe minf - + // test undefined & NaN @@ -122,7 +120,7 @@ object Test extends App { undef.toUnit(DAYS) mustBe nan Duration.fromNanos(nan) mustBe undef - + // test overflow protection for (unit ← Seq(DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS)) { @@ -153,21 +151,21 @@ object Test extends App { } intercept[IllegalArgumentException] { Duration.fromNanos(1e20) } intercept[IllegalArgumentException] { Duration.fromNanos(-1e20) } - + // test precision 1.second + 1.millisecond mustBe 1001.milliseconds 100000.days + 1.nanosecond mustBe 8640000000000000001L.nanoseconds 1.5.seconds.toSeconds mustBe 1 (-1.5).seconds.toSeconds mustBe -1 - + // test unit stability 1000.millis.unit mustBe MILLISECONDS (1000.millis + 0.days).unit mustBe MILLISECONDS 1.second.unit mustBe SECONDS (1.second + 1.millisecond).unit mustBe MILLISECONDS - + // test Deadline val dead = 2.seconds.fromNow @@ -177,10 +175,20 @@ object Test extends App { Thread.sleep(1.second.toMillis) assert(dead.timeLeft < 1.second) assert(dead2.timeLeft < 1.second) - + + + // test integer mul/div + 500.millis * 2 mustBe 1.second + (500.millis * 2).unit mustBe MILLISECONDS + 1.second / 2 mustBe 500.millis + (1.second / 2).unit mustBe MILLISECONDS + // check statically retaining finite-ness - val finiteDuration: FiniteDuration = 1.second plus 3.seconds minus 1.millisecond min 1.second max 1.second - + val finiteDuration: FiniteDuration = 1.second * 2 / 3 mul 5 div 4 plus 3.seconds minus 1.millisecond min 1.second max 1.second + val finite2: FiniteDuration = 2 * 1.second + 3L * 2.seconds + finite2 mustBe 8.seconds + ((2 seconds fromNow).timeLeft: FiniteDuration) < 4.seconds mustBe true + val finite3: FiniteDuration = 3.5 seconds span } diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index 31bb8c4e44..8674be168c 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -2,8 +2,8 @@ import scala.concurrent._ -import scala.concurrent.util.duration._ -import scala.concurrent.util.Duration.Inf +import scala.concurrent.duration._ +import scala.concurrent.duration.Duration.Inf import scala.collection._ import scala.runtime.NonLocalReturnControl import scala.util.{Try,Success,Failure} diff --git a/test/files/jvm/future-spec/PromiseTests.scala b/test/files/jvm/future-spec/PromiseTests.scala index d9aaa1d5ed..8e07393900 100644 --- a/test/files/jvm/future-spec/PromiseTests.scala +++ b/test/files/jvm/future-spec/PromiseTests.scala @@ -2,8 +2,8 @@ import scala.concurrent._ -import scala.concurrent.util.duration._ -import scala.concurrent.util.Duration.Inf +import scala.concurrent.duration._ +import scala.concurrent.duration.Duration.Inf import scala.collection._ import scala.runtime.NonLocalReturnControl import scala.util.{Try,Success,Failure} diff --git a/test/files/jvm/future-spec/main.scala b/test/files/jvm/future-spec/main.scala index 57183d8cea..90048ccda0 100644 --- a/test/files/jvm/future-spec/main.scala +++ b/test/files/jvm/future-spec/main.scala @@ -3,7 +3,7 @@ import scala.collection._ import scala.concurrent._ -import scala.concurrent.util.Duration +import scala.concurrent.duration.Duration import java.util.concurrent.{ TimeoutException, CountDownLatch, TimeUnit } diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 0e76b711de..b529bca38a 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -10,7 +10,7 @@ import scala.concurrent.{ } import scala.concurrent.{ future, promise, blocking } import scala.util.{ Try, Success, Failure } -import scala.concurrent.util.Duration +import scala.concurrent.duration.Duration import scala.reflect.{ classTag, ClassTag } import scala.tools.partest.TestUtil.intercept diff --git a/test/files/neg/deadline-inf-illegal.check b/test/files/neg/deadline-inf-illegal.check index 2b9b25e48e..530d2b2443 100644 --- a/test/files/neg/deadline-inf-illegal.check +++ b/test/files/neg/deadline-inf-illegal.check @@ -1,15 +1,15 @@ -deadline-inf-illegal.scala:5: error: value fromNow is not a member of scala.concurrent.util.Duration +deadline-inf-illegal.scala:5: error: value fromNow is not a member of scala.concurrent.duration.Duration d.fromNow ^ deadline-inf-illegal.scala:6: error: type mismatch; - found : scala.concurrent.util.Duration - required: scala.concurrent.util.FiniteDuration + found : scala.concurrent.duration.Duration + required: scala.concurrent.duration.FiniteDuration Deadline.now + d ^ deadline-inf-illegal.scala:7: error: overloaded method value - with alternatives: - (other: scala.concurrent.util.Deadline)scala.concurrent.util.FiniteDuration <and> - (other: scala.concurrent.util.FiniteDuration)scala.concurrent.util.Deadline - cannot be applied to (scala.concurrent.util.Duration) + (other: scala.concurrent.duration.Deadline)scala.concurrent.duration.FiniteDuration <and> + (other: scala.concurrent.duration.FiniteDuration)scala.concurrent.duration.Deadline + cannot be applied to (scala.concurrent.duration.Duration) Deadline.now - d ^ three errors found diff --git a/test/files/neg/deadline-inf-illegal.scala b/test/files/neg/deadline-inf-illegal.scala index 161089bfee..942cea7014 100644 --- a/test/files/neg/deadline-inf-illegal.scala +++ b/test/files/neg/deadline-inf-illegal.scala @@ -1,4 +1,4 @@ -import concurrent.util.{ Deadline, Duration } +import concurrent.duration.{ Deadline, Duration } class T { val d: Duration = Duration.Zero diff --git a/test/files/neg/structural.check b/test/files/neg/structural.check index 6ef57db1b4..5b2f352a76 100644 --- a/test/files/neg/structural.check +++ b/test/files/neg/structural.check @@ -1,28 +1,28 @@ structural.scala:47: error: Parameter type in structural refinement may not refer to the type of that refinement (self type) val s1 = new { def f(p: this.type): Unit = () } - ^ + ^ structural.scala:10: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def f1[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: A): Object; val x: A }) = x.m[Tata](x.x) //fail - ^ + ^ structural.scala:11: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def f2[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: B): Object; val x: B }) = x.m[Tata](x.x) //fail - ^ + ^ structural.scala:12: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def f3[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: C): Object; val x: C }) = x.m[Tata](x.x) //fail - ^ + ^ structural.scala:13: error: Parameter type in structural refinement may not refer to a type member of that refinement def f4[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: D): Object; val x: D }) = x.m[Tata](x.x) //fail - ^ + ^ structural.scala:42: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement type Summable[T] = { def +(v : T) : T } - ^ + ^ structural.scala:46: error: Parameter type in structural refinement may not refer to the type of that refinement (self type) type S1 = { def f(p: this.type): Unit } - ^ + ^ structural.scala:49: error: Parameter type in structural refinement may not refer to a type member of that refinement type S2 = { type T; def f(p: T): Unit } - ^ + ^ structural.scala:52: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def s3[U >: Null <: Object](p: { def f(p: U): Unit; def u: U }) = () - ^ + ^ 9 errors found diff --git a/test/files/neg/t0565.check b/test/files/neg/t0565.check index c5a64d0e53..98e61a2503 100644 --- a/test/files/neg/t0565.check +++ b/test/files/neg/t0565.check @@ -1,4 +1,4 @@ t0565.scala:8: error: Parameter type in structural refinement may not refer to a type member of that refinement def z (w : T) : T } = - ^ + ^ one error found diff --git a/test/files/neg/t2144.check b/test/files/neg/t2144.check index 7239f4406e..670e188c2a 100644 --- a/test/files/neg/t2144.check +++ b/test/files/neg/t2144.check @@ -1,4 +1,4 @@ t2144.scala:2: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def foo[A](a: A) = new { def bar(x: A): A = x } - ^ + ^ one error found diff --git a/test/files/neg/t5878.check b/test/files/neg/t5878.check index 50dba0d272..c60c4653a2 100644 --- a/test/files/neg/t5878.check +++ b/test/files/neg/t5878.check @@ -1,13 +1,13 @@ -t5878.scala:1: error: value class may not unbox to itself +t5878.scala:1: error: value class may not wrap another user-defined value class case class Foo(x: Bar) extends AnyVal - ^ -t5878.scala:2: error: value class may not unbox to itself + ^ +t5878.scala:2: error: value class may not wrap another user-defined value class case class Bar(x: Foo) extends AnyVal - ^ -t5878.scala:4: error: value class may not unbox to itself + ^ +t5878.scala:4: error: value class may not wrap another user-defined value class class Foo1(val x: Bar1) extends AnyVal - ^ -t5878.scala:5: error: value class may not unbox to itself + ^ +t5878.scala:5: error: value class may not wrap another user-defined value class class Bar1(val x: Foo1) extends AnyVal - ^ + ^ four errors found diff --git a/test/files/neg/t6336.check b/test/files/neg/t6336.check index f6b35ad232..f70a5f70ab 100644 --- a/test/files/neg/t6336.check +++ b/test/files/neg/t6336.check @@ -1,4 +1,7 @@ t6336.scala:3: error: Parameter type in structural refinement may not refer to a user-defined value class val a = new { def y[T](x: X[T]) = x.i } - ^ -one error found + ^ +t6336.scala:4: error: Result type in structural refinement may not refer to a user-defined value class + val b = new { def y[T](x: T): X[T] = new X(2) } + ^ +two errors found diff --git a/test/files/neg/t6336.scala b/test/files/neg/t6336.scala index a9844ff94f..b1d61f4dd2 100644 --- a/test/files/neg/t6336.scala +++ b/test/files/neg/t6336.scala @@ -1,6 +1,7 @@ object D { def main(args: Array[String]) { val a = new { def y[T](x: X[T]) = x.i } + val b = new { def y[T](x: T): X[T] = new X(2) } val x = new X(3) val t = a.y(x) println(t) diff --git a/test/files/neg/t6337.check b/test/files/neg/t6337.check new file mode 100644 index 0000000000..8448f71320 --- /dev/null +++ b/test/files/neg/t6337.check @@ -0,0 +1,7 @@ +t6337.scala:10: error: value class may not wrap another user-defined value class +class X[T](val i: XX[T]) extends AnyVal + ^ +t6337.scala:20: error: value class may not wrap another user-defined value class +class X1[T](val i: XX1[T]) extends AnyVal + ^ +two errors found diff --git a/test/files/neg/t6337.scala b/test/files/neg/t6337.scala new file mode 100644 index 0000000000..c3858f8c04 --- /dev/null +++ b/test/files/neg/t6337.scala @@ -0,0 +1,21 @@ +object C { + + def main(args: Array[String]) = { + val x = new X(new XX(3)) + println(x.i.x + 9) + } + +} + +class X[T](val i: XX[T]) extends AnyVal +class XX[T](val x: T) extends AnyVal + +object C1 { + def main(args: Array[String]) { + val x = new X1(new XX1(Some(3))) + println(x.i.x.get + 9) + } +} + +class X1[T](val i: XX1[T]) extends AnyVal +class XX1[T](val x: Option[T]) extends AnyVal diff --git a/test/files/run/t6394a.check b/test/files/run/t6394a.check new file mode 100644 index 0000000000..34997f71e3 --- /dev/null +++ b/test/files/run/t6394a.check @@ -0,0 +1 @@ +TEST
diff --git a/test/files/run/t6394a.flags b/test/files/run/t6394a.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/t6394a.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/run/t6394a/Macros_1.scala b/test/files/run/t6394a/Macros_1.scala new file mode 100644 index 0000000000..3d39d3e40a --- /dev/null +++ b/test/files/run/t6394a/Macros_1.scala @@ -0,0 +1,12 @@ +import scala.reflect.macros.Context + +object Macros { + def impl(c:Context): c.Expr[Any] = { + import c.universe._ + + val selfTree = This(c.enclosingClass.symbol.asModule.moduleClass) + c.Expr[AnyRef](selfTree) + } + + def foo: Any = macro impl +}
\ No newline at end of file diff --git a/test/files/run/t6394a/Test_2.scala b/test/files/run/t6394a/Test_2.scala new file mode 100644 index 0000000000..75e84f0e38 --- /dev/null +++ b/test/files/run/t6394a/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(Macros.foo) + override def toString = "TEST" +}
\ No newline at end of file diff --git a/test/files/run/typetags_without_scala_reflect_manifest_lookup.check b/test/files/run/typetags_without_scala_reflect_manifest_lookup.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_manifest_lookup.check diff --git a/test/files/run/typetags_without_scala_reflect_manifest_lookup.scala b/test/files/run/typetags_without_scala_reflect_manifest_lookup.scala new file mode 100644 index 0000000000..37047e7884 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_manifest_lookup.scala @@ -0,0 +1,29 @@ +import scala.tools.partest._ +import scala.tools.nsc.Settings + +object Test extends DirectTest { + override def extraSettings = "-cp " + sys.props("partest.lib") + + def code = """ + object Test extends App { + // manifest lookup also involves type tag lookup + // because we support manifest <-> typetag convertability + // + // however when scala-reflect.jar (the home of type tags) is not on the classpath + // we need to omit the type tag lookup, because we lack the necessary symbols + // to do implicit search and tag materialization + // (such missing symbols are e.g. ApiUniverseClass and TypeTagsClass) + // + // the test case you're looking at checks exactly this + // we establish a classpath that only includes scala-library.jar + // and then force scalac to perform implicit search for a manifest + // if type tag lookup is not disabled, the compiler will crash + // if it is disabled, then the compilation will succeed + // http://groups.google.com/group/scala-internals/browse_thread/thread/166ce4b71b7c46bb + def foo[T: Manifest] = () + foo[List[Int]] + } + """ + + def show = compile() +}
\ No newline at end of file diff --git a/test/files/run/typetags_without_scala_reflect_typetag_lookup.check b/test/files/run/typetags_without_scala_reflect_typetag_lookup.check new file mode 100644 index 0000000000..f6b82c33f6 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_typetag_lookup.check @@ -0,0 +1,3 @@ +newSource1:9: error: could not find implicit value for evidence parameter of type reflect.runtime.package.universe.TypeTag[Int]
+ Library.foo[Int]
+ ^
diff --git a/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala b/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala new file mode 100644 index 0000000000..e51ecdb180 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala @@ -0,0 +1,45 @@ +import scala.tools.partest._ + +object Test extends DirectTest { + def code = ??? + + def library = """ + import scala.reflect.runtime.universe._ + + object Library { + def foo[T: TypeTag] = () + } + """ + def compileLibrary() = { + val classpath = List(sys.props("partest.lib"), sys.props("partest.reflect")) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(library) + } + + def app = """ + object Test extends App { + // tries to materialize a type tag not having scala-reflect.jar on the classpath + // even though it's easy to materialize a type tag of Int, this line will fail + // because materialization involves classes from scala-reflect.jar + // + // in this test we make sure that the compiler doesn't crash + // but just displays several missing class file errors and an unavailable implicit message + Library.foo[Int] + } + """ + def compileApp() = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(app) + } + + def show(): Unit = { + val prevErr = System.err + val baos = new java.io.ByteArrayOutputStream(); + System.setErr(new java.io.PrintStream(baos)); + compileLibrary(); + compileApp(); + // we should get bad symbolic reference errors, because we're trying to call a method that can't be unpickled + // but we don't know the number of these errors and their order, so I just ignore them all + baos.toString.split("\n") filter (!_.startsWith("error: bad symbolic reference")) foreach println + System.setErr(prevErr) + } +}
\ No newline at end of file diff --git a/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check new file mode 100644 index 0000000000..34f1d84299 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check @@ -0,0 +1,3 @@ +newSource1:9: error: No Manifest available for App.this.T.
+ manifest[T]
+ ^
diff --git a/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.scala b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.scala new file mode 100644 index 0000000000..e984127583 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.scala @@ -0,0 +1,46 @@ +import scala.tools.partest._ + +object Test extends DirectTest { + def code = ??? + + def library = """ + import scala.reflect.runtime.universe._ + + trait Library { + type T + implicit val tt: TypeTag[T] + } + """ + def compileLibrary() = { + val classpath = List(sys.props("partest.lib"), sys.props("partest.reflect")) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(library) + } + + def app = """ + trait App extends Library { + // tries to create a manifest from a type tag without having scala-reflect.jar on the classpath + // even though it's possible to convert a type tag into a manifest, this will fail + // because conversion requires classes from scala-reflect.jar + // + // in this test we make sure that the compiler doesn't crash + // but just displays several missing class file errors and an unavailable implicit message + manifest[T] + } + """ + def compileApp() = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(app) + } + + def show(): Unit = { + val prevErr = System.err + val baos = new java.io.ByteArrayOutputStream(); + System.setErr(new java.io.PrintStream(baos)); + compileLibrary(); + compileApp(); + // we should get bad symbolic reference errors, because we're trying to use an implicit that can't be unpickled + // but we don't know the number of these errors and their order, so I just ignore them all + baos.toString.split("\n") filter (!_.startsWith("error: bad symbolic reference")) foreach println + System.setErr(prevErr) + } +}
\ No newline at end of file diff --git a/test/files/scalacheck/duration.scala b/test/files/scalacheck/duration.scala new file mode 100644 index 0000000000..5e93638614 --- /dev/null +++ b/test/files/scalacheck/duration.scala @@ -0,0 +1,69 @@ +import org.scalacheck._ +import Prop._ +import Gen._ +import Arbitrary._ +import math._ +import concurrent.duration.Duration.fromNanos + +object Test extends Properties("Division of Duration by Long") { + + val weightedLong = + frequency( + 1 -> choose(-128L, 127L), + 1 -> (arbitrary[Byte] map (_.toLong << 8)), + 1 -> (arbitrary[Byte] map (_.toLong << 16)), + 1 -> (arbitrary[Byte] map (_.toLong << 24)), + 1 -> (arbitrary[Byte] map (_.toLong << 32)), + 1 -> (arbitrary[Byte] map (_.toLong << 40)), + 1 -> (arbitrary[Byte] map (_.toLong << 48)), + 1 -> (choose(-127L, 127L) map (_ << 56)) + ) + + val genTwoSmall = for { + a <- weightedLong + b <- choose(-(Long.MaxValue / max(1, abs(a))), Long.MaxValue / max(1, abs(a))) + } yield (a, b) + + val genTwoLarge = for { + a <- weightedLong + b <- arbitrary[Long] suchThat (b => (abs(b) > Long.MaxValue / max(1, abs(a)))) + } yield (a, b) + + val genClose = for { + a <- weightedLong + if a != 0 + b <- choose(Long.MaxValue / a - 10, Long.MaxValue / a + 10) + } yield (a, b) + + val genBorderline = + frequency( + 1 -> (Long.MinValue, 0L), + 1 -> (Long.MinValue, 1L), + 1 -> (Long.MinValue, -1L), + 1 -> (0L, Long.MinValue), + 1 -> (1L, Long.MinValue), + 1 -> (-1L, Long.MinValue), + 90 -> genClose + ) + + def mul(a: Long, b: Long): Long = { + (fromNanos(a) * b).toNanos + } + + property("without overflow") = forAll(genTwoSmall) { case (a, b) => + a * b == mul(a, b) + } + + property("with overflow") = forAll(genTwoLarge) { case (a, b) => + try { mul(a, b); false } catch { case _: IllegalArgumentException => true } + } + + property("on overflow edge cases") = forAll(genBorderline) { case (a, b) => + val shouldFit = + a != Long.MinValue && // must fail due to illegal duration length + (b != Long.MinValue || a == 0) && // Long factor may only be MinValue if the duration is zero, otherwise the result will be illegal + (abs(b) <= Long.MaxValue / max(1, abs(a))) // check the rest against the “safe” division method + try { mul(a, b); shouldFit } + catch { case _: IllegalArgumentException => !shouldFit } + } +} diff --git a/test/osgi/src/BasicLibrary.scala b/test/osgi/src/BasicLibrary.scala new file mode 100644 index 0000000000..38dea69e99 --- /dev/null +++ b/test/osgi/src/BasicLibrary.scala @@ -0,0 +1,37 @@ +package tools.test.osgi +package libonly + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicLibraryTest extends ScalaOsgiHelper { + @Configuration + def config(): Array[exam.Option] = + justCoreLibraryOptions + + @Test + def everythingLoads(): Unit = { + // Note - This tests sun.misc usage. + import scala.concurrent._ + import scala.concurrent.util.Duration.Inf + import ExecutionContext.Implicits._ + val x = Future(2) map (_ + 1) + assertEquals(3, Await.result(x, Inf)) + } +} diff --git a/test/osgi/src/BasicReflection.scala b/test/osgi/src/BasicReflection.scala new file mode 100644 index 0000000000..8a0a05d531 --- /dev/null +++ b/test/osgi/src/BasicReflection.scala @@ -0,0 +1,66 @@ +package tools.test.osgi +package reflection +package basic + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + +class C { + val f1 = 2 + var f2 = 3 + + def m1 = 4 + def m2() = 5 + def m3[T >: String <: Int]: T = ??? + def m4[A[_], B <: A[Int]](x: A[B])(implicit y: Int) = ??? + def m5(x: => Int, y: Int*): String = ??? + + class C + object M + + override def toString = "an instance of C" +} +object M + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicReflectionTest extends ScalaOsgiHelper { + + @Configuration + def config(): Array[exam.Option] = + justReflectionOptions + + // Ensure Pax-exam requires C/M in our module + def dummy = { + new C + M.toString + } + + @Test + def basicMirrorThroughOsgi(): Unit = { + // Note for now just assert that we can do this stuff. + import scala.reflect.runtime.universe._ + val cm = runtimeMirror(classOf[C].getClassLoader) + val im = cm.reflect(new C) + assertEquals("Unable to reflect field name!", + "value f1", + im.reflectField(typeOf[C].member(newTermName("f1")).asTerm).symbol.toString) + assertEquals("Unable to reflect value!", + 2, + im.reflectField(typeOf[C].member(newTermName("f1")).asTerm).get) + } +} diff --git a/test/osgi/src/BasicTest.scala b/test/osgi/src/BasicTest.scala new file mode 100644 index 0000000000..109b7b911a --- /dev/null +++ b/test/osgi/src/BasicTest.scala @@ -0,0 +1,33 @@ +package tools.test.osgi + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + + + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicTest extends ScalaOsgiHelper { + @Configuration + def config(): Array[exam.Option] = { + // TODO - Find scala bundles. + standardOptions + } + + @Test + def everythingLoads(): Unit = () +} diff --git a/test/osgi/src/ReflectionToolboxTest.scala b/test/osgi/src/ReflectionToolboxTest.scala new file mode 100644 index 0000000000..bb48078e95 --- /dev/null +++ b/test/osgi/src/ReflectionToolboxTest.scala @@ -0,0 +1,49 @@ +package tools.test.osgi +package reflection +package toolbox + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + +class C { + val f1 = 2 +} + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class ReflectionToolBoxTest extends ScalaOsgiHelper { + + @Configuration + def config(): Array[exam.Option] = + standardOptions + + + @Test + def basicMirrorThroughOsgi(): Unit = { + // Note - this tries to make sure when pulling a toolbox, we get the compiler. + import scala.reflect.runtime.universe._ + import scala.tools.reflect.ToolBox + val cm = runtimeMirror(classOf[C].getClassLoader) + val tb = cm.mkToolBox() + val im = cm.reflect(new C) + val tree = tb.parse("1 to 3 map (_+1)") + val eval = tb.eval(tree) + assertEquals(Vector(2, 3, 4), eval) + assertEquals("Evaluate expression using local class.", + 2, + tb.eval(tb.parse("(new tools.test.osgi.reflection.toolbox.C).f1"))) + } +} diff --git a/test/osgi/src/ScalaOsgiHelper.scala b/test/osgi/src/ScalaOsgiHelper.scala new file mode 100644 index 0000000000..bcdc5c0df1 --- /dev/null +++ b/test/osgi/src/ScalaOsgiHelper.scala @@ -0,0 +1,36 @@ +package tools.test.osgi + +import org.ops4j.pax.exam.CoreOptions._ +import org.ops4j.pax.exam +import java.io.File + +trait ScalaOsgiHelper { + + private def allBundleFiles = { + def bundleLocation = new File(sys.props.getOrElse("scala.bundle.dir", "build/osgi")) + bundleLocation.listFiles filter (_.getName endsWith ".jar") + } + + private def filteredBundleFiles(names: String*): Array[exam.Option] = + for(bundle <- allBundleFiles; if names exists (bundle.getName contains)) + yield makeBundle(bundle) + + private def makeBundle(file: File): exam.Option = + bundle(file.toURI.toASCIIString) + + def standardOptions: Array[exam.Option] = { + val bundles = (allBundleFiles map makeBundle) + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + + def justReflectionOptions: Array[exam.Option] = { + val bundles = filteredBundleFiles("scala-library", "scala-reflect") + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + + def justCoreLibraryOptions: Array[exam.Option] = { + val bundles = filteredBundleFiles("scala-library") + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + +} |