diff options
author | Paul Phillips <paulp@improving.org> | 2012-07-13 12:08:20 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-07-13 12:08:20 -0700 |
commit | 453b7068ed4294eef18bf10a321a5b63497c7466 (patch) | |
tree | 8cfc64ec934fdf15d7665208a366611ce9474855 /test/files | |
parent | 724b0dc71f1f8f91b995d01e9e027789f54ecdfe (diff) | |
parent | 3d0099dbc990ab914de5b9deb5087d9d3fb6220c (diff) | |
download | scala-453b7068ed4294eef18bf10a321a5b63497c7466.tar.gz scala-453b7068ed4294eef18bf10a321a5b63497c7466.tar.bz2 scala-453b7068ed4294eef18bf10a321a5b63497c7466.zip |
Merge branch '2.10.x' into topic/name-implicits
Diffstat (limited to 'test/files')
48 files changed, 946 insertions, 347 deletions
diff --git a/test/files/codelib/code.jar.desired.sha1 b/test/files/codelib/code.jar.desired.sha1 index d2b8d9add9..c4cc74c244 100644 --- a/test/files/codelib/code.jar.desired.sha1 +++ b/test/files/codelib/code.jar.desired.sha1 @@ -1 +1 @@ -e737b123d31eede5594ceda07caafed1673ec472 ?code.jar +e737b123d31eede5594ceda07caafed1673ec472 *code.jar diff --git a/test/files/jvm/actmig-loop-react.scala b/test/files/jvm/actmig-loop-react.scala deleted file mode 100644 index d714b26594..0000000000 --- a/test/files/jvm/actmig-loop-react.scala +++ /dev/null @@ -1,188 +0,0 @@ -import scala.actors.MigrationSystem._ -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.{ Promise, Await } - - -object Test { - val finishedLWCR, finishedTNR, finishedEH = Promise[Boolean] - val finishedLWCR1, finishedTNR1, finishedEH1 = Promise[Boolean] - - def testLoopWithConditionReact() = { - // Snippet showing composition of receives - // Loop with Condition Snippet - before - val myActor = actor { - var c = true - loopWhile(c) { - react { - case x: Int => - // do task - println("do task") - if (x == 42) { - c = false - finishedLWCR1.success(true) - } - } - } - } - - myActor.start() - myActor ! 1 - myActor ! 42 - - Await.ready(finishedLWCR1.future, 5 seconds) - - // Loop with Condition Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { - - def receive = { - case x: Int => - // do task - println("do task") - if (x == 42) { - finishedLWCR.success(true) - context.stop(self) - } - } - }, "default-stashing-dispatcher")) - myAkkaActor ! 1 - myAkkaActor ! 42 - } - - def testNestedReact() = { - // Snippet showing composition of receives - // Loop with Condition Snippet - before - val myActor = actor { - var c = true - loopWhile(c) { - react { - case x: Int => - // do task - println("do task " + x) - if (x == 42) { - c = false - finishedTNR1.success(true) - } else - react { - case y: String => - println("do string " + y) - } - println("after react") - } - } - } - myActor.start() - - myActor ! 1 - myActor ! "I am a String" - myActor ! 42 - - Await.ready(finishedTNR1.future, 5 seconds) - - // Loop with Condition Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { - - def receive = { - case x: Int => - // do task - println("do task " + x) - if (x == 42) { - finishedTNR.success(true) - context.stop(self) - } else - context.become(({ - case y: String => - println("do string " + y) - }: Receive).andThen(x => { - unstashAll() - context.unbecome() - }).orElse { case x => stash() }) - } - }, "default-stashing-dispatcher")) - - myAkkaActor ! 1 - myAkkaActor ! "I am a String" - myAkkaActor ! 42 - - } - - def exceptionHandling() = { - // Stashing actor with act and exception handler - val myActor = MigrationSystem.actorOf(Props(() => new StashingActor { - - def receive = { case _ => println("Dummy method.") } - override def act() = { - loop { - react { - case "fail" => - throw new Exception("failed") - case "work" => - println("working") - case "die" => - finishedEH1.success(true) - exit() - } - } - } - - override def exceptionHandler = { - case x: Exception => println("scala got exception") - } - - }, "default-stashing-dispatcher")) - - myActor ! "work" - myActor ! "fail" - myActor ! "die" - - Await.ready(finishedEH1.future, 5 seconds) - // Stashing actor in Akka style - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { - def receive = PFCatch({ - case "fail" => - throw new Exception("failed") - case "work" => - println("working") - case "die" => - finishedEH.success(true) - context.stop(self) - }, { case x: Exception => println("akka got exception") }) - }, "default-stashing-dispatcher")) - - myAkkaActor ! "work" - myAkkaActor ! "fail" - myAkkaActor ! "die" - } - - def main(args: Array[String]) = { - testLoopWithConditionReact() - Await.ready(finishedLWCR.future, 5 seconds) - exceptionHandling() - Await.ready(finishedEH.future, 5 seconds) - testNestedReact() - Await.ready(finishedTNR.future, 5 seconds) - } - -} - -// As per Jim Mcbeath's blog (http://jim-mcbeath.blogspot.com/2008/07/actor-exceptions.html) -class PFCatch(f: PartialFunction[Any, Unit], handler: PartialFunction[Exception, Unit]) - extends PartialFunction[Any, Unit] { - - def apply(x: Any) = { - try { - f(x) - } catch { - case e: Exception if handler.isDefinedAt(e) => handler(e) - } - } - - def isDefinedAt(x: Any) = f.isDefinedAt(x) -} - -object PFCatch { - def apply(f: PartialFunction[Any, Unit], handler: PartialFunction[Exception, Unit]) = new PFCatch(f, handler) -} diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index e5e01a5954..ca9ff5090f 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -10,21 +10,69 @@ import scala.runtime.NonLocalReturnControl object FutureTests extends MinimalScalaTest { - + /* some utils */ - def testAsync(s: String): Future[String] = s match { + def testAsync(s: String)(implicit ec: ExecutionContext): Future[String] = s match { case "Hello" => future { "World" } - case "Failure" => Promise.failed(new RuntimeException("Expected exception; to test fault-tolerance")).future + case "Failure" => Future.failed(new RuntimeException("Expected exception; to test fault-tolerance")) case "NoReply" => Promise[String]().future } val defaultTimeout = 5 seconds /* future specification */ + + "A future with custom ExecutionContext" should { + "shouldHandleThrowables" in { + val ms = new mutable.HashSet[Throwable] with mutable.SynchronizedSet[Throwable] + implicit val ec = scala.concurrent.ExecutionContext.fromExecutor(new scala.concurrent.forkjoin.ForkJoinPool(), { + t => + ms += t + }) + + class ThrowableTest(m: String) extends Throwable(m) + + val f1 = future[Any] { + throw new ThrowableTest("test") + } + + intercept[ThrowableTest] { + Await.result(f1, defaultTimeout) + } + + val latch = new TestLatch + val f2 = future { + Await.ready(latch, 5 seconds) + "success" + } + val f3 = f2 map { s => s.toUpperCase } + + f2 foreach { _ => throw new ThrowableTest("dispatcher foreach") } + f2 onSuccess { case _ => throw new ThrowableTest("dispatcher receive") } + + latch.open() + + Await.result(f2, defaultTimeout) mustBe ("success") + + f2 foreach { _ => throw new ThrowableTest("current thread foreach") } + f2 onSuccess { case _ => throw new ThrowableTest("current thread receive") } + + Await.result(f3, defaultTimeout) mustBe ("SUCCESS") + + val waiting = future { + Thread.sleep(1000) + } + Await.ready(waiting, 2000 millis) + + ms.size mustBe (4) + //FIXME should check + } + } - "A future" should { - + "A future with global ExecutionContext" should { + import ExecutionContext.Implicits._ + "compose with for-comprehensions" in { def async(x: Int) = future { (x * 2).toString } val future0 = future[Any] { @@ -122,20 +170,20 @@ object FutureTests extends MinimalScalaTest { val r = new IllegalStateException("recovered") intercept[IllegalStateException] { - val failed = Promise.failed[String](o).future recoverWith { - case _ if false == true => Promise.successful("yay!").future + val failed = Future.failed[String](o) recoverWith { + case _ if false == true => Future.successful("yay!") } Await.result(failed, defaultTimeout) } mustBe (o) - val recovered = Promise.failed[String](o).future recoverWith { - case _ => Promise.successful("yay!").future + val recovered = Future.failed[String](o) recoverWith { + case _ => Future.successful("yay!") } Await.result(recovered, defaultTimeout) mustBe ("yay!") intercept[IllegalStateException] { - val refailed = Promise.failed[String](o).future recoverWith { - case _ => Promise.failed[String](r).future + val refailed = Future.failed[String](o) recoverWith { + case _ => Future.failed[String](r) } Await.result(refailed, defaultTimeout) } mustBe (r) @@ -164,7 +212,7 @@ object FutureTests extends MinimalScalaTest { "firstCompletedOf" in { def futures = Vector.fill[Future[Int]](10) { Promise[Int]().future - } :+ Promise.successful[Int](5).future + } :+ Future.successful[Int](5) Await.result(Future.firstCompletedOf(futures), defaultTimeout) mustBe (5) Await.result(Future.firstCompletedOf(futures.iterator), defaultTimeout) mustBe (5) @@ -186,21 +234,21 @@ object FutureTests extends MinimalScalaTest { val timeout = 10000 millis val f = new IllegalStateException("test") intercept[IllegalStateException] { - val failed = Promise.failed[String](f).future zip Promise.successful("foo").future + val failed = Future.failed[String](f) zip Future.successful("foo") Await.result(failed, timeout) } mustBe (f) intercept[IllegalStateException] { - val failed = Promise.successful("foo").future zip Promise.failed[String](f).future + val failed = Future.successful("foo") zip Future.failed[String](f) Await.result(failed, timeout) } mustBe (f) intercept[IllegalStateException] { - val failed = Promise.failed[String](f).future zip Promise.failed[String](f).future + val failed = Future.failed[String](f) zip Future.failed[String](f) Await.result(failed, timeout) } mustBe (f) - val successful = Promise.successful("foo").future zip Promise.successful("foo").future + val successful = Future.successful("foo") zip Future.successful("foo") Await.result(successful, timeout) mustBe (("foo", "foo")) } @@ -337,50 +385,6 @@ object FutureTests extends MinimalScalaTest { Await.result(traversedIterator, defaultTimeout).sum mustBe (10000) } - "shouldHandleThrowables" in { - val ms = new mutable.HashSet[Throwable] with mutable.SynchronizedSet[Throwable] - implicit val ec = scala.concurrent.ExecutionContext.fromExecutor(new scala.concurrent.forkjoin.ForkJoinPool(), { - t => - ms += t - }) - - class ThrowableTest(m: String) extends Throwable(m) - - val f1 = future[Any] { - throw new ThrowableTest("test") - } - - intercept[ThrowableTest] { - Await.result(f1, defaultTimeout) - } - - val latch = new TestLatch - val f2 = future { - Await.ready(latch, 5 seconds) - "success" - } - val f3 = f2 map { s => s.toUpperCase } - - f2 foreach { _ => throw new ThrowableTest("dispatcher foreach") } - f2 onSuccess { case _ => throw new ThrowableTest("dispatcher receive") } - - latch.open() - - Await.result(f2, defaultTimeout) mustBe ("success") - - f2 foreach { _ => throw new ThrowableTest("current thread foreach") } - f2 onSuccess { case _ => throw new ThrowableTest("current thread receive") } - - Await.result(f3, defaultTimeout) mustBe ("SUCCESS") - - val waiting = future { - Thread.sleep(1000) - } - Await.ready(waiting, 2000 millis) - - ms.size mustBe (4) - } - "shouldBlockUntilResult" in { val latch = new TestLatch diff --git a/test/files/jvm/future-spec/PromiseTests.scala b/test/files/jvm/future-spec/PromiseTests.scala index bf9d9b39d7..49bc642b57 100644 --- a/test/files/jvm/future-spec/PromiseTests.scala +++ b/test/files/jvm/future-spec/PromiseTests.scala @@ -10,7 +10,8 @@ import scala.runtime.NonLocalReturnControl object PromiseTests extends MinimalScalaTest { - + import ExecutionContext.Implicits._ + val defaultTimeout = Inf /* promise specification */ @@ -20,11 +21,13 @@ object PromiseTests extends MinimalScalaTest { "not be completed" in { val p = Promise() p.future.isCompleted mustBe (false) + p.isCompleted mustBe (false) } "have no value" in { val p = Promise() p.future.value mustBe (None) + p.isCompleted mustBe (false) } "return supplied value on timeout" in { @@ -45,14 +48,16 @@ object PromiseTests extends MinimalScalaTest { "A successful Promise" should { val result = "test value" - val future = Promise[String]().complete(Right(result)).future - futureWithResult(_(future, result)) + val promise = Promise[String]().complete(Right(result)) + promise.isCompleted mustBe (true) + futureWithResult(_(promise.future, result)) } "A failed Promise" should { val message = "Expected Exception" - val future = Promise[String]().complete(Left(new RuntimeException(message))).future - futureWithException[RuntimeException](_(future, message)) + val promise = Promise[String]().complete(Left(new RuntimeException(message))) + promise.isCompleted mustBe (true) + futureWithException[RuntimeException](_(promise.future, message)) } "An interrupted Promise" should { diff --git a/test/files/jvm/non-fatal-tests.scala b/test/files/jvm/non-fatal-tests.scala new file mode 100644 index 0000000000..471a9d227a --- /dev/null +++ b/test/files/jvm/non-fatal-tests.scala @@ -0,0 +1,47 @@ +import scala.util.control.NonFatal + +trait NonFatalTests { + + //NonFatals + val nonFatals: Seq[Throwable] = + Seq(new StackOverflowError, + new RuntimeException, + new Exception, + new Throwable) + + //Fatals + val fatals: Seq[Throwable] = + Seq(new InterruptedException, + new OutOfMemoryError, + new LinkageError, + new VirtualMachineError {}, + new Throwable with scala.util.control.ControlThrowable, + new NotImplementedError) + + def testFatalsUsingApply(): Unit = { + fatals foreach { t => assert(NonFatal(t) == false) } + } + + def testNonFatalsUsingApply(): Unit = { + nonFatals foreach { t => assert(NonFatal(t) == true) } + } + + def testFatalsUsingUnapply(): Unit = { + fatals foreach { t => assert(NonFatal.unapply(t).isEmpty) } + } + + def testNonFatalsUsingUnapply(): Unit = { + nonFatals foreach { t => assert(NonFatal.unapply(t).isDefined) } + } + + testFatalsUsingApply() + testNonFatalsUsingApply() + testFatalsUsingUnapply() + testNonFatalsUsingUnapply() +} + +object Test +extends App +with NonFatalTests { + System.exit(0) +}
\ No newline at end of file diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 407027f904..5c9c71f3f8 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -3,22 +3,19 @@ import scala.concurrent.{ Promise, TimeoutException, SyncVar, - ExecutionException + ExecutionException, + ExecutionContext } -import scala.concurrent.future -import scala.concurrent.promise -import scala.concurrent.blocking +import scala.concurrent.{ future, promise, blocking } import scala.util.{ Try, Success, Failure } - import scala.concurrent.util.Duration - trait TestBase { def once(body: (() => Unit) => Unit) { val sv = new SyncVar[Boolean] body(() => sv put true) - sv.take() + sv.take(2000) } // def assert(cond: => Boolean) { @@ -33,7 +30,8 @@ trait TestBase { trait FutureCallbacks extends TestBase { - + import ExecutionContext.Implicits._ + def testOnSuccess(): Unit = once { done => var x = 0 @@ -147,6 +145,7 @@ trait FutureCallbacks extends TestBase { trait FutureCombinators extends TestBase { + import ExecutionContext.Implicits._ def testMapSuccess(): Unit = once { done => @@ -591,7 +590,8 @@ trait FutureCombinators extends TestBase { trait FutureProjections extends TestBase { - + import ExecutionContext.Implicits._ + def testFailedFailureOnComplete(): Unit = once { done => val cause = new RuntimeException @@ -673,7 +673,8 @@ trait FutureProjections extends TestBase { trait Blocking extends TestBase { - + import ExecutionContext.Implicits._ + def testAwaitSuccess(): Unit = once { done => val f = future { 0 } @@ -702,8 +703,67 @@ trait Blocking extends TestBase { } +trait BlockContexts extends TestBase { + import ExecutionContext.Implicits._ + import scala.concurrent.{ Await, Awaitable, BlockContext } + + private def getBlockContext(body: => BlockContext): BlockContext = { + blocking(Future { body }, Duration(500, "ms")) + } + + // test outside of an ExecutionContext + def testDefaultOutsideFuture(): Unit = { + val bc = BlockContext.current + assert(bc.getClass.getName.contains("DefaultBlockContext")) + } + + // test BlockContext in our default ExecutionContext + def testDefaultFJP(): Unit = { + val bc = getBlockContext(BlockContext.current) + assert(bc.isInstanceOf[scala.concurrent.forkjoin.ForkJoinWorkerThread]) + } + + // test BlockContext inside BlockContext.withBlockContext + def testPushCustom(): Unit = { + val orig = BlockContext.current + val customBC = new BlockContext() { + override def internalBlockingCall[T](awaitable: Awaitable[T], atMost: Duration): T = + orig.internalBlockingCall(awaitable, atMost) + } + + val bc = getBlockContext({ + BlockContext.withBlockContext(customBC) { + BlockContext.current + } + }) + + assert(bc eq customBC) + } + + // test BlockContext after a BlockContext.push + def testPopCustom(): Unit = { + val orig = BlockContext.current + val customBC = new BlockContext() { + override def internalBlockingCall[T](awaitable: Awaitable[T], atMost: Duration): T = + orig.internalBlockingCall(awaitable, atMost) + } + + val bc = getBlockContext({ + BlockContext.withBlockContext(customBC) {} + BlockContext.current + }) + + assert(bc ne customBC) + } + + testDefaultOutsideFuture() + testDefaultFJP() + testPushCustom() + testPopCustom() +} trait Promises extends TestBase { + import ExecutionContext.Implicits._ def testSuccess(): Unit = once { done => @@ -730,7 +790,8 @@ trait Promises extends TestBase { trait Exceptions extends TestBase { - + import ExecutionContext.Implicits._ + } // trait TryEitherExtractor extends TestBase { @@ -811,7 +872,7 @@ trait Exceptions extends TestBase { trait CustomExecutionContext extends TestBase { import scala.concurrent.{ ExecutionContext, Awaitable } - def defaultEC = ExecutionContext.defaultExecutionContext + def defaultEC = ExecutionContext.global val inEC = new java.lang.ThreadLocal[Int]() { override def initialValue = 0 @@ -826,7 +887,7 @@ trait CustomExecutionContext extends TestBase { val _count = new java.util.concurrent.atomic.AtomicInteger(0) def count = _count.get - def delegate = ExecutionContext.defaultExecutionContext + def delegate = ExecutionContext.global override def execute(runnable: Runnable) = { _count.incrementAndGet() @@ -843,9 +904,6 @@ trait CustomExecutionContext extends TestBase { delegate.execute(wrapper) } - override def internalBlockingCall[T](awaitable: Awaitable[T], atMost: Duration): T = - delegate.internalBlockingCall(awaitable, atMost) - override def reportFailure(t: Throwable): Unit = { System.err.println("Failure: " + t.getClass.getSimpleName + ": " + t.getMessage) delegate.reportFailure(t) @@ -860,14 +918,16 @@ trait CustomExecutionContext extends TestBase { def testOnSuccessCustomEC(): Unit = { val count = countExecs { implicit ec => - once { done => - val f = future({ assertNoEC() })(defaultEC) - f onSuccess { - case _ => - assertEC() + blocking { + once { done => + val f = future({ assertNoEC() })(defaultEC) + f onSuccess { + case _ => + assertEC() done() + } + assertNoEC() } - assertNoEC() } } @@ -877,12 +937,14 @@ trait CustomExecutionContext extends TestBase { def testKeptPromiseCustomEC(): Unit = { val count = countExecs { implicit ec => - once { done => - val f = Promise.successful(10).future - f onSuccess { - case _ => - assertEC() + blocking { + once { done => + val f = Promise.successful(10).future + f onSuccess { + case _ => + assertEC() done() + } } } } @@ -893,28 +955,30 @@ trait CustomExecutionContext extends TestBase { def testCallbackChainCustomEC(): Unit = { val count = countExecs { implicit ec => - once { done => - assertNoEC() - val addOne = { x: Int => assertEC(); x + 1 } - val f = Promise.successful(10).future - f.map(addOne).filter { x => - assertEC() - x == 11 - } flatMap { x => - Promise.successful(x + 1).future.map(addOne).map(addOne) - } onComplete { - case Left(t) => - try { - throw new AssertionError("error in test: " + t.getMessage, t) - } finally { + blocking { + once { done => + assertNoEC() + val addOne = { x: Int => assertEC(); x + 1 } + val f = Promise.successful(10).future + f.map(addOne).filter { x => + assertEC() + x == 11 + } flatMap { x => + Promise.successful(x + 1).future.map(addOne).map(addOne) + } onComplete { + case Left(t) => + try { + throw new AssertionError("error in test: " + t.getMessage, t) + } finally { + done() + } + case Right(x) => + assertEC() + assert(x == 14) done() - } - case Right(x) => - assertEC() - assert(x == 14) - done() + } + assertNoEC() } - assertNoEC() } } @@ -934,6 +998,7 @@ with FutureCallbacks with FutureCombinators with FutureProjections with Promises +with BlockContexts with Exceptions // with TryEitherExtractor with CustomExecutionContext diff --git a/test/files/lib/annotations.jar.desired.sha1 b/test/files/lib/annotations.jar.desired.sha1 index 2b4292d796..ff7bc9425e 100644 --- a/test/files/lib/annotations.jar.desired.sha1 +++ b/test/files/lib/annotations.jar.desired.sha1 @@ -1 +1 @@ -02fe2ed93766323a13f22c7a7e2ecdcd84259b6c ?annotations.jar +02fe2ed93766323a13f22c7a7e2ecdcd84259b6c *annotations.jar diff --git a/test/files/lib/enums.jar.desired.sha1 b/test/files/lib/enums.jar.desired.sha1 index 46cd8e92cf..040dff4487 100644 --- a/test/files/lib/enums.jar.desired.sha1 +++ b/test/files/lib/enums.jar.desired.sha1 @@ -1 +1 @@ -981392dbd1f727b152cd1c908c5fce60ad9d07f7 ?enums.jar +981392dbd1f727b152cd1c908c5fce60ad9d07f7 *enums.jar diff --git a/test/files/lib/genericNest.jar.desired.sha1 b/test/files/lib/genericNest.jar.desired.sha1 index e9321262f2..77e4fec408 100644 --- a/test/files/lib/genericNest.jar.desired.sha1 +++ b/test/files/lib/genericNest.jar.desired.sha1 @@ -1 +1 @@ -b1ec8a095cec4902b3609d74d274c04365c59c04 ?genericNest.jar +b1ec8a095cec4902b3609d74d274c04365c59c04 *genericNest.jar diff --git a/test/files/lib/methvsfield.jar.desired.sha1 b/test/files/lib/methvsfield.jar.desired.sha1 index 8c01532b88..6655f45ddb 100644 --- a/test/files/lib/methvsfield.jar.desired.sha1 +++ b/test/files/lib/methvsfield.jar.desired.sha1 @@ -1 +1 @@ -be8454d5e7751b063ade201c225dcedefd252775 ?methvsfield.jar +be8454d5e7751b063ade201c225dcedefd252775 *methvsfield.jar diff --git a/test/files/lib/nest.jar.desired.sha1 b/test/files/lib/nest.jar.desired.sha1 index 674ca79a5b..056e7ada90 100644 --- a/test/files/lib/nest.jar.desired.sha1 +++ b/test/files/lib/nest.jar.desired.sha1 @@ -1 +1 @@ -cd33e0a0ea249eb42363a2f8ba531186345ff68c ?nest.jar +cd33e0a0ea249eb42363a2f8ba531186345ff68c *nest.jar diff --git a/test/files/lib/scalacheck.jar.desired.sha1 b/test/files/lib/scalacheck.jar.desired.sha1 index e6ed543d73..2f15402d18 100644 --- a/test/files/lib/scalacheck.jar.desired.sha1 +++ b/test/files/lib/scalacheck.jar.desired.sha1 @@ -1 +1 @@ -b6f4dbb29f0c2ec1eba682414f60d52fea84f703 ?scalacheck.jar +b6f4dbb29f0c2ec1eba682414f60d52fea84f703 *scalacheck.jar diff --git a/test/files/neg/stringinterpolation_macro-neg.check b/test/files/neg/stringinterpolation_macro-neg.check new file mode 100644 index 0000000000..8986b899a3 --- /dev/null +++ b/test/files/neg/stringinterpolation_macro-neg.check @@ -0,0 +1,70 @@ +stringinterpolation_macro-neg.scala:8: error: too few parts + new StringContext().f() + ^ +stringinterpolation_macro-neg.scala:9: error: too few arguments for interpolated string + new StringContext("", " is ", "%2d years old").f(s) + ^ +stringinterpolation_macro-neg.scala:10: error: too many arguments for interpolated string + new StringContext("", " is ", "%2d years old").f(s, d, d) + ^ +stringinterpolation_macro-neg.scala:11: error: too few arguments for interpolated string + new StringContext("", "").f() + ^ +stringinterpolation_macro-neg.scala:14: error: type mismatch; + found : String + required: Boolean + f"$s%b" + ^ +stringinterpolation_macro-neg.scala:15: error: type mismatch; + found : String + required: Char + f"$s%c" + ^ +stringinterpolation_macro-neg.scala:16: error: type mismatch; + found : Double + required: Char + f"$f%c" + ^ +stringinterpolation_macro-neg.scala:17: error: type mismatch; + found : String + required: Int + f"$s%x" + ^ +stringinterpolation_macro-neg.scala:18: error: type mismatch; + found : Boolean + required: Int + f"$b%d" + ^ +stringinterpolation_macro-neg.scala:19: error: type mismatch; + found : String + required: Int + f"$s%d" + ^ +stringinterpolation_macro-neg.scala:20: error: type mismatch; + found : Double + required: Int + f"$f%o" + ^ +stringinterpolation_macro-neg.scala:21: error: type mismatch; + found : String + required: Double + f"$s%e" + ^ +stringinterpolation_macro-neg.scala:22: error: type mismatch; + found : Boolean + required: Double + f"$b%f" + ^ +stringinterpolation_macro-neg.scala:27: error: type mismatch; + found : String + required: Int +Note that implicit conversions are not applicable because they are ambiguous: + both value strToInt2 of type String => Int + and value strToInt1 of type String => Int + are possible conversion functions from String to Int + f"$s%d" + ^ +stringinterpolation_macro-neg.scala:30: error: illegal conversion character + f"$s%i" + ^ +15 errors found diff --git a/test/files/neg/stringinterpolation_macro-neg.scala b/test/files/neg/stringinterpolation_macro-neg.scala new file mode 100644 index 0000000000..ac9d97d678 --- /dev/null +++ b/test/files/neg/stringinterpolation_macro-neg.scala @@ -0,0 +1,31 @@ +object Test extends App { + val s = "Scala" + val d = 8 + val b = false + val f = 3.14159 + + // 1) number of arguments + new StringContext().f() + new StringContext("", " is ", "%2d years old").f(s) + new StringContext("", " is ", "%2d years old").f(s, d, d) + new StringContext("", "").f() + + // 2) Interpolation mismatches + f"$s%b" + f"$s%c" + f"$f%c" + f"$s%x" + f"$b%d" + f"$s%d" + f"$f%o" + f"$s%e" + f"$b%f" + + { + implicit val strToInt1 = (s: String) => 1 + implicit val strToInt2 = (s: String) => 2 + f"$s%d" + } + + f"$s%i" +} diff --git a/test/files/neg/t2442.flags b/test/files/neg/t2442.flags index 32cf036c3d..e8fb65d50c 100644 --- a/test/files/neg/t2442.flags +++ b/test/files/neg/t2442.flags @@ -1 +1 @@ --Xexperimental -Xfatal-warnings
\ No newline at end of file +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t6042.check b/test/files/neg/t6042.check new file mode 100644 index 0000000000..221f06e2c5 --- /dev/null +++ b/test/files/neg/t6042.check @@ -0,0 +1,4 @@ +t6042.scala:7: error: illegal type selection from volatile type a.OpSemExp (with upper bound LazyExp[a.OpSemExp] with _$1) + def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with This` + ^ +one error found diff --git a/test/files/neg/t6042.scala b/test/files/neg/t6042.scala new file mode 100644 index 0000000000..5a123d17ca --- /dev/null +++ b/test/files/neg/t6042.scala @@ -0,0 +1,8 @@ +trait LazyExp[+This <: LazyExp[This]] { this: This => + type OpSemExp <: LazyExp[OpSemExp] with This + type Val +} + +object Test { + def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with This` +} diff --git a/test/files/presentation/hyperlinks.flags b/test/files/presentation/hyperlinks.flags deleted file mode 100644 index dc13682c5e..0000000000 --- a/test/files/presentation/hyperlinks.flags +++ /dev/null @@ -1,2 +0,0 @@ -# This test will fail in the new pattern matcher because -# it generates trees whose positions are not transparent diff --git a/test/files/presentation/hyperlinks/Runner.scala b/test/files/presentation/hyperlinks/Runner.scala index 3d19f2d948..61da49a3d7 100644 --- a/test/files/presentation/hyperlinks/Runner.scala +++ b/test/files/presentation/hyperlinks/Runner.scala @@ -1,11 +1,11 @@ import scala.tools.nsc.interactive.tests.InteractiveTest object Test extends InteractiveTest { - override def runTests() { + override def runDefaultTests() { // make sure typer is done.. the virtual pattern matcher might translate // some trees and mess up positions. But we'll catch it red handed! sourceFiles foreach (src => askLoadedTyped(src).get) - super.runTests() + super.runDefaultTests() } }
\ No newline at end of file diff --git a/test/files/presentation/ide-bug-1000469/Runner.scala b/test/files/presentation/ide-bug-1000469/Runner.scala index c53533fddd..1ef3cf9025 100644 --- a/test/files/presentation/ide-bug-1000469/Runner.scala +++ b/test/files/presentation/ide-bug-1000469/Runner.scala @@ -1,5 +1,3 @@ import scala.tools.nsc.interactive.tests._ -object Test extends InteractiveTest { - override val runRandomTests = false -} +object Test extends InteractiveTest
\ No newline at end of file diff --git a/test/files/presentation/ide-bug-1000531.flags b/test/files/presentation/ide-bug-1000531.flags deleted file mode 100644 index 56d026a62d..0000000000 --- a/test/files/presentation/ide-bug-1000531.flags +++ /dev/null @@ -1,18 +0,0 @@ -# This file contains command line options that are passed to the presentation compiler -# Lines starting with # are stripped, and you can split arguments on several lines. - -# The -bootclasspath option is treated specially by the test framework: if it's not specified -# in this file, the presentation compiler will pick up the scala-library/compiler that's on the -# java classpath used to run this test (usually build/pack) - -# Any option can be passed this way, like presentation debug -# -Ypresentation-debug -Ypresentation-verbose - -# the classpath is relative to the current working directory. That means it depends where you're -# running partest from. Run it from the root scala checkout for these files to resolve correctly -# (by default when running 'ant test', or 'test/partest'). Paths use Unix separators, the test -# framework translates them to the platform dependent representation. -# -bootclasspath lib/scala-compiler.jar:lib/scala-library.jar:lib/fjbg.jar - -# the following line would test using the quick compiler -# -bootclasspath build/quick/classes/compiler:build/quick/classes/library:lib/fjbg.jar diff --git a/test/files/presentation/ide-t1000976.check b/test/files/presentation/ide-t1000976.check new file mode 100644 index 0000000000..d58f86d6c6 --- /dev/null +++ b/test/files/presentation/ide-t1000976.check @@ -0,0 +1 @@ +Test OK
\ No newline at end of file diff --git a/test/files/presentation/ide-t1000976.flags b/test/files/presentation/ide-t1000976.flags new file mode 100644 index 0000000000..9a1a05a4f6 --- /dev/null +++ b/test/files/presentation/ide-t1000976.flags @@ -0,0 +1 @@ +-sourcepath src
\ No newline at end of file diff --git a/test/files/presentation/ide-t1000976/Test.scala b/test/files/presentation/ide-t1000976/Test.scala new file mode 100644 index 0000000000..722259d3a1 --- /dev/null +++ b/test/files/presentation/ide-t1000976/Test.scala @@ -0,0 +1,30 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest +import scala.reflect.internal.util.SourceFile +import scala.tools.nsc.interactive.Response + +object Test extends InteractiveTest { + override def execute(): Unit = { + loadSourceAndWaitUntilTypechecked("A.scala") + val sourceB = loadSourceAndWaitUntilTypechecked("B.scala") + checkErrors(sourceB) + } + + private def loadSourceAndWaitUntilTypechecked(sourceName: String): SourceFile = { + val sourceFile = sourceFiles.find(_.file.name == sourceName).head + compiler.askToDoFirst(sourceFile) + val res = new Response[Unit] + compiler.askReload(List(sourceFile), res) + res.get + askLoadedTyped(sourceFile).get + sourceFile + } + + private def checkErrors(source: SourceFile): Unit = compiler.getUnitOf(source) match { + case Some(unit) => + val problems = unit.problems.toList + if(problems.isEmpty) reporter.println("Test OK") + else problems.foreach(problem => reporter.println(problem.msg)) + + case None => reporter.println("No compilation unit found for " + source.file.name) + } +} diff --git a/test/files/presentation/ide-t1000976/src/a/A.scala b/test/files/presentation/ide-t1000976/src/a/A.scala new file mode 100644 index 0000000000..fcfef8b525 --- /dev/null +++ b/test/files/presentation/ide-t1000976/src/a/A.scala @@ -0,0 +1,7 @@ +package a + +import d.D._ + +object A { + Seq.empty[Byte].toArray.toSeq +} diff --git a/test/files/presentation/ide-t1000976/src/b/B.scala b/test/files/presentation/ide-t1000976/src/b/B.scala new file mode 100644 index 0000000000..628348cac1 --- /dev/null +++ b/test/files/presentation/ide-t1000976/src/b/B.scala @@ -0,0 +1,7 @@ +package b + +import c.C + +class B { + new C("") +} diff --git a/test/files/presentation/ide-t1000976/src/c/C.scala b/test/files/presentation/ide-t1000976/src/c/C.scala new file mode 100644 index 0000000000..cc23e3eef1 --- /dev/null +++ b/test/files/presentation/ide-t1000976/src/c/C.scala @@ -0,0 +1,3 @@ +package c + +class C(key: String = "", componentStates: String = "") diff --git a/test/files/presentation/ide-t1000976/src/d/D.scala b/test/files/presentation/ide-t1000976/src/d/D.scala new file mode 100644 index 0000000000..d7a48f98d5 --- /dev/null +++ b/test/files/presentation/ide-t1000976/src/d/D.scala @@ -0,0 +1,7 @@ +package d + +import c.C + +object D { + implicit def c2s(c: C): String = "" +} diff --git a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala index 857beac7df..a5533a623a 100644 --- a/test/files/presentation/memory-leaks/MemoryLeaksTest.scala +++ b/test/files/presentation/memory-leaks/MemoryLeaksTest.scala @@ -24,10 +24,7 @@ import scala.tools.nsc.io._ object Test extends InteractiveTest { final val mega = 1024 * 1024 - override def main(args: Array[String]) { - memoryConsumptionTest() - compiler.askShutdown() - } + override def execute(): Unit = memoryConsumptionTest() def batchSource(name: String) = new BatchSourceFile(AbstractFile.getFile(name)) diff --git a/test/files/presentation/t5708/Test.scala b/test/files/presentation/t5708/Test.scala index 96e758d974..bec1131c4c 100644 --- a/test/files/presentation/t5708/Test.scala +++ b/test/files/presentation/t5708/Test.scala @@ -1,5 +1,3 @@ import scala.tools.nsc.interactive.tests.InteractiveTest -object Test extends InteractiveTest { - -}
\ No newline at end of file +object Test extends InteractiveTest
\ No newline at end of file diff --git a/test/files/presentation/visibility/Test.scala b/test/files/presentation/visibility/Test.scala index 96e758d974..bec1131c4c 100644 --- a/test/files/presentation/visibility/Test.scala +++ b/test/files/presentation/visibility/Test.scala @@ -1,5 +1,3 @@ import scala.tools.nsc.interactive.tests.InteractiveTest -object Test extends InteractiveTest { - -}
\ No newline at end of file +object Test extends InteractiveTest
\ No newline at end of file diff --git a/test/files/run/reflect-resolveoverload-bynameparam.scala b/test/files/run/reflect-resolveoverload-bynameparam.scala new file mode 100644 index 0000000000..7fb8c82ab8 --- /dev/null +++ b/test/files/run/reflect-resolveoverload-bynameparam.scala @@ -0,0 +1,32 @@ + +class A +class B extends A + +class C { + def foo(x: => Int)(y: String) = x + def foo(x: String)(y: List[_]) = x + def foo(x: => A)(y: Array[_]) = 1 + def foo(x: A)(y: Seq[_]) = 2 + def foo(x: B)(y: Map[_, _]) = 4 +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val c = new C + val im = cm.reflect(c) + val t = u.typeOf[C] member u.newTermName("foo") asTermSymbol + val f1 = t.resolveOverloaded(posVargs = List(u.typeOf[Int])) asMethodSymbol + val f2 = t.resolveOverloaded(posVargs = List(u.typeOf[String])) asMethodSymbol + val f3 = t.resolveOverloaded(posVargs = List(u.typeOf[A])) asMethodSymbol + val f4 = t.resolveOverloaded(posVargs = List(u.typeOf[B])) asMethodSymbol + val m1 = im.reflectMethod(f1) + val m2 = im.reflectMethod(f2) + val m3 = im.reflectMethod(f3) + val m4 = im.reflectMethod(f4) + assert(m1(() => 1, null) == c.foo(1)(null)) + assert(m2("a", null) == c.foo("a")(null)) + assert(m3(new A, null) == c.foo(new A)(null)) + assert(m4(new B, null) == c.foo(new B)(null)) +} + diff --git a/test/files/run/reflect-resolveoverload-expected.scala b/test/files/run/reflect-resolveoverload-expected.scala new file mode 100644 index 0000000000..1378090309 --- /dev/null +++ b/test/files/run/reflect-resolveoverload-expected.scala @@ -0,0 +1,43 @@ + +class A { + override def equals(x: Any) = { + x.isInstanceOf[A] && !x.isInstanceOf[B] + } +} +class B extends A { + override def equals(x: Any) = { + x.isInstanceOf[B] + } +} + +class C { + def a(x: String) = 1 + def a(x: Array[_]) = "a" + def b(x: String) = new A + def b(x: Array[_]) = new B + def c(x: String) = new B + def c(x: Array[_]) = "a" +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val c = new C + val im = cm.reflect(c) + def invoke(s: String, expectedType: u.Type, expectedResult: Any) { + val ol = (u.typeOf[C] member u.newTermName(s)).asTermSymbol + val methodSym = ol.resolveOverloaded(posVargs = List(u.typeOf[Null]), expected = expectedType).asMethodSymbol + val sig = methodSym.typeSignature.asInstanceOf[u.MethodType] + val method = im.reflectMethod(methodSym) + assert(method(null) == expectedResult) + } + + invoke("a", u.typeOf[Int], c.a(null): Int) + invoke("a", u.typeOf[String], c.a(null): String) + invoke("b", u.typeOf[B], c.b(null): B) + invoke("c", u.typeOf[A], c.c(null): A) + invoke("c", u.typeOf[A], c.c(null): A) + invoke("c", u.typeOf[B], c.c(null): B) + invoke("c", u.typeOf[String], c.c(null): String) + +} diff --git a/test/files/run/reflect-resolveoverload-invalid.scala b/test/files/run/reflect-resolveoverload-invalid.scala new file mode 100644 index 0000000000..def28ccbb4 --- /dev/null +++ b/test/files/run/reflect-resolveoverload-invalid.scala @@ -0,0 +1,43 @@ + +class A +class B extends A + +class C { + def a(x: Int) = 1 + def a(x: String) = 2 + def b(x: B) = 3 + def c(x: A, y: B) = 4 + def c(x: B, y: A) = 5 + def d[T](x: Int) = 6 + def d(x: String) = 7 + def e(x: A) = 8 + def e(x: =>B) = 9 +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + + val x = new C + val t = u.typeOf[C] + + val a = t member u.newTermName("a") asTermSymbol + val b = t member u.newTermName("b") asTermSymbol + val c = t member u.newTermName("c") asTermSymbol + val d = t member u.newTermName("d") asTermSymbol + val e = t member u.newTermName("e") asTermSymbol + + val n1 = a.resolveOverloaded(posVargs = List(u.typeOf[Char])) + val n2 = b.resolveOverloaded(posVargs = List(u.typeOf[A])) + val n3 = c.resolveOverloaded(posVargs = List(u.typeOf[B], u.typeOf[B])) + val n4 = d.resolveOverloaded(targs = List(u.typeOf[Int])) + val n5 = d.resolveOverloaded() + val n6 = e.resolveOverloaded(posVargs = List(u.typeOf[B])) + + assert(n1 == u.NoSymbol) + assert(n2 == u.NoSymbol) + assert(n3 == u.NoSymbol) + assert(n4 == u.NoSymbol) + assert(n5 == u.NoSymbol) + assert(n6 == u.NoSymbol) +} diff --git a/test/files/run/reflect-resolveoverload-named.scala b/test/files/run/reflect-resolveoverload-named.scala new file mode 100644 index 0000000000..017ec85c0d --- /dev/null +++ b/test/files/run/reflect-resolveoverload-named.scala @@ -0,0 +1,26 @@ + +class A { + def foo(x: String, y: Int) = 1 + def foo(x: Int, y: String) = 2 +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val a = new A + val im = cm.reflect(a) + val tpe = u.typeOf[A] + val overloaded = tpe member u.newTermName("foo") asTermSymbol + val ms1 = + overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("x"), u.typeOf[String]), (u.newTermName("y"), u.typeOf[Int]))) + val ms2 = + overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("y"), u.typeOf[Int]), (u.newTermName("x"), u.typeOf[String]))) + val ms3 = + overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("x"), u.typeOf[Int]), (u.newTermName("y"), u.typeOf[String]))) + val ms4 = + overloaded resolveOverloaded(nameVargs = Seq((u.newTermName("y"), u.typeOf[String]), (u.newTermName("x"), u.typeOf[Int]))) + assert(im.reflectMethod(ms1 asMethodSymbol)("A", 1) == 1) + assert(im.reflectMethod(ms2 asMethodSymbol)("A", 1) == 1) + assert(im.reflectMethod(ms3 asMethodSymbol)(1, "A") == 2) + assert(im.reflectMethod(ms4 asMethodSymbol)(1, "A") == 2) +} diff --git a/test/files/run/reflect-resolveoverload-targs.scala b/test/files/run/reflect-resolveoverload-targs.scala new file mode 100644 index 0000000000..888b2f0c15 --- /dev/null +++ b/test/files/run/reflect-resolveoverload-targs.scala @@ -0,0 +1,29 @@ + +import reflect.runtime.{universe=>u} +import scala.reflect.runtime.{currentMirror => cm} + +class C { + def foo[T: u.TypeTag](x: String) = 1 + def foo[T: u.TypeTag, S: u.TypeTag](x: String) = 2 +} + +object Test extends App { + val c = new C + val im = cm.reflect(c) + val foo = u.typeOf[C] member u.newTermName("foo") asTermSymbol + val f1 = foo.resolveOverloaded( + targs = Seq(u.typeOf[Int]), + posVargs = Seq(u.typeOf[String]) + ) + + val f2 = foo.resolveOverloaded( + targs = Seq(u.typeOf[Int], + u.typeOf[Int]), posVargs = Seq(u.typeOf[String]) + ) + + val m1 = im.reflectMethod(f1 asMethodSymbol) + val m2 = im.reflectMethod(f2 asMethodSymbol) + + assert(m1("a", u.typeTag[Int]) == c.foo[Int]("a")) + assert(m2("a", u.typeTag[Int], u.typeTag[Int]) == c.foo[Int, Int]("a")) +} diff --git a/test/files/run/reflect-resolveoverload-tparm-substitute.scala b/test/files/run/reflect-resolveoverload-tparm-substitute.scala new file mode 100644 index 0000000000..22e7bcd40a --- /dev/null +++ b/test/files/run/reflect-resolveoverload-tparm-substitute.scala @@ -0,0 +1,77 @@ + +class A +class B extends A + +class C { + def foo[T](x: T) = x + def foo(x: Int) = "a" + def foo(x: A) = x +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val c = new C + val im = cm.reflect(c) + val term = u.typeOf[C] member u.newTermName("foo") asTermSymbol + + val f1 = term.resolveOverloaded( + posVargs = List(u.typeOf[Int]), + expected = u.typeOf[String] + ) + + val f2 = term.resolveOverloaded( + targs = List(u.typeOf[String]), + posVargs = List(u.typeOf[String]), + expected = u.typeOf[String] + ) + + val f3 = term.resolveOverloaded( + posVargs = List(u.typeOf[A]), + expected = u.typeOf[A] + ) + + val f4 = term.resolveOverloaded( + targs = List(u.typeOf[A]), + posVargs = List(u.typeOf[A]), + expected = u.typeOf[A] + ) + + val f5 = term.resolveOverloaded( + targs = List(u.typeOf[B]), + posVargs = List(u.typeOf[B]), + expected = u.typeOf[B] + ) + + val f6 = term.resolveOverloaded( + targs = List(u.typeOf[B]), + posVargs = List(u.typeOf[B]), + expected = u.typeOf[A] + ) + + val f7 = term.resolveOverloaded( + targs = List(u.typeOf[A]), + posVargs = List(u.typeOf[B]), + expected = u.typeOf[A] + ) + + val m1 = im.reflectMethod(f1 asMethodSymbol) + val m2 = im.reflectMethod(f2 asMethodSymbol) + val m3 = im.reflectMethod(f3 asMethodSymbol) + val m4 = im.reflectMethod(f4 asMethodSymbol) + val m5 = im.reflectMethod(f5 asMethodSymbol) + val m6 = im.reflectMethod(f6 asMethodSymbol) + val m7 = im.reflectMethod(f7 asMethodSymbol) + + val a = new A + val b = new B + assert(m1(2) == (c.foo(2): String)) + assert(m2("xyz") == (c.foo[String]("xyz"): String)) + assert(m3(a) == (c.foo(a): A)) + assert(m4(a) == (c.foo[A](a): A)) + assert(m5(b) == (c.foo[B](b): B)) + assert(m6(b) == (c.foo[B](b): A)) + assert(m7(b) == (c.foo[A](b): A)) + + +} diff --git a/test/files/run/reflect-resolveoverload-variadic.scala b/test/files/run/reflect-resolveoverload-variadic.scala new file mode 100644 index 0000000000..8e2e15600f --- /dev/null +++ b/test/files/run/reflect-resolveoverload-variadic.scala @@ -0,0 +1,27 @@ + +class C { + def foo(x: Int*) = 1 + x.sum + def foo(x: String) = 2 +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val c = new C + val im = cm.reflect(c) + val foo = u.typeOf[C] member u.newTermName("foo") asTermSymbol + val f0 = foo.resolveOverloaded() + val f1 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[Int])) + val f2 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[Int], u.typeOf[Int])) + val f3 = foo.resolveOverloaded(posVargs = Seq(u.typeOf[String])) + + val m0 = im.reflectMethod(f0 asMethodSymbol) + val m1 = im.reflectMethod(f1 asMethodSymbol) + val m2 = im.reflectMethod(f2 asMethodSymbol) + val m3 = im.reflectMethod(f3 asMethodSymbol) + + assert(m0(Seq()) == c.foo()) + assert(m1(Seq(1)) == c.foo(1)) + assert(m2(Seq(4, 9)) == c.foo(4, 9)) + assert(m3("abc") == c.foo("abc")) +} diff --git a/test/files/run/reflect-overload.scala b/test/files/run/reflect-resolveoverload1.scala index 870a200813..a859a0ec4e 100644 --- a/test/files/run/reflect-overload.scala +++ b/test/files/run/reflect-resolveoverload1.scala @@ -9,11 +9,11 @@ object Test extends App { val st = sc.asType val meth = (st member newTermName("indexOf")).asTermSymbol val IntType = definitions.IntClass.asType - val indexOf = (meth resolveOverloaded(actuals = List(IntType))).asMethodSymbol + val indexOf = (meth resolveOverloaded(posVargs = List(IntType))).asMethodSymbol assert(m.reflectMethod(indexOf)('w') == 6) assert((m.reflectMethod(indexOf)('w') match { case x: Int => x }) == 6) val meth2 = (st member newTermName("substring")).asTermSymbol - val substring = (meth2 resolveOverloaded(actuals = List(IntType, IntType))).asMethodSymbol + val substring = (meth2 resolveOverloaded(posVargs = List(IntType, IntType))).asMethodSymbol assert(m.reflectMethod(substring)(2, 6) == "llo ") } diff --git a/test/files/run/reflect-resolveoverload2.scala b/test/files/run/reflect-resolveoverload2.scala new file mode 100644 index 0000000000..b5f719814b --- /dev/null +++ b/test/files/run/reflect-resolveoverload2.scala @@ -0,0 +1,40 @@ +class A +class B extends A + +class C { + def a(x: Int) = 1 + def a(x: String) = 2 + //def b(x: => Int)(s: String) = 1 + //def b(x: => String)(a: Array[_]) = 2 + def c(x: A) = 1 + def c(x: B) = 2 + //def d(x: => A)(s: String) = 1 + //def d(x: => B)(a: Array[_]) = 2 + def e(x: A) = 1 + def e(x: B = new B) = 2 +} + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + val c = new C + val im = cm.reflect(c) + def invoke(s: String, arg: Any, argType: u.Type): Int = { + val ol = u.typeOf[C] member u.newTermName(s) asTermSymbol + val methodSym = ol.resolveOverloaded(posVargs = List(argType)) asMethodSymbol + val sig = methodSym.typeSignature.asInstanceOf[u.MethodType] + val method = im.reflectMethod(methodSym) + if (sig.resultType.kind == "MethodType") method(arg, null).asInstanceOf[Int] + else method(arg).asInstanceOf[Int] + } + assert(c.a(1) == invoke("a", 1, u.typeOf[Int])) + assert(c.a("a") == invoke("a", "a", u.typeOf[String])) + //assert(c.b(1)(null) == invoke("b", 1, u.typeOf[Int])) + //assert(c.b("a")(null) == invoke("b", "a", u.typeOf[String])) + assert(c.c(new A) == invoke("c", new A, u.typeOf[A])) + assert(c.c(new B) == invoke("c", new B, u.typeOf[B])) + //assert(c.d(new A)(null) == invoke("d", new A, u.typeOf[A])) + //assert(c.d(new B)(null) == invoke("d", new B, u.typeOf[B])) + assert(c.e(new A) == invoke("e", new A, u.typeOf[A])) + assert(c.e(new B) == invoke("e", new B, u.typeOf[B])) +} diff --git a/test/files/run/reflection-magicsymbols.check b/test/files/run/reflection-magicsymbols.check new file mode 100644 index 0000000000..2600847d99 --- /dev/null +++ b/test/files/run/reflection-magicsymbols.check @@ -0,0 +1,22 @@ +Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+
+scala> import scala.reflect.runtime.universe._
+import scala.reflect.runtime.universe._
+
+scala> class A { def foo(x: Int*) = 1 }
+defined class A
+
+scala> val sig = typeOf[A] member newTermName("foo") typeSignature
+warning: there were 1 feature warnings; re-run with -feature for details
+sig: reflect.runtime.universe.Type = (x: <?>)scala.Int
+
+scala> val x = sig.asInstanceOf[MethodType].params.head
+x: reflect.runtime.universe.Symbol = value x
+
+scala> println(x.typeSignature)
+scala.Int*
+
+scala>
diff --git a/test/files/run/reflection-magicsymbols.scala b/test/files/run/reflection-magicsymbols.scala new file mode 100644 index 0000000000..a40845d6ac --- /dev/null +++ b/test/files/run/reflection-magicsymbols.scala @@ -0,0 +1,11 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + |import scala.reflect.runtime.universe._ + |class A { def foo(x: Int*) = 1 } + |val sig = typeOf[A] member newTermName("foo") typeSignature + |val x = sig.asInstanceOf[MethodType].params.head + |println(x.typeSignature) + |""".stripMargin +} diff --git a/test/files/run/stringinterpolation_macro-run.check b/test/files/run/stringinterpolation_macro-run.check new file mode 100644 index 0000000000..be62c5780b --- /dev/null +++ b/test/files/run/stringinterpolation_macro-run.check @@ -0,0 +1,62 @@ +false +false +true +false +true +FALSE +FALSE +TRUE +FALSE +TRUE +true +false +null +0 +80000000 +4c01926 +NULL +4C01926 +null +NULL +Scala +SCALA +5 +x +x +x +x +x +x +x +x +x +x +x +x +S +120 +120 +120 +120 +120 +120 +120 +120 +120 +120 +120 +120 +120 +42 +3.400000e+00 +3.400000e+00 +3.400000e+00 +3.400000e+00 +3.400000e+00 +3.400000e+00 +3.000000e+00 +3.000000e+00 +05/26/12 +05/26/12 +05/26/12 +05/26/12 diff --git a/test/files/run/stringinterpolation_macro-run.scala b/test/files/run/stringinterpolation_macro-run.scala new file mode 100644 index 0000000000..9c59c334f8 --- /dev/null +++ b/test/files/run/stringinterpolation_macro-run.scala @@ -0,0 +1,103 @@ +object Test extends App { + +// 'b' / 'B' (category: general) +// ----------------------------- +println(f"${null}%b") +println(f"${false}%b") +println(f"${true}%b") +println(f"${new java.lang.Boolean(false)}%b") +println(f"${new java.lang.Boolean(true)}%b") + +println(f"${null}%B") +println(f"${false}%B") +println(f"${true}%B") +println(f"${new java.lang.Boolean(false)}%B") +println(f"${new java.lang.Boolean(true)}%B") + +implicit val stringToBoolean = java.lang.Boolean.parseBoolean(_: String) +println(f"${"true"}%b") +println(f"${"false"}%b") + +// 'h' | 'H' (category: general) +// ----------------------------- +println(f"${null}%h") +println(f"${0.0}%h") +println(f"${-0.0}%h") +println(f"${"Scala"}%h") + +println(f"${null}%H") +println(f"${"Scala"}%H") + +// 's' | 'S' (category: general) +// ----------------------------- +println(f"${null}%s") +println(f"${null}%S") +println(f"${"Scala"}%s") +println(f"${"Scala"}%S") +println(f"${5}") + +// 'c' | 'C' (category: character) +// ------------------------------- +println(f"${120:Char}%c") +println(f"${120:Byte}%c") +println(f"${120:Short}%c") +println(f"${120:Int}%c") +println(f"${new java.lang.Character('x')}%c") +println(f"${new java.lang.Byte(120:Byte)}%c") +println(f"${new java.lang.Short(120:Short)}%c") +println(f"${new java.lang.Integer(120)}%c") + +println(f"${'x' : java.lang.Character}%c") +println(f"${(120:Byte) : java.lang.Byte}%c") +println(f"${(120:Short) : java.lang.Short}%c") +println(f"${120 : java.lang.Integer}%c") + +implicit val stringToChar = (x: String) => x(0) +println(f"${"Scala"}%c") + +// 'd' | 'o' | 'x' | 'X' (category: integral) +// ------------------------------------------ +println(f"${120:Byte}%d") +println(f"${120:Short}%d") +println(f"${120:Int}%d") +println(f"${120:Long}%d") +println(f"${new java.lang.Byte(120:Byte)}%d") +println(f"${new java.lang.Short(120:Short)}%d") +println(f"${new java.lang.Integer(120)}%d") +println(f"${new java.lang.Long(120)}%d") +println(f"${120 : java.lang.Integer}%d") +println(f"${120 : java.lang.Long}%d") +println(f"${BigInt(120)}%d") +println(f"${new java.math.BigInteger("120")}%d") + +{ + implicit val strToShort = (s: String) => java.lang.Short.parseShort(s) + println(f"${"120"}%d") + implicit val strToInt = (s: String) => 42 + println(f"${"120"}%d") +} + +// 'e' | 'E' | 'g' | 'G' | 'f' | 'a' | 'A' (category: floating point) +// ------------------------------------------------------------------ +println(f"${3.4f}%e") +println(f"${3.4}%e") +println(f"${3.4f : java.lang.Float}%e") +println(f"${3.4 : java.lang.Double}%e") +println(f"${BigDecimal(3.4)}%e") +println(f"${new java.math.BigDecimal(3.4)}%e") +println(f"${3}%e") +println(f"${3L}%e") + +// 't' | 'T' (category: date/time) +// ------------------------------- +import java.util.Calendar +import java.util.Locale +val c = Calendar.getInstance(Locale.US) +c.set(2012, Calendar.MAY, 26) +println(f"${c}%TD") +println(f"${c.getTime}%TD") +println(f"${c.getTime.getTime}%TD") + +implicit val strToDate = (x: String) => c +println(f"""${"1234"}%TD""") +} diff --git a/test/files/run/t3613.scala b/test/files/run/t3613.scala index c3b249571b..171a6a21aa 100644 --- a/test/files/run/t3613.scala +++ b/test/files/run/t3613.scala @@ -8,7 +8,7 @@ class Boopy { case "Boopy" => fireIntervalAdded( model, 0, 1 ) } def getSize = 0 - def getElementAt( idx: Int ) : AnyRef = "egal" + def getElementAt( idx: Int ) = ??? } } diff --git a/test/files/run/t5974.check b/test/files/run/t5974.check new file mode 100644 index 0000000000..9766475a41 --- /dev/null +++ b/test/files/run/t5974.check @@ -0,0 +1 @@ +ok diff --git a/test/files/run/t5974.scala b/test/files/run/t5974.scala new file mode 100644 index 0000000000..5b99e9f721 --- /dev/null +++ b/test/files/run/t5974.scala @@ -0,0 +1,10 @@ +object Test extends App { + import scala.collection.JavaConverters._ + + def ser(a: AnyRef) = + (new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream())).writeObject(a) + + val l = java.util.Arrays.asList("pigdog").asScala + ser(l) + println("ok") +} diff --git a/test/files/speclib/instrumented.jar.desired.sha1 b/test/files/speclib/instrumented.jar.desired.sha1 index 24856fe19a..0b8ee593da 100644 --- a/test/files/speclib/instrumented.jar.desired.sha1 +++ b/test/files/speclib/instrumented.jar.desired.sha1 @@ -1 +1 @@ -474d8c20ab31438d5d4a2ba6bc07ebdcdb530b50 ?instrumented.jar +474d8c20ab31438d5d4a2ba6bc07ebdcdb530b50 *instrumented.jar |