Skip to content

Commit

Permalink
honor -encoding compiler flag and defaults
Browse files Browse the repository at this point in the history
rename test/pos/valueclasses to pos_valueclasses

tests/pos/valueclasses generates a valueclasses.flags
file in /tests/partest-generated/pos that conflicts
with the valueClasses.flags file that
tests/neg/valueClasses.scala tries to create
  • Loading branch information
Martijn Hoekstra authored and Martijn Hoekstra committed Sep 7, 2016
1 parent 6bce106 commit 32819e2
Show file tree
Hide file tree
Showing 41 changed files with 50 additions and 27 deletions.
23 changes: 12 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# These files are text and should be normalized (convert crlf => lf)
*.c text
*.check text
*.css text
*.html text
*.java text
*.js text
*.sbt text
*.scala text
*.sh text
*.txt text
*.xml text

*.c text eol=lf
*.check text eol=lf
*.css text eol=lf
*.html text eol=lf
*.java text eol=lf
*.js text eol=lf
*.sbt text eol=lf
*.scala text eol=lf
*.sh text eol=lf
*.txt text eol=lf
*.xml text eol=lf

# Windows-specific files get windows endings
*.bat eol=crlf
Expand Down
2 changes: 1 addition & 1 deletion dottydoc/test/BaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import model.Package
trait DottyTest {
dotty.tools.dotc.parsing.Scanners // initialize keywords

implicit var ctx: FreshContext = {
implicit val ctx: FreshContext = {
val base = new ContextBase
import base.settings._
val ctx = base.initialCtx.fresh
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object DottyBuild extends Build {
homepage in Global := Some(url("https://github.com/lampepfl/dotty")),

// scalac options
scalacOptions in Global ++= Seq("-feature", "-deprecation", "-language:existentials,higherKinds,implicitConversions"),
scalacOptions in Global ++= Seq("-feature", "-deprecation", "-encoding", "UTF8", "-language:existentials,higherKinds,implicitConversions"),

javacOptions in Global ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")
)
Expand Down
6 changes: 4 additions & 2 deletions src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Phases._
import Decorators._
import dotty.tools.dotc.transform.TreeTransforms.TreeTransformer
import io.PlainFile
import scala.io.Codec
import util._
import reporting.Reporter
import transform.TreeChecker
Expand All @@ -28,8 +29,9 @@ class Run(comp: Compiler)(implicit ctx: Context) {
var units: List[CompilationUnit] = _

def getSource(fileName: String): SourceFile = {
val encoding = ctx.settings.encoding.value
val f = new PlainFile(fileName)
if (f.exists) new SourceFile(f)
if (f.exists) new SourceFile(f, Codec(encoding))
else {
ctx.error(s"not found: $fileName")
NoSource
Expand Down Expand Up @@ -113,7 +115,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
writer.write(sourceCode)
writer.close()
compileSources(List(new SourceFile(virtualFile)))
compileSources(List(new SourceFile(virtualFile, Codec.UTF8)))
}

/** The context created for this run */
Expand Down
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ object Settings {
private var values = ArrayBuffer(initialValues: _*)
private var _wasRead: Boolean = false

override def toString = s"SettingsState(values: ${values.toList})"

def value(idx: Int): Any = {
_wasRead = true
values(idx)
Expand Down
7 changes: 4 additions & 3 deletions src/dotty/tools/dotc/util/SourceFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.IOException
import Chars._
import ScriptSourceFile._
import Positions._
import scala.io.Codec

import java.util.Optional

Expand All @@ -36,9 +37,9 @@ object ScriptSourceFile {

case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfaces.SourceFile {

def this(_file: AbstractFile) = this(_file, _file.toCharArray)
def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
def this(_file: AbstractFile, codec: Codec) = this(_file, new String(_file.toByteArray, codec.charSet).toCharArray)
def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)

/** Tab increment; can be overridden */
def tabInc = 8
Expand Down
10 changes: 7 additions & 3 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class tests extends CompilerTest {
val defaultOutputDir = "./out/"

implicit val defaultOptions = noCheckOptions ++ List(
"-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases",
"-d", defaultOutputDir) ++ {
"-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", "-d", defaultOutputDir) ++ {
if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725
else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")
}
Expand All @@ -38,6 +37,9 @@ class tests extends CompilerTest {
val allowDoubleBindings = defaultOptions diff List("-Yno-double-bindings")
val scala2mode = List("-language:Scala2")

val explicitUTF8 = List("-encoding", "UTF8")
val explicitUTF16 = List("-encoding", "UTF16")

val testsDir = "./tests/"
val posDir = testsDir + "pos/"
val posSpecialDir = testsDir + "pos-special/"
Expand Down Expand Up @@ -95,7 +97,7 @@ class tests extends CompilerTest {
@Test def pos_overloadedAccess = compileFile(posDir, "overloadedAccess", twice)
@Test def pos_approximateUnion = compileFile(posDir, "approximateUnion", twice)
@Test def pos_tailcall = compileDir(posDir, "tailcall", twice)
@Test def pos_valueclasses = compileFiles(posDir + "valueclasses/", twice)
@Test def pos_valueclasses = compileFiles(posDir + "pos_valueclasses/", twice)
@Test def pos_nullarify = compileFile(posDir, "nullarify", args = "-Ycheck:nullarify" :: Nil)
@Test def pos_subtyping = compileFile(posDir, "subtyping", twice)
@Test def pos_packageObj = compileFile(posDir, "i0239", twice)
Expand All @@ -118,6 +120,8 @@ class tests extends CompilerTest {
compileFile(posSpecialDir, "spec-t5545/S_1")
compileFile(posSpecialDir, "spec-t5545/S_2")
}
@Test def pos_utf8 = compileFile(posSpecialDir, "utf8encoded", explicitUTF8)
@Test def pos_utf16 = compileFile(posSpecialDir, "utf16encoded", explicitUTF16)

@Test def new_all = compileFiles(newDir, twice)
@Test def repl_all = replFiles(replDir)
Expand Down
8 changes: 5 additions & 3 deletions test/test/CompilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ abstract class CompilerTest {
val flags = oldFlags.map(f => if (f == oldOutput) partestOutput else f) ++
List(s"-classpath $partestOutput") // Required for separate compilation tests

getExisting(dest).isDifferent(source, flags, nerr) match {
val difference = getExisting(dest).isDifferent(source, flags, nerr)
difference match {
case NotExists => copyFiles(source, dest, partestOutput, flags, nerr, kind)
case ExistsSame => // nothing else to do
case ExistsDifferent =>
Expand Down Expand Up @@ -449,6 +450,7 @@ abstract class CompilerTest {
/** Recursively copy over source files and directories, excluding extensions
* that aren't in extensionsToCopy. */
private def recCopyFiles(sourceFile: Path, dest: Path): Unit = {

def copyfile(file: SFile, bytewise: Boolean): Unit = {
if (bytewise) {
val in = file.inputStream()
Expand Down Expand Up @@ -490,7 +492,7 @@ abstract class CompilerTest {

/** Reads the existing files for the given test source if any. */
private def getExisting(dest: Path): ExistingFiles = {
val content: Option[Option[String]] = processFileDir(dest, f => f.safeSlurp, d => Some(""))
val content: Option[Option[String]] = processFileDir(dest, f => try Some(f.slurp("UTF8")) catch {case io: java.io.IOException => Some(io.toString())}, d => Some(""))
if (content.isDefined && content.get.isDefined) {
val flags = (dest changeExtension "flags").toFile.safeSlurp
val nerr = (dest changeExtension "nerr").toFile.safeSlurp
Expand All @@ -504,7 +506,7 @@ abstract class CompilerTest {
if (!genSrc.isDefined) {
NotExists
} else {
val source = processFileDir(sourceFile, { f => f.safeSlurp }, { d => Some("") },
val source = processFileDir(sourceFile, { f => try Some(f.slurp("UTF8")) catch {case _: java.io.IOException => None} }, { d => Some("") },
Some("DPCompilerTest sourceFile doesn't exist: " + sourceFile)).get
if (source == genSrc) {
nerr match {
Expand Down
1 change: 1 addition & 0 deletions test/test/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DottyTest /*extends ContextEscapeDetection*/ {
import base.settings._
val ctx = base.initialCtx.fresh
base.initialize()(ctx)
ctx.setSetting(ctx.settings.encoding, "UTF8")
ctx
}
/*
Expand Down
3 changes: 2 additions & 1 deletion test/test/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scala.reflect.io._
import dotty.tools.dotc.util._
import dotty.tools.dotc.core._
import dotty.tools.dotc.parsing._
import scala.io.Codec
import Tokens._, Parsers._
import dotty.tools.dotc.ast.untpd._
import org.junit.Test
Expand All @@ -23,7 +24,7 @@ class ParserTest extends DottyTest {

def parse(file: PlainFile): Tree = {
//println("***** parsing " + file)
val source = new SourceFile(file)
val source = new SourceFile(file, Codec.UTF8)
val parser = new Parser(source)
val tree = parser.parse()
parsed += 1
Expand Down
5 changes: 3 additions & 2 deletions test/test/ScannerTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import scala.reflect.io._
import scala.io.Codec
import dotty.tools.dotc.util._
import dotty.tools.dotc.parsing._
import Tokens._, Scanners._
Expand All @@ -16,8 +17,8 @@ class ScannerTest extends DottyTest {
def scan(name: String): Unit = scan(new PlainFile(name))

def scan(file: PlainFile): Unit = {
println("***** scanning " + file)
val source = new SourceFile(file)
//println("***** scanning " + file)
val source = new SourceFile(file, Codec.UTF8)
val scanner = new Scanner(source)
var i = 0
while (scanner.token != EOF) {
Expand Down
Binary file added tests/pos-special/utf16encoded.scala
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/pos-special/utf8encoded.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//this file is saved as UTF-8
object Test {
def main(args: Array[String]): Unit = {
val testchar = '⇒'
println(testchar == '\u21D2')
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 32819e2

Please sign in to comment.