Skip to content

Commit aed2662

Browse files
committed
prepare for Dotty: avoid scala-reflect
1 parent 3b7aff7 commit aed2662

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

junit/src/test/scala/scala/SerializationStabilityTest.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala
1414

1515
import javax.xml.bind.DatatypeConverter._
16-
import scala.reflect.io.File
16+
import java.nio.file.{ Path, Paths, Files }
1717
import org.junit.Test
1818

1919
// This test is self-modifying when run as follows:
@@ -24,7 +24,10 @@ import org.junit.Test
2424

2525
// based on run/t8549.scala partest
2626
object SerializationStability extends App {
27-
val overwrite: Option[File] = sys.props.get("overwrite.source").map(s => new File(new java.io.File(s).getAbsoluteFile))
27+
28+
val overwrite: Option[Path] =
29+
sys.props.get("overwrite.source")
30+
.map(s => Paths.get(s).toAbsolutePath)
2831

2932
def serialize(o: AnyRef): String = {
3033
val bos = new java.io.ByteArrayOutputStream()
@@ -34,13 +37,15 @@ object SerializationStability extends App {
3437
printBase64Binary(bos.toByteArray())
3538
}
3639

37-
def amend(file: File)(f: String => String): Unit = {
38-
file.writeAll(f(file.slurp()))
40+
def amend(path: Path)(f: String => String): Unit = {
41+
val old = new String(java.nio.file.Files.readAllBytes(path))
42+
Files.write(path, f(old).getBytes)
3943
}
44+
4045
def quote(s: String) = List("\"", s, "\"").mkString
4146

42-
def patch(file: File, line: Int, prevResult: String, result: String): Unit = {
43-
amend(file) {
47+
def patch(path: Path, line: Int, prevResult: String, result: String): Unit = {
48+
amend(path) {
4449
content =>
4550
content.linesIterator.toList.zipWithIndex.map {
4651
case (content, i) if i == line - 1 =>
@@ -53,14 +58,14 @@ object SerializationStability extends App {
5358
}
5459
}
5560

56-
def updateComment(file: File): Unit = {
61+
def updateComment(path: Path): Unit = {
5762
val timestamp = {
5863
import java.text.SimpleDateFormat
5964
val sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss")
6065
sdf.format(new java.util.Date)
6166
}
6267
val newComment = s" // Generated on $timestamp with Scala ${scala.util.Properties.versionString})"
63-
amend(file) {
68+
amend(path) {
6469
content =>
6570
content.linesIterator.toList.map {
6671
f => f.replaceAll("""^ +// Generated on.*""", newComment)

0 commit comments

Comments
 (0)