Skip to content

Commit 00c9adb

Browse files
committed
test printing of annotations
1 parent 046f52a commit 00c9adb

9 files changed

+112
-8
lines changed

compiler/test/dotty/tools/dotc/printing/PrintingTest.scala

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ import scala.io.Source
1919
import org.junit.Test
2020

2121
class PrintingTest {
22-
val testsDir = "tests/printing"
23-
val options = List("-Xprint:typer", "-color:never", "-classpath", TestConfiguration.basicClasspath)
2422

25-
private def compileFile(path: JPath): Boolean = {
23+
def options(phase: String) =
24+
List(s"-Xprint:$phase", "-color:never", "-classpath", TestConfiguration.basicClasspath)
25+
26+
private def compileFile(path: JPath, phase: String): Boolean = {
2627
val baseFilePath = path.toString.stripSuffix(".scala")
2728
val checkFilePath = baseFilePath + ".check"
2829
val byteStream = new ByteArrayOutputStream()
2930
val reporter = TestReporter.reporter(new PrintStream(byteStream), INFO)
3031

3132
try {
32-
Main.process((path.toString::options).toArray, reporter, null)
33+
Main.process((path.toString::options(phase)).toArray, reporter, null)
3334
} catch {
3435
case e: Throwable =>
3536
println(s"Compile $path exception:")
@@ -40,11 +41,10 @@ class PrintingTest {
4041
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
4142
}
4243

43-
@Test
44-
def printing: Unit = {
44+
def testIn(testsDir: String, phase: String) =
4545
val res = Directory(testsDir).list.toList
4646
.filter(f => f.extension == "scala")
47-
.map { f => compileFile(f.jpath) }
47+
.map { f => compileFile(f.jpath, phase) }
4848

4949
val failed = res.filter(!_)
5050

@@ -53,5 +53,12 @@ class PrintingTest {
5353
assert(failed.length == 0, msg)
5454

5555
println(msg)
56-
}
56+
57+
end testIn
58+
59+
@Test
60+
def printing: Unit = testIn("tests/printing", "typer")
61+
62+
@Test
63+
def untypedPrinting: Unit = testIn("tests/printing/untyped", "parser")
5764
}

tests/printing/annot-printing.check

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[[syntax trees at end of typer]] // tests/printing/annot-printing.scala
2+
package <empty> {
3+
import scala.annotation.*
4+
class Foo() extends annotation.Annotation() {}
5+
class Bar(s: String) extends annotation.Annotation() {
6+
private[this] val s: String
7+
}
8+
class Xyz(i: Int) extends annotation.Annotation() {
9+
private[this] val i: Int
10+
}
11+
final lazy module val Xyz: Xyz = new Xyz()
12+
final module class Xyz() extends AnyRef() { this: Xyz.type =>
13+
def $lessinit$greater$default$1: Int @uncheckedVariance = 23
14+
}
15+
final lazy module val annot-printing$package: annot-printing$package =
16+
new annot-printing$package()
17+
final module class annot-printing$package() extends Object() {
18+
this: annot-printing$package.type =>
19+
def x: Int @nowarn() @main @Xyz() @Foo @Bar("hello") = ???
20+
}
21+
}
22+

tests/printing/annot-printing.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.annotation.*
2+
3+
class Foo() extends Annotation
4+
class Bar(s: String) extends Annotation
5+
class Xyz(i: Int = 23) extends Annotation
6+
7+
def x: Int @nowarn @main @Xyz() @Foo @Bar("hello") = ???

tests/printing/dependent-annot.check

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[syntax trees at end of typer]] // tests/printing/dependent-annot.scala
2+
package <empty> {
3+
class C() extends Object() {}
4+
class ann(x: Seq[Any] @Repeated) extends annotation.Annotation() {
5+
private[this] val x: Seq[Any] @Repeated
6+
}
7+
final lazy module val dependent-annot$package: dependent-annot$package =
8+
new dependent-annot$package()
9+
final module class dependent-annot$package() extends Object() {
10+
this: dependent-annot$package.type =>
11+
def f(y: C, z: C): Unit =
12+
{
13+
def g(): C @ann([y,z : Any]*) = ???
14+
val ac:
15+
(C => Array[String])
16+
{
17+
def apply(x: C): Array[String @ann([x : Any]*)]
18+
}
19+
= ???
20+
val dc: Array[String] = ac.apply(g())
21+
()
22+
}
23+
}
24+
}
25+

tests/printing/dependent-annot.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C
2+
class ann(x: Any*) extends annotation.Annotation
3+
4+
def f(y: C, z: C) =
5+
def g(): C @ann(y, z) = ???
6+
val ac: ((x: C) => Array[String @ann(x)]) = ???
7+
val dc = ac(g())
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[[syntax trees at end of parser]] // tests/printing/untyped/annot-printing.scala
2+
package <empty> {
3+
import scala.annotation.*
4+
class Foo() extends Annotation {}
5+
class Bar(private[this] val s: String) extends Annotation {}
6+
class Xyz(private[this] val i: Int = 23) extends Annotation {}
7+
def x: Int @nowarn @main @Xyz @Foo @Bar("hello") = ???
8+
}
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.annotation.*
2+
3+
class Foo() extends Annotation
4+
class Bar(s: String) extends Annotation
5+
class Xyz(i: Int = 23) extends Annotation
6+
7+
def x: Int @nowarn @main @Xyz() @Foo @Bar("hello") = ???
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[syntax trees at end of parser]] // tests/printing/untyped/dependent-annot.scala
2+
package <empty> {
3+
class C {}
4+
class ann(private[this] val x: Any *) extends annotation.Annotation {}
5+
def f(y: C, z: C) =
6+
{
7+
def g(): C @ann(y, z) = ???
8+
val ac: ((x: C) => Array[String @ann(x)]) = ???
9+
val dc = ac(g())
10+
<empty>
11+
}
12+
}
13+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C
2+
class ann(x: Any*) extends annotation.Annotation
3+
4+
def f(y: C, z: C) =
5+
def g(): C @ann(y, z) = ???
6+
val ac: ((x: C) => Array[String @ann(x)]) = ???
7+
val dc = ac(g())

0 commit comments

Comments
 (0)