Skip to content

Commit f570fcc

Browse files
committed
Rewrite test
Test rewritings that were implemented so far.
1 parent 0cb2dd3 commit f570fcc

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

test/dotc/tests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class tests extends CompilerTest {
104104

105105
@Test def pos_scala2_all = compileFiles(posScala2Dir, scala2mode)
106106

107+
@Test def rewrites = compileFile(posScala2Dir, "rewrites", "-rewrite" :: scala2mode)
108+
107109
@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)
108110

109111
@Test def new_all = compileFiles(newDir, twice)

test/test/CompilerTest.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.reflect.io.{ Path, Directory, File => SFile, AbstractFile }
1010
import scala.tools.partest.nest.{ FileManager, NestUI }
1111
import scala.annotation.tailrec
1212
import java.io.{ RandomAccessFile, File => JFile }
13+
import dotty.tools.io.PlainFile
1314

1415
import org.junit.Test
1516

@@ -89,7 +90,20 @@ abstract class CompilerTest {
8990
if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions)) {
9091
if (runTest)
9192
log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension")
92-
compileArgs((s"$filePath" :: args).toArray, expErrors)
93+
if (args.contains("-rewrite")) {
94+
val file = new PlainFile(filePath)
95+
val data = file.toByteArray
96+
val cs = data.map(_.toChar)
97+
println(s"data = ${cs.mkString}")
98+
compileArgs((filePath :: args).toArray, expErrors)
99+
val plainArgs = args.filter(arg => arg != "-rewrite" && arg != "-language:Scala2")
100+
println(s"plainArgs = $plainArgs")
101+
compileFile(prefix, fileName, plainArgs, extension, runTest)
102+
val out = file.output
103+
out.write(data)
104+
out.close()
105+
}
106+
else compileArgs((filePath :: args).toArray, expErrors)
93107
} else {
94108
val kind = testKind(prefix, runTest)
95109
log(s"generating partest files for test file: $prefix$fileName$extension of kind $kind")
@@ -191,6 +205,8 @@ abstract class CompilerTest {
191205
}
192206
}
193207

208+
209+
194210
// ========== HELPERS =============
195211

196212
private def expectedErrors(filePaths: List[String]): List[ErrorsInFile] = if (filePaths.exists(isNegTest(_))) filePaths.map(getErrors(_)) else Nil

tests/pos-scala2/rewrites.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
trait Test {
2+
3+
def baz() {}
4+
5+
def bar()
6+
7+
def foo() {
8+
println("hi")
9+
}
10+
11+
lazy val x: Int
12+
}
13+
14+
object Test {
15+
16+
lazy val x = 1
17+
18+
@deprecated lazy val y = 2
19+
20+
@deprecated private lazy val z = 2
21+
22+
lazy val (x1, y1) = (1, 2)
23+
24+
@deprecated private lazy val (x2, y2) = (1, 2)
25+
26+
val yy = x1 _
27+
28+
}
29+

0 commit comments

Comments
 (0)