diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/literals.check | 69 | ||||
-rw-r--r-- | test/files/run/literals.flags | 1 | ||||
-rw-r--r-- | test/files/run/literals.scala | 39 | ||||
-rw-r--r-- | test/files/run/priorityQueue.scala | 373 | ||||
-rw-r--r-- | test/files/run/t6440.check | 9 | ||||
-rw-r--r-- | test/files/run/t6440.scala | 2 | ||||
-rw-r--r-- | test/files/run/t6502.scala | 27 | ||||
-rw-r--r-- | test/files/run/t6669.scala | 7 | ||||
-rw-r--r-- | test/files/run/t8502.scala | 41 | ||||
-rw-r--r-- | test/files/run/t9003.flags | 1 | ||||
-rw-r--r-- | test/files/run/t9003.scala | 71 | ||||
-rw-r--r-- | test/files/run/t9027.check | 19 | ||||
-rw-r--r-- | test/files/run/t9027.scala | 15 | ||||
-rw-r--r-- | test/files/run/various-flat-classpath-types.check | 12 | ||||
-rw-r--r-- | test/files/run/various-flat-classpath-types.scala | 214 |
15 files changed, 430 insertions, 470 deletions
diff --git a/test/files/run/literals.check b/test/files/run/literals.check index 62c5fd68ae..092340eead 100644 --- a/test/files/run/literals.check +++ b/test/files/run/literals.check @@ -1,57 +1,12 @@ -warning: there were 5 deprecation warnings; re-run with -deprecation for details -test '\u0024' == '$' was successful -test '\u005f' == '_' was successful -test 65.asInstanceOf[Char] == 'A' was successful -test "\141\142" == "ab" was successful -test "\0x61\0x62".trim() == "x61\0x62" was successful - -test (65 : Byte) == 'A' was successful - -test 0X01 == 1 was successful -test 0x01 == 1 was successful -test 0x10 == 16 was successful -test 0xa == 10 was successful -test 0x0a == 10 was successful -test +0x01 == 1 was successful -test +0x10 == 16 was successful -test +0xa == 10 was successful -test +0x0a == 10 was successful -test -0x01 == -1 was successful -test -0x10 == -16 was successful -test -0xa == -10 was successful -test -0x0a == -10 was successful -test 0x7fffffff == 2147483647 was successful -test 0x80000000 == -2147483648 was successful -test 0xffffffff == -1 was successful - -test 1l == 1L was successful -test 1L == 1l was successful -test 1.asInstanceOf[Long] == 1l was successful -test 0x7fffffffffffffffL == 9223372036854775807L was successful -test 0x8000000000000000L == -9223372036854775808L was successful -test 0xffffffffffffffffL == -1L was successful - -test 1e1f == 10.0f was successful -test .3f == 0.3f was successful -test 0f == 0.0f was successful -test 01.23f == 1.23f was successful -test 3.14f == 3.14f was successful -test 6.022e23f == 6.022e23f was successful -test 09f == 9.0f was successful -test 1.asInstanceOf[Float] == 1.0 was successful -test 1l.asInstanceOf[Float] == 1.0 was successful - -test 1e1 == 10.0 was successful -test .3 == 0.3 was successful -test 0.0 == 0.0 was successful -test 0d == 0.0 was successful -test 01.23 == 1.23 was successful -test 01.23d == 1.23d was successful -test 3.14 == 3.14 was successful -test 1e-9d == 1.0e-9 was successful -test 1e137 == 1.0e137 was successful -test 1.asInstanceOf[Double] == 1.0 was successful -test 1l.asInstanceOf[Double] == 1.0 was successful - -test "".length() was successful -test ggg == 3 was successful +literals.scala:34: warning: Octal escape literals are deprecated, use \u0061 instead. + check_success("\"\\141\\142\" == \"ab\"", "\141\142", "ab") + ^ +literals.scala:34: warning: Octal escape literals are deprecated, use \u0062 instead. + check_success("\"\\141\\142\" == \"ab\"", "\141\142", "ab") + ^ +literals.scala:37: warning: Octal escape literals are deprecated, use \u0000 instead. + "\0x61\0x62".getBytes(io.Codec.UTF8.charSet) sameElements Array[Byte](0, 120, 54, 49, 0, 120, 54, 50), + ^ +literals.scala:37: warning: Octal escape literals are deprecated, use \u0000 instead. + "\0x61\0x62".getBytes(io.Codec.UTF8.charSet) sameElements Array[Byte](0, 120, 54, 49, 0, 120, 54, 50), + ^ diff --git a/test/files/run/literals.flags b/test/files/run/literals.flags new file mode 100644 index 0000000000..dcc59ebe32 --- /dev/null +++ b/test/files/run/literals.flags @@ -0,0 +1 @@ +-deprecation diff --git a/test/files/run/literals.scala b/test/files/run/literals.scala index 5f23e6b492..13fda05876 100644 --- a/test/files/run/literals.scala +++ b/test/files/run/literals.scala @@ -14,21 +14,16 @@ object Test { def \u03b1\u03b1(that: GGG) = i + that.i } - def check_success[a](name: String, closure: => a, expected: a) { - print("test " + name) - try { - val actual: a = closure - if (actual == expected) { - print(" was successful"); - } else { - print(" failed: expected "+ expected +", found "+ actual); + def check_success[A](name: String, closure: => A, expected: A) { + val res: Option[String] = + try { + val actual: A = closure + if (actual == expected) None //print(" was successful") + else Some(s" failed: expected $expected, found $actual") + } catch { + case exception: Throwable => Some(s" raised exception $exception") } - } catch { - case exception: Throwable => { - print(" raised exception " + exception); - } - } - println + for (e <- res) println(s"test $name $e") } def main(args: Array[String]) { @@ -37,15 +32,14 @@ object Test { check_success("'\\u005f' == '_'", '\u005f', '_') check_success("65.asInstanceOf[Char] == 'A'", 65.asInstanceOf[Char], 'A') check_success("\"\\141\\142\" == \"ab\"", "\141\142", "ab") - check_success("\"\\0x61\\0x62\".trim() == \"x61\\0x62\"", "\0x61\0x62".substring(1), "x61\0x62") - - println + //check_success("\"\\0x61\\0x62\".trim() == \"x61\\0x62\"", "\0x61\0x62".substring(1), "x61\0x62") + check_success(""""\0x61\0x62".getBytes == Array(0, 120, ...)""", + "\0x61\0x62".getBytes(io.Codec.UTF8.charSet) sameElements Array[Byte](0, 120, 54, 49, 0, 120, 54, 50), + true) // boolean check_success("(65 : Byte) == 'A'", (65: Byte) == 'A', true) // contrib #176 - println - // int check_success("0X01 == 1", 0X01, 1) check_success("0x01 == 1", 0x01, 1) @@ -67,8 +61,6 @@ object Test { check_success("0x80000000 == -2147483648", 0x80000000, -2147483648) check_success("0xffffffff == -1", 0xffffffff, -1) - println - // long check_success("1l == 1L", 1l, 1L) check_success("1L == 1l", 1L, 1l) @@ -81,8 +73,6 @@ object Test { check_success("0xffffffffffffffffL == -1L", 0xffffffffffffffffL, -1L) - println - // see JLS at address: // http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#230798 @@ -97,8 +87,6 @@ object Test { check_success("1.asInstanceOf[Float] == 1.0", 1.asInstanceOf[Float], 1.0f) check_success("1l.asInstanceOf[Float] == 1.0", 1l.asInstanceOf[Float], 1.0f) - println - // double check_success("1e1 == 10.0", 1e1, 10.0) check_success(".3 == 0.3", .3, 0.3) @@ -112,7 +100,6 @@ object Test { check_success("1.asInstanceOf[Double] == 1.0", 1.asInstanceOf[Double], 1.0) check_success("1l.asInstanceOf[Double] == 1.0", 1l.asInstanceOf[Double], 1.0) - println check_success("\"\".length()", "\u001a".length(), 1) val ggg = GGG(1) \u03b1\u03b1 GGG(2) diff --git a/test/files/run/priorityQueue.scala b/test/files/run/priorityQueue.scala deleted file mode 100644 index 327d8bf137..0000000000 --- a/test/files/run/priorityQueue.scala +++ /dev/null @@ -1,373 +0,0 @@ - - - -import scala.collection.mutable.PriorityQueue - - - - - - -// populate a priority queue a few different ways and make sure they all seem equal -object Test { - - def main(args: Array[String]) { - // testInsertionsAndEqualities - // testIntensiveEnqueueDequeue - // testTails - // testInits - // testFilters - // testDrops - // testEquality - // testMisc - // testReverse - // testToList - // testForeach - } - - // def testInsertionsAndEqualities { - // import scala.util.Random.nextInt - // val pq1 = new PriorityQueue[String] - // val pq2 = new PriorityQueue[String] - // val pq3 = new PriorityQueue[String] - // val pq4 = new PriorityQueue[String] - - // val strings = (1 to 20).toList map (i => List.fill((Math.abs(nextInt % 20)) + 1)("x").mkString) - - // pq1 ++= strings - // pq2 ++= strings.reverse - // for (s <- strings) pq3 += s - // for (s <- strings.reverse) pq4 += s - - // val pqs = List(pq1, pq2, pq3, pq4, pq1.clone, pq2.clone) - - // for (queue1 <- pqs ; queue2 <- pqs) { - // val l1: List[String] = queue1.dequeueAll[String, List[String]] - // val l2: List[String] = queue2.dequeueAll[String, List[String]] - // assert(l1 == l2) - // assert(queue1.max == queue2.max) - // } - - // assertPriorityDestructive(pq1) - // } - - // not a sequence anymore, Mildred - // def testIndexing { - // val pq = new PriorityQueue[Char] - // "The quick brown fox jumps over the lazy dog".foreach(pq += _) - - // // val iter = pq.iterator - // // while (iter.hasNext) println("`" + iter.next + "`") - // assert(pq(0) == 'z') - // assert(pq(1) == 'y') - // assert(pq(2) == 'x') - // assert(pq(3) == 'w') - // assert(pq(4) == 'v') - // assert(pq(5) == 'u') - // assert(pq(7) == 't') - // assert(pq(8) == 's') - // assert(pq(9) == 'r') - // assert(pq(10) == 'r') - - // pq.clear - // "abcdefghijklmnopqrstuvwxyz".foreach(pq += _) - // for (i <- 0 until 26) assert(pq(i) == ('z' - i)) - - // val intpq = new PriorityQueue[Int] - // val intlst = new collection.mutable.ArrayBuffer ++ (0 until 100) - // val random = new util.Random(101) - // while (intlst.nonEmpty) { - // val idx = random.nextInt(intlst.size) - // intpq += intlst(idx) - // intlst.remove(idx) - // } - // for (i <- 0 until 100) assert(intpq(i) == (99 - i)) - // } - - // def testTails { - // val pq = new PriorityQueue[Int] - // for (i <- 0 until 10) pq += i * 4321 % 200 - - // assert(pq.size == 10) - // assert(pq.nonEmpty) - - // val tailpq = pq.tail - // // pq.printstate - // // tailpq.printstate - // assert(tailpq.size == 9) - // assert(tailpq.nonEmpty) - // assertPriorityDestructive(tailpq) - // } - - // def assertPriorityDestructive[A](pq: PriorityQueue[A])(implicit ord: Ordering[A]) { - // import ord._ - // var prev: A = null.asInstanceOf[A] - // while (pq.nonEmpty) { - // val curr = pq.dequeue - // if (prev != null) assert(curr <= prev) - // prev = curr - // } - // } - - // def testInits { - // val pq = new PriorityQueue[Long] - // for (i <- 0 until 20) pq += (i + 313) * 111 % 300 - - // assert(pq.size == 20) - - // val initpq = pq.init - // assert(initpq.size == 19) - // assertPriorityDestructive(initpq) - // } - - // def testFilters { - // val pq = new PriorityQueue[String] - // for (i <- 0 until 100) pq += "Some " + (i * 312 % 200) - - // val filpq = pq.filter(_.indexOf('0') != -1) - // assertPriorityDestructive(filpq) - // } - - // def testIntensiveEnqueueDequeue { - // val pq = new PriorityQueue[Int] - - // testIntensive(1000, pq) - // pq.clear - // testIntensive(200, pq) - // } - - // def testIntensive(sz: Int, pq: PriorityQueue[Int]) { - // val lst = new collection.mutable.ArrayBuffer[Int] ++ (0 until sz) - // val rand = new util.Random(7) - // while (lst.nonEmpty) { - // val idx = rand.nextInt(lst.size) - // pq.enqueue(lst(idx)) - // lst.remove(idx) - // if (rand.nextDouble < 0.25 && pq.nonEmpty) pq.dequeue - // assertPriority(pq) - // } - // } - - // def testDrops { - // val pq = new PriorityQueue[Int] - // pq ++= (0 until 100) - // val droppq = pq.drop(50) - // assertPriority(droppq) - - // pq.clear - // pq ++= droppq - // assertPriorityDestructive(droppq) - // assertPriority(pq) - // assertPriorityDestructive(pq) - // } - - // // your sequence days have ended, foul priority queue - // // def testUpdates { - // // val pq = new PriorityQueue[Int] - // // pq ++= (0 until 36) - // // assertPriority(pq) - - // // pq(0) = 100 - // // assert(pq(0) == 100) - // // assert(pq.dequeue == 100) - // // assertPriority(pq) - - // // pq.clear - - // // pq ++= (1 to 100) - // // pq(5) = 200 - // // assert(pq(0) == 200) - // // assert(pq(1) == 100) - // // assert(pq(2) == 99) - // // assert(pq(3) == 98) - // // assert(pq(4) == 97) - // // assert(pq(5) == 96) - // // assert(pq(6) == 94) - // // assert(pq(7) == 93) - // // assert(pq(98) == 2) - // // assert(pq(99) == 1) - // // assertPriority(pq) - - // // pq(99) = 450 - // // assert(pq(0) == 450) - // // assert(pq(1) == 200) - // // assert(pq(99) == 2) - // // assertPriority(pq) - - // // pq(1) = 0 - // // assert(pq(1) == 100) - // // assert(pq(99) == 0) - // // assertPriority(pq) - // // assertPriorityDestructive(pq) - // // } - - // def testEquality { - // val pq1 = new PriorityQueue[Int] - // val pq2 = new PriorityQueue[Int] - - // pq1 ++= (0 until 50) - // var i = 49 - // while (i >= 0) { - // pq2 += i - // i -= 1 - // } - // assert(pq1 == pq2) - // assertPriority(pq2) - - // pq1 += 100 - // assert(pq1 != pq2) - // pq2 += 100 - // assert(pq1 == pq2) - // pq2 += 200 - // assert(pq1 != pq2) - // pq1 += 200 - // assert(pq1 == pq2) - // assertPriorityDestructive(pq1) - // assertPriorityDestructive(pq2) - // } - - // def testMisc { - // val pq = new PriorityQueue[Int] - // pq ++= (0 until 100) - // assert(pq.size == 100) - - // val (p1, p2) = pq.partition(_ < 50) - // assertPriorityDestructive(p1) - // assertPriorityDestructive(p2) - - // val spq = pq.slice(25, 75) - // assertPriorityDestructive(spq) - - // pq.clear - // pq ++= (0 until 10) - // pq += 5 - // assert(pq.size == 11) - - // val ind = pq.lastIndexWhere(_ == 5) - // assert(ind == 5) - // assertPriorityDestructive(pq) - - // pq.clear - // pq ++= (0 until 10) - // assert(pq.lastIndexWhere(_ == 9) == 0) - // assert(pq.lastIndexOf(8) == 1) - // assert(pq.lastIndexOf(7) == 2) - - // pq += 5 - // pq += 9 - // assert(pq.lastIndexOf(9) == 1) - // assert(pq.lastIndexWhere(_ % 2 == 1) == 10) - // assert(pq.lastIndexOf(5) == 6) - - // val lst = pq.reverseIterator.toList - // for (i <- 0 until 5) assert(lst(i) == i) - // assert(lst(5) == 5) - // assert(lst(6) == 5) - // assert(lst(7) == 6) - // assert(lst(8) == 7) - // assert(lst(9) == 8) - // assert(lst(10) == 9) - // assert(lst(11) == 9) - - // pq.clear - // assert(pq.reverseIterator.toList.isEmpty) - - // pq ++= (50 to 75) - // assert(pq.lastIndexOf(70) == 5) - - // pq += 55 - // pq += 70 - // assert(pq.lastIndexOf(70) == 6) - // assert(pq.lastIndexOf(55) == 22) - // assert(pq.lastIndexOf(55, 21) == 21) - // assert(pq.lastIndexWhere(_ > 54) == 22) - // assert(pq.lastIndexWhere(_ > 54, 21) == 21) - // assert(pq.lastIndexWhere(_ > 69, 5) == 5) - // } - - // def testReverse { - // val pq = new PriorityQueue[(Int, Int)] - // pq ++= (for (i <- 0 until 10) yield (i, i * i % 10)) - - // assert(pq.reverse.size == pq.reverseIterator.toList.size) - // assert((pq.reverse zip pq.reverseIterator.toList).forall(p => p._1 == p._2)) - // assert(pq.reverse.sameElements(pq.reverseIterator.toSeq)) - // assert(pq.reverse(0)._1 == pq(9)._1) - // assert(pq.reverse(1)._1 == pq(8)._1) - // assert(pq.reverse(4)._1 == pq(5)._1) - // assert(pq.reverse(9)._1 == pq(0)._1) - - // pq += ((7, 7)) - // pq += ((7, 9)) - // pq += ((7, 8)) - // assert(pq.reverse.reverse == pq) - // assert(pq.reverse.lastIndexWhere(_._2 == 6) == 6) - // assertPriorityDestructive(pq.reverse.reverse) - - // val iq = new PriorityQueue[Int] - // iq ++= (0 until 50) - // assert(iq.reverse == iq.reverseIterator.toSeq) - // assert(iq.reverse.reverse == iq) - - // iq += 25 - // iq += 40 - // iq += 10 - // assert(iq.reverse == iq.reverseIterator.toList) - // assert(iq.reverse.reverse == iq) - // assert(iq.reverse.lastIndexWhere(_ == 10) == 11) - // assertPriorityDestructive(iq.reverse.reverse) - // } - - // def testToList { - // val pq = new PriorityQueue[Int] - - // pq += 1 - // pq += 4 - // pq += 0 - // pq += 5 - // pq += 3 - // pq += 2 - // assert(pq.toList == pq) - // assert(pq == List(5, 4, 3, 2, 1, 0)) - // assert(pq.reverse == List(0, 1, 2, 3, 4, 5)) - - // pq.clear - // for (i <- -50 until 50) pq += i - // assert(pq.toList == pq) - // assert(pq.toList == (-50 until 50).reverse) - // } - - // def testForeach { - // val pq = new PriorityQueue[Char] - - // pq += 't' - // pq += 'o' - // pq += 'b' - // pq += 'y' - // val sbf = new StringBuilder - // val sbi = new StringBuilder - // pq.foreach(sbf += _) - // pq.iterator.foreach(sbi += _) - // assert(sbf.toString == sbi.toString) - // assert(sbf.toString == "ytob") - // } - -} - - - - - - - - - - - - - - - - - - diff --git a/test/files/run/t6440.check b/test/files/run/t6440.check index 2358f08fcc..4d8618182b 100644 --- a/test/files/run/t6440.check +++ b/test/files/run/t6440.check @@ -1,5 +1,4 @@ -pos: source-newSource1.scala,line-9,offset=109 missing or invalid dependency detected while loading class file 'U.class'. -Could not access term pack1 in package <root>, -because it (or its dependencies) are missing. Check your build definition for -missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) -A full rebuild may help if 'U.class' was compiled against an incompatible version of <root>. ERROR +pos: source-newSource1.scala,line-9,offset=109 reference to U is ambiguous; +it is imported twice in the same scope by +import pack2._ +and import X._ ERROR diff --git a/test/files/run/t6440.scala b/test/files/run/t6440.scala index 5a3a4150d9..94eda3642e 100644 --- a/test/files/run/t6440.scala +++ b/test/files/run/t6440.scala @@ -41,7 +41,7 @@ object Test extends StoreReporterDirectTest { assert(tClass.delete()) assert(pack1.delete()) - // bad symbolic reference error expected (but no stack trace!) + // should report ambiguous import, despite the fact that a parent of pack2.U is absent compileCode(app) println(filteredInfos.mkString("\n")) } diff --git a/test/files/run/t6502.scala b/test/files/run/t6502.scala index ced1b5812d..4ce034a482 100644 --- a/test/files/run/t6502.scala +++ b/test/files/run/t6502.scala @@ -1,6 +1,7 @@ -import scala.tools.partest._ -import java.io.File +import scala.tools.nsc.Settings import scala.tools.nsc.interpreter.ILoop +import scala.tools.nsc.settings.ClassPathRepresentationType +import scala.tools.partest._ object Test extends StoreReporterDirectTest { def code = ??? @@ -10,6 +11,14 @@ object Test extends StoreReporterDirectTest { compileString(newCompiler("-cp", classpath, "-d", s"${testOutput.path}/$jarFileName"))(code) } + // TODO flat classpath doesn't support the classpath invalidation yet so we force using the recursive one + // it's the only test which needed such a workaround + override def settings = { + val settings = new Settings + settings.YclasspathImpl.value = ClassPathRepresentationType.Recursive + settings + } + def app1 = """ package test @@ -41,7 +50,8 @@ object Test extends StoreReporterDirectTest { val jar = "test1.jar" compileCode(app1, jar) - val output = ILoop.run(List(s":require ${testOutput.path}/$jar", "test.Test.test()")) + val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar", "test.Test.test()") + val output = ILoop.run(codeToRun, settings) val lines = output.split("\n") val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar") val res2 = lines(lines.length-3).contains("testing...") @@ -56,7 +66,8 @@ object Test extends StoreReporterDirectTest { val jar2 = "test2.jar" compileCode(app2, jar2) - val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar2")) + val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar2") + val output = ILoop.run(codeToRun, settings) val lines = output.split("\n") val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar") val res2 = lines(lines.length-3).contains("test2.jar") && lines(lines.length-3).contains("existing classpath entries conflict") @@ -71,7 +82,8 @@ object Test extends StoreReporterDirectTest { val jar3 = "test3.jar" compileCode(app3, jar3) - val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar3", "test.Test3.test()")) + val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar3", "test.Test3.test()") + val output = ILoop.run(codeToRun, settings) val lines = output.split("\n") val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar") val res2 = lines(lines.length-3).contains("new object in existing package") @@ -83,7 +95,8 @@ object Test extends StoreReporterDirectTest { def test4(): Unit = { // twice the same jar should be rejected val jar1 = "test1.jar" - val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar1")) + val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar1") + val output = ILoop.run(codeToRun, settings) val lines = output.split("\n") val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar") val res2 = lines(lines.length-3).contains("test1.jar") && lines(lines.length-3).contains("existing classpath entries conflict") @@ -98,4 +111,6 @@ object Test extends StoreReporterDirectTest { test3() test4() } + + def toCodeInSeparateLines(lines: String*): String = lines.map(_ + "\n").mkString } diff --git a/test/files/run/t6669.scala b/test/files/run/t6669.scala index e18f2514a9..27c4970d60 100644 --- a/test/files/run/t6669.scala +++ b/test/files/run/t6669.scala @@ -1,4 +1,5 @@ import java.io.{ByteArrayOutputStream, PrintStream} +import scala.reflect.io.File object Test extends App { val baos = new ByteArrayOutputStream() @@ -9,9 +10,11 @@ object Test extends App { scala.tools.scalap.Main.main(Array("-verbose", "java.lang.Object")) } + val currentLocationCpFragment = File.pathSeparator + "." + // now make sure we saw the '.' in the classpath val msg1 = baos.toString() - assert(msg1 contains "directory classpath: .", s"Did not see '.' in the default class path. Full results were:\n$msg1") + assert(msg1 contains currentLocationCpFragment, s"Did not see '.' in the default class path. Full results were:\n$msg1") // then test again with a user specified classpath baos.reset @@ -22,5 +25,5 @@ object Test extends App { // now make sure we did not see the '.' in the classpath val msg2 = baos.toString() - assert(!(msg2 contains "directory classpath: ."), s"Did saw '.' in the user specified class path. Full results were:\n$msg2") + assert(!(msg2 contains currentLocationCpFragment), s"Did saw '.' in the user specified class path. Full results were:\n$msg2") } diff --git a/test/files/run/t8502.scala b/test/files/run/t8502.scala new file mode 100644 index 0000000000..903e573711 --- /dev/null +++ b/test/files/run/t8502.scala @@ -0,0 +1,41 @@ +import scala.tools.partest._ +import java.io.File + +object Test extends StoreReporterDirectTest { + def code = ??? + + def compileCode(code: String) = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code) + } + + def show(): Unit = { + compileCode(""" + object U { + def foo(log: vanishing.Vanishing) = () + } + + package vanishing { + class Vanishing + } + """) + assert(filteredInfos.isEmpty, filteredInfos) + deletePackage("vanishing") + compileCode(""" + class Test { + U + } + """) + assert(storeReporter.infos.isEmpty, storeReporter.infos.mkString("\n")) // Included a MissingRequirementError before. + } + + def deletePackage(name: String) { + val directory = new File(testOutput.path, name) + for (f <- directory.listFiles()) { + assert(f.getName.endsWith(".class")) + assert(f.delete()) + } + assert(directory.listFiles().isEmpty) + assert(directory.delete()) + } +} diff --git a/test/files/run/t9003.flags b/test/files/run/t9003.flags new file mode 100644 index 0000000000..49d036a887 --- /dev/null +++ b/test/files/run/t9003.flags @@ -0,0 +1 @@ +-optimize diff --git a/test/files/run/t9003.scala b/test/files/run/t9003.scala new file mode 100644 index 0000000000..4f24712201 --- /dev/null +++ b/test/files/run/t9003.scala @@ -0,0 +1,71 @@ +object Single { + var i = 0 + def isEmpty = false + def get = i + def unapply(a: Single.type) = this +} + +object Product { + var i = 0 + def _1: Int = i + def _2: String = ??? + def productArity = 2 + def unapply(a: Product.type) = this + def isEmpty = false + def get: this.type = this +} + +object Sequence { + var i = 0 + def apply(n: Int): Int = i + def length = 2 + def unapplySeq(a: Sequence.type) = this + def isEmpty = false + def get = this +} + +object Test { + def main(args: Array[String]): Unit = { + def assertZero(i: Int) = assert(i == 0) + + Single match { + case Single(i) => + Single.i = 1 + assertZero(i) // fails under -optimize + } + + Product match { + case Product(i, _) => + Product.i = 1 + assertZero(i) // fails under -optimize + } + + Sequence match { + case Sequence(i, _ @ _*) => + Sequence.i = 1 + assertZero(i) // okay + } + + Sequence.i = 0 + Sequence match { + case Sequence(_, i) => + Sequence.i = 1 + assertZero(i) // okay + } + + val buffer = collection.mutable.Buffer(0, 0) + buffer match { + case Seq(_, i) => + buffer(1) = 1 + assertZero(i) // failed + } + + case class CaseSequence(as: Int*) + val buffer1 = collection.mutable.Buffer(0, 0) + CaseSequence(buffer1: _*) match { + case CaseSequence(_, i) => + buffer1(1) = 1 + assertZero(i) // failed + } + } +} diff --git a/test/files/run/t9027.check b/test/files/run/t9027.check new file mode 100644 index 0000000000..3429254286 --- /dev/null +++ b/test/files/run/t9027.check @@ -0,0 +1,19 @@ +{ + { + val $buf = new _root_.scala.xml.NodeBuffer(); + $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true)); + $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true)); + $buf + }; + println("hello, world.") +} +{ + { + val $buf = new _root_.scala.xml.NodeBuffer(); + $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true)); + $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true)); + $buf.$amp$plus(new _root_.scala.xml.Elem(null, "c", _root_.scala.xml.Null, $scope, true)); + $buf + }; + println("hello, world.") +} diff --git a/test/files/run/t9027.scala b/test/files/run/t9027.scala new file mode 100644 index 0000000000..26238147da --- /dev/null +++ b/test/files/run/t9027.scala @@ -0,0 +1,15 @@ + +// used to be parsed as .println +object Test extends App { + import reflect.runtime._, universe._ + + val trees = List( + q"""<a/><b/> + println("hello, world.")""", + q"""<a/> + <b/> + <c/> + println("hello, world.")""" + ) + trees foreach println +} diff --git a/test/files/run/various-flat-classpath-types.check b/test/files/run/various-flat-classpath-types.check new file mode 100644 index 0000000000..401f707d0e --- /dev/null +++ b/test/files/run/various-flat-classpath-types.check @@ -0,0 +1,12 @@ +ZipBin() +JarBin() +DirBin() +ZipSrc() +JarSrc() +DirSrc() +NestedZipBin() +NestedJarBin() +NestedDirBin() +NestedZipSrc() +NestedJarSrc() +NestedDirSrc()
\ No newline at end of file diff --git a/test/files/run/various-flat-classpath-types.scala b/test/files/run/various-flat-classpath-types.scala new file mode 100644 index 0000000000..d39019e885 --- /dev/null +++ b/test/files/run/various-flat-classpath-types.scala @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2014 Contributor. All rights reserved. + */ + +import java.io.{File => JFile, FileInputStream, FileOutputStream} +import java.util.zip.{ZipEntry, ZipOutputStream} +import scala.reflect.io.{Directory, File} +import scala.tools.nsc.classpath.FlatClassPath.RootPackage +import scala.tools.nsc.classpath.PackageNameUtils +import scala.tools.nsc.io.Jar + +/** + * Generates directories, jars and zip files containing sources and classes + * (the result of a compilation which is executed here) + * and use them as a class- and sourcepath during compilation and running + * created application. At the end everything is cleaned up. + * + * It can test also current, recursive classpath. Just right now we force + * flat classpath to test it also when the recursive one would be set as a default. + */ +object Test { + + private implicit class JFileOps(file: JFile) { + + def createDir(newDirName: String) = { + val newDir = new JFile(file, newDirName) + newDir.mkdir() + newDir + } + + def createSrcFile(newFileName: String) = createFile(newFileName + ".scala") + + def createFile(fullFileName: String) = { + val newFile = new JFile(file, fullFileName) + newFile.createNewFile() + newFile + } + + def writeAll(text: String): Unit = File(file) writeAll text + + def moveContentToZip(zipName: String): Unit = { + val newZip = zipsDir createFile s"$zipName.zip" + val outputStream = new ZipOutputStream(new FileOutputStream(newZip)) + + def addFileToZip(dirPrefix: String = "")(fileToAdd: JFile): Unit = + if (fileToAdd.isDirectory) { + val dirEntryName = fileToAdd.getName + "/" + outputStream.putNextEntry(new ZipEntry(dirEntryName)) + fileToAdd.listFiles() foreach addFileToZip(dirEntryName) + } else { + val inputStream = new FileInputStream(fileToAdd) + outputStream.putNextEntry(new ZipEntry(dirPrefix + fileToAdd.getName)) + + val buffer = new Array[Byte](1024) + var count = inputStream.read(buffer) + while (count > 0) { + outputStream.write(buffer, 0, count) + count = inputStream.read(buffer) + } + + inputStream.close() + } + + file.listFiles() foreach addFileToZip() + outputStream.close() + + cleanDir(file) + } + + def moveContentToJar(jarName: String): Unit = { + val newJar = jarsDir createFile s"$jarName.jar" + Jar.create(file = File(newJar), sourceDir = Directory(file), mainClass = "won't be used") + cleanDir(file) + } + + def path: String = file.getAbsolutePath + } + + private case class DirRep(name: String, nestedDirs: Seq[DirRep] = Nil, sourceFiles: Seq[String] = Nil) + + private val compiler = new scala.tools.nsc.MainClass + private val appRunner = new scala.tools.nsc.MainGenericRunner + private val classPathImplFlag = "-YclasspathImpl:flat" + private val javaClassPath = sys.props("java.class.path") + + // creates a test dir in a temporary dir containing compiled files of this test + // root dir will be automatically deleted after the end of test + private val rootDir = new JFile(sys.props("partest.output")) + private val testDir = rootDir createDir s"cp-tests-${System.currentTimeMillis()}" + + private val jarsDir = testDir createDir "jars" + private val zipsDir = testDir createDir "zips" + private val srcDir = testDir createDir "src" + private val binDir = testDir createDir "bin" + private val outDir = testDir createDir "out" + + def main(args: Array[String]): Unit = { + createClassesZipInZipsDir() + createClassesJarInJarsDir() + createClassesInBinDir() + createSourcesZipInZipsDir() + createSourcesJarInJarsDir() + createSourcesInSrcDir() + compileFinalApp() + runApp() + // at the end all created files will be deleted automatically + } + + private def createClassesZipInZipsDir(): Unit = { + val baseFileName = "ZipBin" + createStandardSrcHierarchy(baseFileName) + compileSrc(baseFileName) + outDir moveContentToZip "Bin" + cleanDir(srcDir) + } + + private def createClassesJarInJarsDir(): Unit = { + val baseFileName = "JarBin" + createStandardSrcHierarchy(baseFileName) + compileSrc(baseFileName) + outDir moveContentToJar "Bin" + cleanDir(srcDir) + } + + private def createClassesInBinDir(): Unit = { + val baseFileName = "DirBin" + createStandardSrcHierarchy(baseFileName) + compileSrc(baseFileName, destination = binDir) + cleanDir(srcDir) + } + + private def createSourcesZipInZipsDir(): Unit = { + createStandardSrcHierarchy(baseFileName = "ZipSrc") + srcDir moveContentToZip "Src" + } + + private def createSourcesJarInJarsDir(): Unit = { + createStandardSrcHierarchy(baseFileName = "JarSrc") + srcDir moveContentToJar "Src" + } + + private def createSourcesInSrcDir(): Unit = { + createStandardSrcHierarchy(baseFileName = "DirSrc") + + val appFile = srcDir createSrcFile "Main" + appFile writeAll s"""import nested._ + | object Main extends App { + | println(new ZipBin) + | println(new JarBin) + | println(new DirBin) + | println(new ZipSrc) + | println(new JarSrc) + | println(new DirSrc) + | + | println(new NestedZipBin) + | println(new NestedJarBin) + | println(new NestedDirBin) + | println(new NestedZipSrc) + | println(new NestedJarSrc) + | println(new NestedDirSrc) + | } + """.stripMargin + } + + private def compileFinalApp(): Unit = { + val classPath = mkPath(javaClassPath, binDir.path, zipsDir.path + "/Bin.zip", jarsDir.path + "/Bin.jar") + val sourcePath = mkPath(srcDir.path, zipsDir.path + "/Src.zip", jarsDir.path + "/Src.jar") + + compiler.process(Array(classPathImplFlag, "-cp", classPath, "-sourcepath", sourcePath, + "-d", outDir.path, s"${srcDir.path}/Main.scala")) + } + + private def runApp(): Unit = { + val classPath = mkPath(javaClassPath, outDir.path, binDir.path, zipsDir.path + "/Bin.zip", jarsDir.path + "/Bin.jar") + appRunner.process(Array(classPathImplFlag, "-cp", classPath, "Main")) + } + + private def createStandardSrcHierarchy(baseFileName: String): Unit = + createSources(RootPackage, srcDir, + DirRep("", + nestedDirs = Seq(DirRep("nested", sourceFiles = Seq("Nested" + baseFileName))), + sourceFiles = Seq(baseFileName) + ) + ) + + private def createSources(pkg: String, dirFile: JFile, dirRep: DirRep): Unit = { + dirRep.nestedDirs foreach { rep => + val nestedDir = dirFile createDir rep.name + val nestedPkg = PackageNameUtils.packagePrefix(pkg) + rep.name + createSources(nestedPkg, nestedDir, rep) + } + + val pkgHeader = if (pkg == RootPackage) "" else s"package $pkg\n\n" + dirRep.sourceFiles foreach { srcName => + val text = s"""${pkgHeader}case class $srcName(x: String = "")""" + val srcFile = dirFile createSrcFile srcName + srcFile writeAll text + } + } + + private def compileSrc(baseFileName: String, destination: JFile = outDir): Unit = { + val srcDirPath = srcDir.path + compiler.process(Array(classPathImplFlag, "-cp", javaClassPath, "-d", destination.path, + s"$srcDirPath/$baseFileName.scala", s"$srcDirPath/nested/Nested$baseFileName.scala")) + } + + private def cleanDir(dir: JFile): Unit = + dir.listFiles().foreach { file => + if (file.isDirectory) cleanDir(file) + file.delete() + } + + private def mkPath(pathEntries: String*) = pathEntries.mkString(File.pathSeparator) +} |