From 42544e7a8308c2dc75e0a26200a249d121615976 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 14 Feb 2014 22:31:22 +0100 Subject: currentUnit.freshName => c.freshName (leads to less precise tests...) --- .../scala/async/internal/TransformUtils.scala | 4 ++-- src/test/scala/scala/async/TreeInterrogation.scala | 4 ++-- src/test/scala/scala/async/package.scala | 9 +++++++++ .../scala/async/run/anf/AnfTransformSpec.scala | 2 +- .../scala/async/run/live/LiveVariablesSpec.scala | 22 +++++++++++----------- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/scala/scala/async/internal/TransformUtils.scala b/src/main/scala/scala/async/internal/TransformUtils.scala index 03fb25d..83feb86 100644 --- a/src/main/scala/scala/async/internal/TransformUtils.scala +++ b/src/main/scala/scala/async/internal/TransformUtils.scala @@ -30,9 +30,9 @@ private[async] trait TransformUtils { val tr = newTermName("tr") val t = newTermName("throwable") - def fresh(name: TermName): TermName = newTermName(fresh(name.toString)) + def fresh(name: TermName): TermName = c.freshName(name) - def fresh(name: String): String = currentUnit.freshTermName("" + name + "$").toString + def fresh(name: String): String = c.freshName(name) } def isAwait(fun: Tree) = diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index 8261898..6e15513 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -38,7 +38,7 @@ class TreeInterrogation { val varDefs = tree1.collect { case ValDef(mods, name, _, _) if mods.hasFlag(Flag.MUTABLE) => name } - varDefs.map(_.decoded.trim).toSet mustBe (Set("state", "await$1$1", "await$2$1")) + varDefs.map(_.decoded.trim).toSet.toList.sorted mustStartWith (List("await$macro$", "await$macro$", "state")) val defDefs = tree1.collect { case t: Template => @@ -49,7 +49,7 @@ class TreeInterrogation { && !dd.symbol.asTerm.isAccessor && !dd.symbol.asTerm.isSetter => dd.name } }.flatten - defDefs.map(_.decoded.trim).toSet mustBe (Set("foo$1", "apply", "resume", "")) + defDefs.map(_.decoded.trim).toSet.toList.sorted mustStartWith (List("", "apply", "foo$macro$", "resume")) } } diff --git a/src/test/scala/scala/async/package.scala b/src/test/scala/scala/async/package.scala index 1c93776..166edaa 100644 --- a/src/test/scala/scala/async/package.scala +++ b/src/test/scala/scala/async/package.scala @@ -18,6 +18,15 @@ package object async { implicit class stringops(text: String) { def mustContain(substring: String) = assert(text contains substring, text) + + def mustStartWith(prefix: String) = assert(text startsWith prefix, text) + } + + implicit class listops(list: List[String]) { + def mustStartWith(prefixes: List[String]) = { + assert(list.length == prefixes.size, ("expected = " + prefixes.length + ", actual = " + list.length, list)) + list.zip(prefixes).foreach{ case (el, prefix) => el mustStartWith prefix } + } } def intercept[T <: Throwable : ClassTag](body: => Any): T = { diff --git a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala index 757ae0b..2cce7e8 100644 --- a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala +++ b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala @@ -403,6 +403,6 @@ class AnfTransformSpec { """.stripMargin }) val applyImplicitView = tree.collect { case x if x.getClass.getName.endsWith("ApplyImplicitView") => x } - applyImplicitView.map(_.toString) mustBe List("view(a$1)") + applyImplicitView.map(_.toString) mustStartWith List("view(a$macro$") } } diff --git a/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala b/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala index 17d33af..30646a6 100644 --- a/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala +++ b/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala @@ -36,9 +36,9 @@ class LiveVariablesSpec { // a == Cell(1) val b: Cell[Int] = await(m1(a)) // await$2$1 // b == Cell(2) - assert(AsyncTestLV.log.exists(_ == ("await$1$1" -> Cell(1))), AsyncTestLV.log) + assert(AsyncTestLV.log.exists(_._2 == Cell(1)), AsyncTestLV.log) val res = await(m2(b)) // await$3$1 - assert(AsyncTestLV.log.exists(_ == ("await$2$1" -> Cell(2)))) + assert(AsyncTestLV.log.exists(_._2 == Cell(2))) res } @@ -60,9 +60,9 @@ class LiveVariablesSpec { // a == Cell(1) val b: Any = await(m1(a)) // await$5$1 // b == Cell(2) - assert(AsyncTestLV.log.exists(_ == ("await$4$1" -> Cell(1)))) + assert(AsyncTestLV.log.exists(_._2 == Cell(1))) val res = await(m2(b)) // await$6$1 - assert(AsyncTestLV.log.exists(_ == ("await$5$1" -> Cell(2)))) + assert(AsyncTestLV.log.exists(_._2 == Cell(2))) res } @@ -84,9 +84,9 @@ class LiveVariablesSpec { // a == 1 val b: Any = await(m1(a)) // await$8$1 // b == Cell(2) - assert(!AsyncTestLV.log.exists(p => p._1 == "await$7$1")) + // assert(!AsyncTestLV.log.exists(p => p._1 == "await$7$1")) val res = await(m2(b)) // await$9$1 - assert(AsyncTestLV.log.exists(_ == ("await$8$1" -> Cell(2)))) + assert(AsyncTestLV.log.exists(_._2 == Cell(2))) res } @@ -108,9 +108,9 @@ class LiveVariablesSpec { // a == Cell(1) val b: Meter = await(m1(a)) // await$11$1 // b == Meter(2) - assert(AsyncTestLV.log.exists(_ == ("await$10$1" -> Cell(1)))) + assert(AsyncTestLV.log.exists(_._2 == Cell(1))) val res = await(m2(b.len)) // await$12$1 - assert(AsyncTestLV.log.exists(entry => entry._1 == "await$11$1" && entry._2.asInstanceOf[Meter].len == 2L)) + assert(AsyncTestLV.log.exists(_._2.asInstanceOf[Meter].len == 2L)) res } @@ -138,12 +138,12 @@ class LiveVariablesSpec { } // state #3 - assert(AsyncTestLV.log.exists(entry => entry._1 == "await$14$1")) + // assert(AsyncTestLV.log.exists(entry => entry._1 == "await$14$1")) val b = await(m1(a, y.v)) // await$15$1 // state #8 - assert(AsyncTestLV.log.exists(_ == ("a$1" -> MCell(10))), AsyncTestLV.log) - assert(AsyncTestLV.log.exists(_ == ("y$1" -> MCell(11)))) + assert(AsyncTestLV.log.exists(_._2 == MCell(10)), AsyncTestLV.log) + assert(AsyncTestLV.log.exists(_._2 == MCell(11))) b } -- cgit v1.2.3