diff --git a/.appveyor.yml b/.appveyor.yml index d2529936c249..fd7e5630bd59 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,4 +15,6 @@ build_script: - cmd: sbt dotty-bootstrapped/compile test_script: - cmd: sbt "dotty-bootstrapped/dotc tests\pos\HelloWorld.scala" + # - cmd: sbt test + # - cmd: sbt dotty-bootstrapped/test - cmd: sbt sjsJUnitTests/test diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index d8083cee7309..6fab10c9301e 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -12,25 +12,25 @@ import Denotations.Denotation import typer.Typer import typer.ImportInfo._ import Decorators._ -import io.{AbstractFile, PlainFile} +import io.{AbstractFile, PlainFile, VirtualFile} import Phases.unfusedPhases -import scala.io.Codec import util._ import reporting.Reporter import rewrites.Rewrites -import java.io.{BufferedWriter, OutputStreamWriter} import profile.Profiler import printing.XprintMode import parsing.Parsers.Parser import parsing.JavaParsers.JavaParser import typer.ImplicitRunInfo -import collection.mutable -import dotty.tools.io.VirtualFile +import java.io.{BufferedWriter, OutputStreamWriter} +import java.nio.charset.StandardCharsets +import scala.collection.mutable import scala.util.control.NonFatal +import scala.io.Codec /** A compiler run. Exports various methods to compile source files */ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo { @@ -274,7 +274,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint val uuid = java.util.UUID.randomUUID().toString val ext = if (isJava) ".java" else ".scala" val virtualFile = new VirtualFile(s"compileFromString-$uuid.$ext") - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) // buffering is still advised by javadoc writer.write(source) writer.close() new SourceFile(virtualFile, Codec.UTF8) diff --git a/compiler/src/dotty/tools/dotc/config/Properties.scala b/compiler/src/dotty/tools/dotc/config/Properties.scala index 673499f3ceed..36d0e018bccb 100644 --- a/compiler/src/dotty/tools/dotc/config/Properties.scala +++ b/compiler/src/dotty/tools/dotc/config/Properties.scala @@ -6,6 +6,7 @@ import scala.annotation.internal.sharable import java.io.IOException import java.util.jar.Attributes.{ Name => AttributeName } +import java.nio.charset.StandardCharsets /** Loads `library.properties` from the jar. */ object Properties extends PropertiesTrait { @@ -88,13 +89,13 @@ trait PropertiesTrait { /** This is the encoding to use reading in source files, overridden with -encoding * Note that it uses "prop" i.e. looks in the scala jar, not the system properties. */ - def sourceEncoding: String = scalaPropOrElse("file.encoding", "UTF-8") + def sourceEncoding: String = scalaPropOrElse("file.encoding", StandardCharsets.UTF_8.name) def sourceReader: String = scalaPropOrElse("source.reader", "scala.tools.nsc.io.SourceReader") /** This is the default text encoding, overridden (unreliably) with * `JAVA_OPTS="-Dfile.encoding=Foo"` */ - def encodingString: String = propOrElse("file.encoding", "UTF-8") + def encodingString: String = propOrElse("file.encoding", StandardCharsets.UTF_8.name) /** The default end of line character. */ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala index c7bb68bd6aa2..62978d8b64d3 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala @@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts._ import dotty.tools.tasty.TastyBuffer import TastyBuffer.{Addr, NoAddr} -import java.nio.charset.Charset +import java.nio.charset.StandardCharsets class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]): private val buf = new TastyBuffer(5000) @@ -17,7 +17,7 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docStr private def pickleComment(addr: Addr, comment: Comment): Unit = if addr != NoAddr then - val bytes = comment.raw.getBytes(Charset.forName("UTF-8")) + val bytes = comment.raw.getBytes(StandardCharsets.UTF_8) val length = bytes.length buf.writeAddr(addr) buf.writeNat(length) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala index 5c18594b7ebe..d59b1e581b49 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala @@ -8,7 +8,7 @@ import util.HashMap import dotty.tools.tasty.{TastyReader, TastyBuffer} import TastyBuffer.Addr -import java.nio.charset.Charset +import java.nio.charset.StandardCharsets class CommentUnpickler(reader: TastyReader) { import reader._ @@ -21,7 +21,7 @@ class CommentUnpickler(reader: TastyReader) { if (length > 0) { val bytes = readBytes(length) val position = new Span(readLongInt()) - val rawComment = new String(bytes, Charset.forName("UTF-8")) + val rawComment = new String(bytes, StandardCharsets.UTF_8) comments(addr) = Comment(position, rawComment) } } diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index 1f067ba0f116..7b58237133bf 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -2,6 +2,7 @@ package dotty.tools.dotc package decompiler import java.io.{OutputStream, PrintStream} +import java.nio.charset.StandardCharsets import scala.io.Codec @@ -27,7 +28,7 @@ class DecompilationPrinter extends Phase { var ps: PrintStream = null try { os = File(outputDir.fileNamed("decompiled.scala").path)(Codec.UTF8).outputStream(append = true) - ps = new PrintStream(os, /* autoFlush = */ false, "UTF-8") + ps = new PrintStream(os, /* autoFlush = */ false, StandardCharsets.UTF_8.name) printToOutput(ps) } finally { diff --git a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala index d9c7d286f5be..f117d483c809 100644 --- a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala +++ b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala @@ -6,6 +6,7 @@ import java.net.URI import java.io._ import java.nio.file._ import java.nio.file.attribute.BasicFileAttributes +import java.nio.charset.StandardCharsets import java.util.zip._ import scala.collection._ @@ -298,7 +299,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver { private def toSource(uri: URI, sourceCode: String): SourceFile = { val path = Paths.get(uri) val virtualFile = new VirtualFile(path.getFileName.toString, path.toString) - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) writer.write(sourceCode) writer.close() new SourceFile(virtualFile, Codec.UTF8) diff --git a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala index 34210965607f..2d228ffeed64 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala @@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal import java.io.IOException import java.io.InputStream import java.util.Arrays +import java.nio.charset.StandardCharsets + import SemanticdbInputStream._ import scala.collection.mutable @@ -434,7 +436,7 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) { def readString(): String = { val size: Int = readRawVarint32() if (size <= (bufferSize - bufferPos) && size > 0) { - val result: String = new String(buffer, bufferPos, size, Internal.UTF_8) + val result: String = new String(buffer, bufferPos, size, StandardCharsets.UTF_8) bufferPos += size return result } @@ -442,7 +444,7 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) { return "" } else { - return new String(readRawBytesSlowPath(size), Internal.UTF_8) + return new String(readRawBytesSlowPath(size), StandardCharsets.UTF_8) } } diff --git a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbOutputStream.scala b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbOutputStream.scala index 2da5b70cbb91..da39949f09fc 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbOutputStream.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbOutputStream.scala @@ -3,6 +3,8 @@ package dotty.tools.dotc.semanticdb.internal import java.io.IOException import java.io.OutputStream import java.nio.ByteBuffer +import java.nio.charset.StandardCharsets + import SemanticdbOutputStream._ object SemanticdbOutputStream { @@ -144,7 +146,7 @@ object SemanticdbOutputStream { def computeBoolSizeNoTag(value: Boolean): Int = 1 def computeStringSizeNoTag(value: String): Int = { - val bytes = value.getBytes(Internal.UTF_8) + val bytes = value.getBytes(StandardCharsets.UTF_8) computeRawVarint32Size(bytes.length) + bytes.length } @@ -391,7 +393,7 @@ class SemanticdbOutputStream(output: OutputStream, buffer: Array[Byte]) { } def writeStringNoTag(value: String): Unit = { - val bytes = value.getBytes(Internal.UTF_8) + val bytes = value.getBytes(StandardCharsets.UTF_8) writeRawVarint32(bytes.length) writeRawBytes(bytes) } @@ -602,6 +604,5 @@ class SemanticdbOutputStream(output: OutputStream, buffer: Array[Byte]) { } object Internal { - val UTF_8 = java.nio.charset.Charset.forName("UTF-8") val EMPTY_BYTE_ARRAY: Array[Byte] = Array() } diff --git a/compiler/src/dotty/tools/dotc/util/ShowPickled.scala b/compiler/src/dotty/tools/dotc/util/ShowPickled.scala index f69b993ade4d..e744cc3c1e5e 100644 --- a/compiler/src/dotty/tools/dotc/util/ShowPickled.scala +++ b/compiler/src/dotty/tools/dotc/util/ShowPickled.scala @@ -2,9 +2,11 @@ package dotty.tools.dotc package util import java.io.PrintStream +import java.nio.charset.StandardCharsets import java.lang.Long.toHexString import java.lang.Float.intBitsToFloat import java.lang.Double.longBitsToDouble + import core.unpickleScala2.PickleBuffer import core.Names._ @@ -18,7 +20,7 @@ object ShowPickled { case _ => false } def readName: String = - if (isName) new String(bytes, "UTF-8") + if (isName) new String(bytes, StandardCharsets.UTF_8) else sys.error("%s is no name" format tagName) def nameIndex: Int = if (hasName) readNat(bytes, 0) diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index 82f6957a28a0..ba73ffd67167 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -2,19 +2,21 @@ package dotty.tools package dotc package util -import scala.collection.mutable.ArrayBuffer import dotty.tools.io._ -import java.util.regex.Pattern -import java.io.IOException -import scala.internal.Chars._ import Spans._ -import scala.io.Codec import core.Contexts._ + +import scala.io.Codec +import scala.internal.Chars._ import scala.annotation.internal.sharable -import java.util.concurrent.atomic.AtomicInteger import scala.collection.mutable +import scala.collection.mutable.ArrayBuffer +import java.io.IOException +import java.nio.charset.StandardCharsets import java.util.Optional +import java.util.concurrent.atomic.AtomicInteger +import java.util.regex.Pattern object ScriptSourceFile { @sharable private val headerPattern = Pattern.compile("""^(::)?!#.*(\r|\n|\r\n)""", Pattern.MULTILINE) @@ -212,7 +214,7 @@ object SourceFile { def fromId(id: Int): SourceFile = sourceOfChunk(id >> ChunkSizeLog) def virtual(name: String, content: String, maybeIncomplete: Boolean = false) = - val src = new SourceFile(new VirtualFile(name, content.getBytes), scala.io.Codec.UTF8) + val src = new SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), scala.io.Codec.UTF8) src._maybeInComplete = maybeIncomplete src diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 97865fc63eb0..f040d702a936 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -1,6 +1,7 @@ package dotty.tools.repl import java.io.{File => JFile, PrintStream} +import java.nio.charset.StandardCharsets import dotty.tools.dotc.ast.Trees._ import dotty.tools.dotc.ast.{tpd, untpd} @@ -367,7 +368,7 @@ class ReplDriver(settings: Array[String], case Load(path) => val file = new JFile(path) if (file.exists) { - val contents = Using(scala.io.Source.fromFile(file, "UTF-8"))(_.mkString).get + val contents = Using(scala.io.Source.fromFile(file, StandardCharsets.UTF_8.name))(_.mkString).get run(contents) } else { diff --git a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala index 7577ca411a7a..8a625590dc7a 100644 --- a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala @@ -129,7 +129,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting { ) }.checkRuns() - @Test def runWithCompiler: Unit = { + @Test def runWithCompiler: Unit = if (!scala.util.Properties.isWin) { implicit val testGroup: TestGroup = TestGroup("runWithCompiler") aggregateTests( compileFilesInDir("tests/run-with-compiler", withCompilerOptions), diff --git a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala index 460d8d459718..cd0aee578742 100644 --- a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala +++ b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala @@ -10,6 +10,7 @@ import reporting.TestReporter import java.io._ import java.nio.file.{Path => JPath} import java.lang.System.{lineSeparator => EOL} +import java.nio.charset.StandardCharsets import interfaces.Diagnostic.INFO import dotty.tools.io.Directory @@ -35,21 +36,8 @@ class PrintingTest { e.printStackTrace() } - val actualLines = byteStream.toString("UTF-8").split("\\r?\\n") - // 'options' includes option '-Xprint:typer' so the first output line - // looks similar to "result of tests/printing/i620.scala after typer:"; - // check files use slashes as file separators (Unix) but running tests - // on Windows produces backslashes. - // NB. option '-Xprint:<..>' can specify several phases. - val filteredLines = - if (config.Properties.isWin) - actualLines.map(line => - if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line - ) - else - actualLines - - FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath) + val actualLines = byteStream.toString(StandardCharsets.UTF_8.name).linesIterator + FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath) } @Test diff --git a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala index b3fe710c800e..a8418fafc770 100644 --- a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala +++ b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala @@ -36,7 +36,7 @@ class SemanticdbTests: val metacExpectFile = rootSrc.resolve("metac.expect") @Category(Array(classOf[dotty.SlowTests])) - @Test def expectTests: Unit = runExpectTest(updateExpectFiles = false) + @Test def expectTests: Unit = if (!scala.util.Properties.isWin) runExpectTest(updateExpectFiles = false) def runExpectTest(updateExpectFiles: Boolean): Unit = val target = generateSemanticdb() diff --git a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala index 4d0d197cbc47..646af4682a4f 100644 --- a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala +++ b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala @@ -20,23 +20,27 @@ class PatmatExhaustivityTest { // stop-after: patmatexhaust-huge.scala crash compiler val options = List("-color:never", "-Ystop-after:crossCast", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath) - private def compileFile(path: JPath): Boolean = { + private def compile(files: Seq[String]): Seq[String] = { val stringBuffer = new StringWriter() val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer)) try { - Main.process((path.toString::options).toArray, reporter, null) + Main.process((options ++ files).toArray, reporter, null) } catch { case e: Throwable => - println(s"Compile $path exception:") + println(s"Compile $files exception:") e.printStackTrace() } - val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match { + stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match { case "" => Nil - case s => s.split("\\r?\\n").toIndexedSeq + case s => s.linesIterator.toSeq } - val baseFilePath = path.toString.stripSuffix(".scala") + } + + private def compileFile(path: JPath): Boolean = { + val actualLines = compile(path.toString :: Nil) + val baseFilePath = path.toString.stripSuffix(".scala") val checkFilePath = baseFilePath + ".check" FileDiff.checkAndDump(path.toString, actualLines, checkFilePath) @@ -44,26 +48,11 @@ class PatmatExhaustivityTest { /** A single test with multiple files grouped in a folder */ private def compileDir(path: JPath): Boolean = { - val stringBuffer = new StringWriter() - val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer)) - val files = Directory(path).list.toList .filter(f => f.extension == "scala" || f.extension == "java" ) .map(_.jpath.toString) - try { - Main.process((options ++ files).toArray, reporter, null) - } catch { - case e: Throwable => - println(s"Compile $path exception:") - e.printStackTrace() - } - - val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match { - case "" => Nil - case s => s.split("\\r?\\n").toIndexedSeq - } - + val actualLines = compile(files) val checkFilePath = s"${path}${File.separator}expected.check" FileDiff.checkAndDump(path.toString, actualLines, checkFilePath) diff --git a/compiler/test/dotty/tools/repl/ReplTest.scala b/compiler/test/dotty/tools/repl/ReplTest.scala index 45e47c72cd73..70a4d0d224ca 100644 --- a/compiler/test/dotty/tools/repl/ReplTest.scala +++ b/compiler/test/dotty/tools/repl/ReplTest.scala @@ -2,12 +2,14 @@ package dotty.tools package repl import vulpix.TestConfiguration +import vulpix.FileDiff import java.lang.System.{lineSeparator => EOL} import java.io.{ByteArrayOutputStream, File => JFile, PrintStream} +import java.nio.charset.StandardCharsets + import scala.io.Source import scala.util.Using - import scala.collection.mutable.ArrayBuffer import dotty.tools.dotc.reporting.MessageRendering @@ -25,11 +27,11 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By "-color:never", "-Yerased-terms", ), - new PrintStream(out) + new PrintStream(out, true, StandardCharsets.UTF_8.name) ) with MessageRendering { /** Get the stored output from `out`, resetting the buffer */ def storedOutput(): String = { - val output = stripColor(out.toString) + val output = stripColor(out.toString(StandardCharsets.UTF_8.name)) out.reset() output } @@ -76,11 +78,11 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By } val expectedOutput = - Using(Source.fromFile(f, "UTF-8"))(_.getLines().flatMap(filterEmpties).mkString(EOL)).get + Using(Source.fromFile(f, StandardCharsets.UTF_8.name))(_.getLines().flatMap(filterEmpties).toList).get val actualOutput = { resetToInitial() - val lines = Using(Source.fromFile(f, "UTF-8"))(_.getLines.toList).get + val lines = Using(Source.fromFile(f, StandardCharsets.UTF_8.name))(_.getLines.toList).get assert(lines.head.startsWith(prompt), s"""Each file has to start with the prompt: "$prompt"""") val inputRes = lines.filter(_.startsWith(prompt)) @@ -88,23 +90,23 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By val buf = new ArrayBuffer[String] inputRes.foldLeft(initialState) { (state, input) => val (out, nstate) = evaluate(state, input) - buf.append(out) + out.linesIterator.foreach(buf.append) assert(out.endsWith("\n"), s"Expected output of $input to end with newline") nstate } - buf.flatMap(filterEmpties).mkString(EOL) + buf.toList.flatMap(filterEmpties) } - if (expectedOutput != actualOutput) { + if !FileDiff.matches(actualOutput, expectedOutput) then println("expected =========>") - println(expectedOutput) + println(expectedOutput.mkString(EOL)) println("actual ===========>") - println(actualOutput) + println(actualOutput.mkString(EOL)) fail(s"Error in file $f, expected output did not match actual") - } + end if } } diff --git a/compiler/test/dotty/tools/vulpix/FileDiff.scala b/compiler/test/dotty/tools/vulpix/FileDiff.scala index bee9a28db965..af44dbf2076d 100644 --- a/compiler/test/dotty/tools/vulpix/FileDiff.scala +++ b/compiler/test/dotty/tools/vulpix/FileDiff.scala @@ -2,9 +2,12 @@ package dotty.tools.vulpix import scala.io.Source import scala.util.Using + import java.io.File import java.lang.System.{lineSeparator => EOL} import java.nio.file.{Files, Paths} +import java.nio.charset.StandardCharsets + object FileDiff { def diffMessage(expectFile: String, actualFile: String): String = @@ -18,19 +21,28 @@ object FileDiff { def check(sourceTitle: String, outputLines: Seq[String], checkFile: String): Option[String] = { val checkLines = if (!(new File(checkFile)).exists) Nil - else Using(Source.fromFile(checkFile, "UTF-8"))(_.getLines().toList).get + else Using(Source.fromFile(checkFile, StandardCharsets.UTF_8.name))(_.getLines().toList).get - def linesMatch = - outputLines.length == checkLines.length && - outputLines.lazyZip(checkLines).forall(_ == _) - - if (!linesMatch) Some( + if (!matches(outputLines, checkLines)) Some( s"""|Output from '$sourceTitle' did not match check file. Actual output: |${outputLines.mkString(EOL)} |""".stripMargin + "\n") else None } + def matches(actual: String, expect: String): Boolean = { + val actual1 = actual.stripLineEnd + val expect1 = expect.stripLineEnd + + // handle check file path mismatch on windows + actual1 == expect1 || File.separatorChar == '\\' && actual1.replace('\\', '/') == expect1 + } + + def matches(actual: Seq[String], expect: Seq[String]): Boolean = { + actual.length == expect.length + && actual.lazyZip(expect).forall(matches) + } + def dump(path: String, content: Seq[String]): Unit = { val outFile = dotty.tools.io.File(path) outFile.writeAll(content.mkString("", EOL, EOL)) diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 7be747538852..6e66ebc4bcfd 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -2,10 +2,11 @@ package dotty package tools package vulpix -import java.io.{File => JFile} +import java.io.{File => JFile, IOException} import java.lang.System.{lineSeparator => EOL} import java.nio.file.StandardCopyOption.REPLACE_EXISTING import java.nio.file.{Files, NoSuchFileException, Path, Paths} +import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.{HashMap, Timer, TimerTask} import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors} @@ -451,7 +452,7 @@ trait ParallelTesting extends RunnerOrchestration { self => def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) { val fullArgs = Array( "javac", - "-encoding", "UTF-8", + "-encoding", StandardCharsets.UTF_8.name, ) ++ flags.javacFlags ++ fs val process = Runtime.getRuntime.exec(fullArgs) @@ -606,7 +607,11 @@ trait ParallelTesting extends RunnerOrchestration { self => testSource.sourceFiles.foreach { file => if checkFiles.contains(file) then val checkFile = checkFiles(file) - val actual = Source.fromFile(file, "UTF-8").getLines().toList + val actual = { + val source = Source.fromFile(file, StandardCharsets.UTF_8.name) + try source.getLines().toList + finally source.close() + } diffTest(testSource, checkFile, actual, reporters, logger) } @@ -690,7 +695,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val errorMap = new HashMap[String, Integer]() var expectedErrors = 0 files.filter(isSourceFile).foreach { file => - Using(Source.fromFile(file, "UTF-8")) { source => + Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source => source.getLines.zipWithIndex.foreach { case (line, lineNbr) => val errors = line.toSeq.sliding("// error".length).count(_.unwrap == "// error") if (errors > 0) @@ -728,7 +733,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val pos1 = error.pos.nonInlined val key = if (pos1.exists) { def toRelative(path: String): String = // For some reason, absolute paths leak from the compiler itself... - path.split("/").dropWhile(_ != "tests").mkString("/") + path.split(JFile.separatorChar).dropWhile(_ != "tests").mkString(JFile.separator) val fileName = toRelative(pos1.source.file.toString) s"$fileName:${pos1.line}" diff --git a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala index 779df71b7ba6..4fd415a1dcd2 100644 --- a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala +++ b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala @@ -4,6 +4,7 @@ package vulpix import java.io.{ File => JFile, InputStreamReader, BufferedReader, PrintStream } import java.nio.file.Paths +import java.nio.charset.StandardCharsets import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.TimeoutException @@ -117,7 +118,7 @@ trait RunnerOrchestration { val sb = new StringBuilder if (childStdout eq null) - childStdout = new BufferedReader(new InputStreamReader(process.getInputStream, "UTF-8")) + childStdout = new BufferedReader(new InputStreamReader(process.getInputStream, StandardCharsets.UTF_8)) var childOutput: String = childStdout.readLine() diff --git a/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala b/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala index 595367fd33c1..dfa89ec72825 100644 --- a/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala +++ b/compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala @@ -65,7 +65,8 @@ class VulpixUnitTests extends ParallelTesting { compileFile("tests/vulpix-tests/unit/runDiffOutput1.scala", defaultOptions).expectFailure.checkRuns() @Test def runStackOverflow: Unit = - compileFile("tests/vulpix-tests/unit/stackOverflow.scala", defaultOptions).expectFailure.checkRuns() + if (!scala.util.Properties.isWin) + compileFile("tests/vulpix-tests/unit/stackOverflow.scala", defaultOptions).expectFailure.checkRuns() @Test def runOutRedirects: Unit = compileFile("tests/vulpix-tests/unit/i2147.scala", defaultOptions).expectFailure.checkRuns() @@ -90,15 +91,16 @@ class VulpixUnitTests extends ParallelTesting { case ae: AssertionError => assertTrue(ae.getMessage.contains("java compilation failed")) } - @Test def runTimeout: Unit = { - val fileName = s"tests${JFile.separatorChar}vulpix-tests${JFile.separatorChar}unit${JFile.separatorChar}timeout.scala" + @Test def runTimeout: Unit = if (!scala.util.Properties.isWin) { + val fileName = s"tests/vulpix-tests/unit/timeout.scala" try { compileFile(fileName, defaultOptions).checkRuns() fail() } catch { case ae: AssertionError => - assertEquals(s"Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test '${fileName}' timed out", - ae.getMessage) + val expect = """(?m).*test '.+' timed out.*""" + val actual = ae.getMessage.linesIterator.toList.last + assert(actual.matches(expect), "actual = " + actual) } } } diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala index eb288bf60185..78871c888a3b 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala @@ -2,17 +2,20 @@ package dotty.tools package dottydoc package staticsite +import model.Package import dotc.util.SourceFile +import dotc.core.Contexts.{Context, ctx} +import io.VirtualFile + import com.vladsch.flexmark.html.HtmlRenderer import com.vladsch.flexmark.parser.Parser import com.vladsch.flexmark.ext.yaml.front.matter.AbstractYamlFrontMatterVisitor + import java.util.{ Map => JMap, List => JList } import java.io.{ OutputStreamWriter, BufferedWriter } +import java.nio.charset.StandardCharsets -import io.VirtualFile -import dotc.core.Contexts.{Context, ctx} -import model.Package import scala.io.Codec /** When the YAML front matter cannot be parsed, this exception is thrown */ @@ -82,7 +85,7 @@ trait Page { protected def virtualFile(subSource: String): SourceFile = { val virtualFile = new VirtualFile(path, path) - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) writer.write(subSource) writer.close() diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala index 7998dfcc9e9d..a35c8ae33212 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala @@ -124,7 +124,7 @@ case class Site( /** Create virtual file from string `sourceCode` */ private def stringToSourceFile(name: String, path: String, sourceCode: String): SourceFile = { val virtualFile = new VirtualFile(name, path) - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) writer.write(sourceCode) writer.close() @@ -413,7 +413,7 @@ case class Site( } private def toSourceFile(f: JFile): SourceFile = - new SourceFile(AbstractFile.getFile(new File(f.toPath)), Using(Source.fromFile(f, "UTF-8"))(_.toArray).get) + new SourceFile(AbstractFile.getFile(new File(f.toPath)), Using(Source.fromFile(f, StandardCharsets.UTF_8.name))(_.toArray).get) private def collectFiles(dir: JFile, includes: String => Boolean): Array[JFile] = dir diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Yaml.java b/doc-tool/src/dotty/tools/dottydoc/staticsite/Yaml.java index 60201752bef7..23f0c11be0d1 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Yaml.java +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Yaml.java @@ -6,12 +6,13 @@ import java.util.HashMap; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; public class Yaml { public static HashMap apply(String input) throws java.io.UnsupportedEncodingException, java.io.IOException { - ByteArrayInputStream is = new ByteArrayInputStream(input.getBytes("UTF-8")); + ByteArrayInputStream is = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); TypeReference> typeRef = diff --git a/doc-tool/test/dotty/tools/dottydoc/DottyDocTest.scala b/doc-tool/test/dotty/tools/dottydoc/DottyDocTest.scala index e2d0b494100c..157c9bd56fd3 100644 --- a/doc-tool/test/dotty/tools/dottydoc/DottyDocTest.scala +++ b/doc-tool/test/dotty/tools/dottydoc/DottyDocTest.scala @@ -20,6 +20,7 @@ import io.Directory import org.junit.Assert.fail import java.io.{ BufferedWriter, OutputStreamWriter } +import java.nio.charset.StandardCharsets trait DottyDocTest extends MessageRendering { dotty.tools.dotc.parsing.Scanners // initialize keywords @@ -80,7 +81,7 @@ trait DottyDocTest extends MessageRendering { private def sourceFileFromString(name: String, contents: String): SourceFile = { val virtualFile = new dotty.tools.io.VirtualFile(name) - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8)) writer.write(contents) writer.close() new SourceFile(virtualFile, scala.io.Codec.UTF8) diff --git a/doc-tool/test/dotty/tools/dottydoc/staticsite/SourceFileOps.scala b/doc-tool/test/dotty/tools/dottydoc/staticsite/SourceFileOps.scala index 7d27fedaed9a..698c9ffc93ed 100644 --- a/doc-tool/test/dotty/tools/dottydoc/staticsite/SourceFileOps.scala +++ b/doc-tool/test/dotty/tools/dottydoc/staticsite/SourceFileOps.scala @@ -3,12 +3,16 @@ package dottydoc package staticsite import dotc.util.SourceFile -import java.io.{ BufferedWriter, OutputStreamWriter } import io.VirtualFile -import scala.io.Codec import model.Package +import java.io.{ BufferedWriter, OutputStreamWriter } +import java.nio.charset.StandardCharsets + +import scala.io.Codec + + trait SourceFileOps { import scala.collection.JavaConverters._ val siteRoot = new java.io.File("doc-tool/resources/") @@ -19,7 +23,7 @@ trait SourceFileOps { def stringToSource(path: String, sourceCode: String): SourceFile = { val virtualFile = new VirtualFile(path, path) - val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) + val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, StandardCharsets.UTF_8.name)) writer.write(sourceCode) writer.close() diff --git a/language-server/test/dotty/tools/languageserver/DefinitionTest.scala b/language-server/test/dotty/tools/languageserver/DefinitionTest.scala index 064fc7393b98..4eebe9d40dd0 100644 --- a/language-server/test/dotty/tools/languageserver/DefinitionTest.scala +++ b/language-server/test/dotty/tools/languageserver/DefinitionTest.scala @@ -208,7 +208,7 @@ class DefinitionTest { .definition(m9 to m10, List(m3 to m4)) } - @Test def definitionFromTasty: Unit = { + @Test def definitionFromTasty: Unit = if (!scala.util.Properties.isWin) { withSources( tasty"""package mypackage class ${m1}A${m2}""", diff --git a/language-server/test/dotty/tools/languageserver/HoverTest.scala b/language-server/test/dotty/tools/languageserver/HoverTest.scala index 84652af55efc..54d3271f2565 100644 --- a/language-server/test/dotty/tools/languageserver/HoverTest.scala +++ b/language-server/test/dotty/tools/languageserver/HoverTest.scala @@ -101,7 +101,7 @@ class HoverTest { .hover(m3 to m4, hoverContent("Bar", "Test")) } - @Test def documentationIsFormatted: Unit = { + @Test def documentationIsFormatted: Unit = if (!scala.util.Properties.isWin) { code"""class Foo(val x: Int, val y: Int) { | /** | * Does something diff --git a/language-server/test/dotty/tools/languageserver/ReferencesTest.scala b/language-server/test/dotty/tools/languageserver/ReferencesTest.scala index 365e3fe00aa4..fae7c29bd378 100644 --- a/language-server/test/dotty/tools/languageserver/ReferencesTest.scala +++ b/language-server/test/dotty/tools/languageserver/ReferencesTest.scala @@ -201,7 +201,7 @@ class ReferencesTest { .references(m3 to m4, List(m3 to m4), withDecl = false) } - @Test def findReferencesInUntouchedProject: Unit = { + @Test def findReferencesInUntouchedProject: Unit = if (!scala.util.Properties.isWin) { val p0 = Project.withSources( code"""package hello |object A { def ${m1}foo${m2} = 1 }""" diff --git a/language-server/test/dotty/tools/languageserver/util/server/TestServer.scala b/language-server/test/dotty/tools/languageserver/util/server/TestServer.scala index ea6538c90f7b..06e0a7abad7a 100644 --- a/language-server/test/dotty/tools/languageserver/util/server/TestServer.scala +++ b/language-server/test/dotty/tools/languageserver/util/server/TestServer.scala @@ -4,6 +4,7 @@ import java.io.PrintWriter import java.io.File.{pathSeparator, separator} import java.net.URI import java.nio.file.{Files, Path} +import java.nio.charset.StandardCharsets import java.util import dotty.tools.dotc.Main @@ -138,7 +139,7 @@ class TestServer(testFolder: Path, projects: List[Project]) { val sourcesDir = sourceDirectory(project, wipe = true) val sources = project.sources.zipWithIndex.map { case (src, id) => val path = sourcesDir.resolve(src.sourceName(id)).toAbsolutePath - Files.write(path, src.text.getBytes("UTF-8")) + Files.write(path, src.text.getBytes(StandardCharsets.UTF_8.name)) path.toString } diff --git a/tests/generic-java-signatures/derivedNames.check b/tests/generic-java-signatures/derivedNames.check deleted file mode 100644 index ddcd95bfca29..000000000000 --- a/tests/generic-java-signatures/derivedNames.check +++ /dev/null @@ -1 +0,0 @@ -Test$Foo$A$B$> diff --git a/tests/generic-java-signatures/derivedNames.scala b/tests/generic-java-signatures/derivedNames.scala index e2bcbe0eecc0..0608bc54142b 100644 --- a/tests/generic-java-signatures/derivedNames.scala +++ b/tests/generic-java-signatures/derivedNames.scala @@ -1,8 +1,15 @@ +import java.lang.reflect.ParameterizedType + object Test { def main(args: Array[String]): Unit = { val objectB = classOf[Foo[Any]].getClasses - val returnType = objectB(1).getDeclaredMethod("m").getGenericReturnType - println(returnType) + val returnType = objectB(1).getDeclaredMethod("m").getGenericReturnType.asInstanceOf[ParameterizedType] + val out1 = "Test$Foo.Test$Foo$A.B$>" // Windows and OSX + val out2 = "Test$Foo$A$B$>" // Linux and sometimes Windows + if (scala.util.Properties.isWin) + assert(returnType.toString == out1 || returnType.toString == out2) + else + assert(returnType.toString == out2) } class Foo[T1] { class A[T2] diff --git a/tests/pos/i4588.scala b/tests/pos/i4588.scala new file mode 100644 index 000000000000..ff861b5469d8 --- /dev/null +++ b/tests/pos/i4588.scala @@ -0,0 +1,9 @@ +class Test { + type → + + def bar: → = ??? + + type `🤪` + + def baz: `🤪` = ??? +} diff --git a/tests/run-custom-args/tasty-interpreter/Test.scala b/tests/run-custom-args/tasty-interpreter/Test.scala index b27293f9937b..dbbd1b461855 100644 --- a/tests/run-custom-args/tasty-interpreter/Test.scala +++ b/tests/run-custom-args/tasty-interpreter/Test.scala @@ -84,7 +84,9 @@ object Test { val out = java.nio.file.Paths.get("out/interpreted") if (!java.nio.file.Files.exists(out)) java.nio.file.Files.createDirectory(out) - dotty.tools.dotc.Main.process(Array("-classpath", System.getProperty("java.class.path"), "-d", out.toString, "tests/run/" + testFileName), reproter) + + val filePath = "tests" + File.separator + "run" + File.separator + testFileName + dotty.tools.dotc.Main.process(Array("-classpath", System.getProperty("java.class.path"), "-d", out.toString, filePath), reproter) val actualOutput = interpret(out.toString)("Test")