Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5129: Use system-dependent path separator #5130

Merged
merged 1 commit into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/test/dotty/tools/dotc/FromTastyTests.scala
Expand Up @@ -5,6 +5,8 @@ package dotc
import org.junit.{AfterClass, Test}
import vulpix._

import java.io.{File => JFile}

import scala.concurrent.duration._

class FromTastyTests extends ParallelTesting {
Expand All @@ -26,7 +28,7 @@ class FromTastyTests extends ParallelTesting {
// > dotc -Ythrough-tasty -Ycheck:all <source>

implicit val testGroup: TestGroup = TestGroup("posTestFromTasty")
compileTastyInDir("tests/pos", defaultOptions,
compileTastyInDir(s"tests${JFile.separator}pos", defaultOptions,
fromTastyFilter = FileFilter.exclude(TestSources.posFromTastyBlacklisted),
decompilationFilter = FileFilter.exclude(TestSources.posDecompilationBlacklisted),
recompilationFilter = FileFilter.include(TestSources.posRecompilationWhitelist)
Expand All @@ -40,7 +42,7 @@ class FromTastyTests extends ParallelTesting {
// > dotr Test

implicit val testGroup: TestGroup = TestGroup("runTestFromTasty")
compileTastyInDir("tests/run", defaultOptions,
compileTastyInDir(s"tests${JFile.separator}run", defaultOptions,
fromTastyFilter = FileFilter.exclude(TestSources.runFromTastyBlacklisted),
decompilationFilter = FileFilter.exclude(TestSources.runDecompilationBlacklisted),
recompilationFilter = FileFilter.include(TestSources.runRecompilationWhitelist)
Expand Down
53 changes: 28 additions & 25 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Expand Up @@ -54,7 +54,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
def outDir: JFile
def flags: TestFlags

def runClassPath: String = outDir.getAbsolutePath + ":" + flags.runClassPath
def runClassPath: String = outDir.getAbsolutePath + JFile.pathSeparator + flags.runClassPath

def title: String = self match {
case self: JointCompilationSource =>
Expand Down Expand Up @@ -337,7 +337,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
"javac",
"-encoding", "UTF-8",
"-classpath",
s"${Properties.scalaLibrary}:${targetDir.getAbsolutePath}"
s"${Properties.scalaLibrary}${JFile.pathSeparator}${targetDir.getAbsolutePath}"
) ++ flags.all.takeRight(2) ++ fs

val process = Runtime.getRuntime.exec(fullArgs)
Expand Down Expand Up @@ -396,7 +396,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
val flags = flags0 and ("-d", tastyOutput.getAbsolutePath) and "-from-tasty"

def tastyFileToClassName(f: JFile): String = {
val pathStr = targetDir.toPath.relativize(f.toPath).toString.replace('/', '.')
val pathStr = targetDir.toPath.relativize(f.toPath).toString.replace(JFile.separatorChar, '.')
pathStr.stripSuffix(".tasty").stripSuffix(".hasTasty")
}
val classes = flattenFiles(targetDir).filter(isTastyFile).map(tastyFileToClassName)
Expand All @@ -420,14 +420,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>

protected def decompile(flags0: TestFlags, suppressErrors: Boolean, targetDir0: JFile): TestReporter = {
val targetDir = new JFile(targetDir0.getParent + "_decompiled")
val decompilationOutput = new JFile(targetDir + "/" + targetDir0.getName)
val decompilationOutput = new JFile(targetDir + JFile.separator + targetDir0.getName)
decompilationOutput.mkdirs()
val flags =
flags0 and ("-d", decompilationOutput.getAbsolutePath) and
"-decompile" and "-pagewidth" and "80"

def hasTastyFileToClassName(f: JFile): String =
targetDir0.toPath.relativize(f.toPath).toString.stripSuffix(".hasTasty").stripSuffix(".tasty").replace('/', '.')
targetDir0.toPath.relativize(f.toPath).toString.stripSuffix(".hasTasty").
stripSuffix(".tasty").replace(JFile.separatorChar, '.')
val classes = flattenFiles(targetDir0).filter(isTastyFile).map(hasTastyFileToClassName).sorted

val reporter =
Expand Down Expand Up @@ -531,17 +532,19 @@ trait ParallelTesting extends RunnerOrchestration { self =>
}.headOption
checkFileOpt match {
case Some(checkFile) =>
val ignoredFilePathLine = "/** Decompiled from"
val stripTrailingWhitespaces = "(.*\\S|)\\s+".r
val output = Source.fromFile(outDir.getParent + "_decompiled/" + outDir.getName + "/decompiled.scala").getLines().map {line =>
val output = Source.fromFile(outDir.getParent + "_decompiled" + JFile.separator + outDir.getName
+ JFile.separator + "decompiled.scala").getLines().map {line =>
stripTrailingWhitespaces.unapplySeq(line).map(_.head).getOrElse(line)
}.mkString("\n")

val check: String = Source.fromFile(checkFile).getLines().mkString("\n")
}

val check: String = Source.fromFile(checkFile).getLines().filter(!_.startsWith(ignoredFilePathLine))
.mkString("\n")

if (output != check) {
if (output.filter(!_.startsWith(ignoredFilePathLine)).mkString("\n") != check) {
val outFile = dotty.tools.io.File(checkFile.toPath).addExtension(".out")
outFile.writeAll(output)
outFile.writeAll(output.mkString("\n"))
val msg =
s"""Output differed for test $name, use the following command to see the diff:
| > diff $checkFile $outFile
Expand Down Expand Up @@ -678,7 +681,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
(reporter.compilerCrashed, reporter.errorCount, reporter.warningCount, () => verifyOutput(checkFile, outDir, testSource, reporter.warningCount))

case testSource @ SeparateCompilationSource(_, dir, flags, outDir) =>
val checkFile = new JFile(dir.getAbsolutePath.reverse.dropWhile(_ == '/').reverse + ".check")
val checkFile = new JFile(dir.getAbsolutePath.reverse.dropWhile(_ == JFile.separatorChar).reverse + ".check")
val reporters = testSource.compilationGroups.map(compile(_, flags, false, outDir))
val compilerCrashed = reporters.exists(_.compilerCrashed)
val (errorCount, warningCount) =
Expand Down Expand Up @@ -1120,15 +1123,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>
/** Create out directory for `file` */
private def createOutputDirsForFile(file: JFile, sourceDir: JFile, outDir: String): JFile = {
val uniqueSubdir = file.getName.substring(0, file.getName.lastIndexOf('.'))
val targetDir = new JFile(outDir + s"${sourceDir.getName}/$uniqueSubdir")
val targetDir = new JFile(outDir + s"${sourceDir.getName}${JFile.separatorChar}$uniqueSubdir")
targetDir.mkdirs()
targetDir
}

/** Make sure that directory string is as expected */
private def checkRequirements(f: String, sourceDir: JFile, outDir: String): Unit = {
require(sourceDir.isDirectory && sourceDir.exists, "passed non-directory to `compileFilesInDir`")
require(outDir.last == '/', "please specify an `outDir` with a trailing slash")
require(outDir.last == JFile.separatorChar, "please specify an `outDir` with a trailing file separator")
}

/** Separates directories from files and returns them as `(dirs, files)` */
Expand All @@ -1145,8 +1148,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
val sourceFile = new JFile(f)
val parent = sourceFile.getParentFile
val outDir =
defaultOutputDir + testGroup + "/" +
sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + "/"
defaultOutputDir + testGroup + JFile.separator +
sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + JFile.separator

require(
sourceFile.exists && !sourceFile.isDirectory &&
Expand All @@ -1171,7 +1174,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
* can be used for randomization.
*/
def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, recursive: Boolean = true)(implicit testGroup: TestGroup): CompilationTest = {
val outDir = defaultOutputDir + testGroup + "/"
val outDir = defaultOutputDir + testGroup + JFile.separator
val sourceDir = new JFile(f)
checkRequirements(f, sourceDir, outDir)

Expand All @@ -1190,7 +1193,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
}

// Directories in which to compile all containing files with `flags`:
val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
val targetDir = new JFile(outDir + JFile.separator + sourceDir.getName + JFile.separator)
targetDir.mkdirs()

val target = JointCompilationSource(s"compiling '$f' in test '$testGroup'", randomized, flags, targetDir)
Expand All @@ -1202,7 +1205,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
* dissociated
*/
def compileList(testName: String, files: List[String], flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = {
val outDir = defaultOutputDir + testGroup + "/" + testName + "/"
val outDir = defaultOutputDir + testGroup + JFile.separator + testName + JFile.separator

// Directories in which to compile all containing files with `flags`:
val targetDir = new JFile(outDir)
Expand Down Expand Up @@ -1233,7 +1236,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
* the same name as the directory (with the file extension `.check`)
*/
def compileFilesInDir(f: String, flags: TestFlags, fileFilter: FileFilter = FileFilter.NoFilter)(implicit testGroup: TestGroup): CompilationTest = {
val outDir = defaultOutputDir + testGroup + "/"
val outDir = defaultOutputDir + testGroup + JFile.separator
val sourceDir = new JFile(f)
checkRequirements(f, sourceDir, outDir)

Expand Down Expand Up @@ -1269,7 +1272,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
*/
def compileTastyInDir(f: String, flags0: TestFlags, fromTastyFilter: FileFilter, decompilationFilter: FileFilter, recompilationFilter: FileFilter)(
implicit testGroup: TestGroup): TastyCompilationTest = {
val outDir = defaultOutputDir + testGroup + "/"
val outDir = defaultOutputDir + testGroup + JFile.separator
val flags = flags0 and "-Yretain-trees"
val sourceDir = new JFile(f)
checkRequirements(f, sourceDir, outDir)
Expand All @@ -1291,15 +1294,15 @@ trait ParallelTesting extends RunnerOrchestration { self =>
) extends JointCompilationSource(name, Array(file), flags, outDir, fromTasty, decompilation) {

override def buildInstructions(errors: Int, warnings: Int): String = {
val runOrPos = if (file.getPath.startsWith("tests/run/")) "run" else "pos"
val runOrPos = if (file.getPath.startsWith(s"tests${JFile.separator}run${JFile.separator}")) "run" else "pos"
val listName = if (fromTasty) "from-tasty" else "decompilation"
s"""|
|Test '$title' compiled with $errors error(s) and $warnings warning(s),
|the test can be reproduced by running:
|
| sbt "testFromTasty $file"
|
|This tests can be disabled by adding `${file.getName}` to `compiler/test/dotc/$runOrPos-$listName.blacklist`
|This tests can be disabled by adding `${file.getName}` to `compiler${JFile.separator}test${JFile.separator}dotc${JFile.separator}$runOrPos-$listName.blacklist`
|
|""".stripMargin
}
Expand Down Expand Up @@ -1378,7 +1381,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
* tests.
*/
def compileShallowFilesInDir(f: String, flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = {
val outDir = defaultOutputDir + testGroup + "/"
val outDir = defaultOutputDir + testGroup + JFile.separator
val sourceDir = new JFile(f)
checkRequirements(f, sourceDir, outDir)

Expand All @@ -1395,7 +1398,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>

object ParallelTesting {

def defaultOutputDir: String = "out/"
def defaultOutputDir: String = "out"+JFile.separator

def isSourceFile(f: JFile): Boolean = {
val name = f.getName
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala
Expand Up @@ -156,9 +156,9 @@ trait RunnerOrchestration {
* scala library.
*/
private def createProcess: Process = {
val sep = sys.props("file.separator")
val sep = JFile.separator
val cp =
classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation.getFile + ":" +
classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation.getFile + JFile.pathSeparator +
Properties.scalaLibrary
val javaBin = sys.props("java.home") + sep + "bin" + sep + "java"
new ProcessBuilder(javaBin, "-Xmx1g", "-cp", cp, "dotty.tools.vulpix.ChildJVMMain")
Expand Down
6 changes: 4 additions & 2 deletions compiler/test/dotty/tools/vulpix/TestFlags.scala
@@ -1,5 +1,7 @@
package dotty.tools.vulpix

import java.io.{File => JFile}

final case class TestFlags(
defaultClassPath: String,
runClassPath: String, // class path that is used when running `run` tests (not compiling)
Expand All @@ -12,10 +14,10 @@ final case class TestFlags(
TestFlags(defaultClassPath, runClassPath, options diff flags)

def withClasspath(classPath: String): TestFlags =
TestFlags(s"$defaultClassPath:$classPath", runClassPath, options)
TestFlags(s"$defaultClassPath${JFile.pathSeparator}$classPath", runClassPath, options)

def withRunClasspath(classPath: String): TestFlags =
TestFlags(defaultClassPath, s"$runClassPath:$classPath", options)
TestFlags(defaultClassPath, s"$runClassPath${JFile.pathSeparator}$classPath", options)

def all: Array[String] = Array("-classpath", defaultClassPath) ++ options
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala
@@ -1,6 +1,7 @@
package dotty.tools
package vulpix

import java.io.{File => JFile}
import org.junit.Assert._
import org.junit.Test

Expand Down Expand Up @@ -86,12 +87,13 @@ class VulpixUnitTests extends ParallelTesting {
}

@Test def runTimeout: Unit = {
val fileName = s"tests${JFile.separatorChar}vulpix-tests${JFile.separatorChar}unit${JFile.separatorChar}timeout.scala"
try {
compileFile("tests/vulpix-tests/unit/timeout.scala", defaultOptions).checkRuns()
compileFile(fileName, defaultOptions).checkRuns()
fail()
} catch {
case ae: AssertionError =>
assertEquals("Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test 'tests/vulpix-tests/unit/timeout.scala' timed out",
assertEquals(s"Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test '${fileName}' timed out",
ae.getMessage)
}
}
Expand Down
4 changes: 2 additions & 2 deletions doc-tool/test/dotty/tools/dottydoc/staticsite/SiteTests.scala
Expand Up @@ -78,8 +78,8 @@ class SiteTests extends DottyDocTest with SourceFileOps with CheckFromSource {
}

@Test def siteStructure = {
val assets = site.staticAssets.map(site.stripRoot(_)).toSet
val compd = site.compilableFiles.map(site.stripRoot(_)).toSet
val assets = site.staticAssets.map(site.stripRoot(_).replace('\\','/')).toSet
val compd = site.compilableFiles.map(site.stripRoot(_).replace('\\','/')).toSet

val expectedAssets = Set(
"css/toolbar.css",
Expand Down
31 changes: 17 additions & 14 deletions tests/idempotency/IdempotencyCheck.scala
@@ -1,4 +1,5 @@

import java.io.{File => JFile}
import java.nio.file.{ Files => JFiles, Path => JPath, Paths => JPaths }
import java.util.stream.{ Stream => JStream }

Expand All @@ -7,15 +8,19 @@ import scala.collection.JavaConverters._
object IdempotencyCheck {
val blacklisted = Set(
// No fix needed. Bridges on collections in different order. Second one in scala2 order.
"pos/Map/scala/collection/immutable/Map",
"pos/Map/scala/collection/immutable/AbstractMap",
"pos/t1203a/NodeSeq",
"pos/i2345/Whatever"
s"pos{JFile.separator}Map{JFile.separator}scala{JFile.separator}collection{JFile.separator}immutable/Map",
s"pos{JFile.separator}Map{JFile.separator}scala{JFile.separator}collection{JFile.separator}immutable{JFile.separator}AbstractMap",
s"pos{JFile.separator}t1203a/NodeSeq",
s"pos{JFile.separator}i2345{JFile.separator}Whatever"
)

def checkIdempotency(dir1: String, dir2: String): Unit = {
var failed = 0
var total = 0
val dir1Path = JPaths.get(dir1)
val dir2Path = JPaths.get(dir2)
val dir1String = dir1Path.toString
val dir2String= dir2Path.toString

val groupedBytecodeFiles: List[(JPath, JPath, JPath, JPath)] = {
val bytecodeFiles = {
Expand All @@ -24,21 +29,19 @@ object IdempotencyCheck {
def tupleWithName(f: JPath) = (f.toString.substring(dir.length + 1, f.toString.length - 6), f)
paths.iterator.asScala.filter(path => isBytecode(path.toString)).map(tupleWithName).toList
}
val compilerDir1 = JPaths.get(dir1)
val compilerDir2 = JPaths.get(dir2)
bytecodeFiles(JFiles.walk(compilerDir1), dir1) ++ bytecodeFiles(JFiles.walk(compilerDir2), dir2)
bytecodeFiles(JFiles.walk(dir1Path), dir1String) ++ bytecodeFiles(JFiles.walk(dir2Path), dir2String)
}
val groups = bytecodeFiles.groupBy(_._1).mapValues(_.map(_._2))

groups.filterNot(x => blacklisted(x._1)).valuesIterator.flatMap { g =>
groups.filterNot(x => blacklisted(x._1)).iterator.flatMap { g =>
def pred(f: JPath, dir: String, isTasty: Boolean) =
f.toString.contains(dir) && f.toString.endsWith(if (isTasty) ".tasty" else ".class")
val class1 = g.find(f => pred(f, dir1, isTasty = false))
val class2 = g.find(f => pred(f, dir2, isTasty = false))
val tasty1 = g.find(f => pred(f, dir1, isTasty = true))
val tasty2 = g.find(f => pred(f, dir2, isTasty = true))
assert(class1.isDefined, s"Could not find class in ${dir1} for $class2")
assert(class2.isDefined, s"Could not find class in ${dir2} for $class1")
val class1 = g._2.find(f => pred(f, dir1String, isTasty = false))
val class2 = g._2.find(f => pred(f, dir2String, isTasty = false))
val tasty1 = g._2.find(f => pred(f, dir1String, isTasty = true))
val tasty2 = g._2.find(f => pred(f, dir2String, isTasty = true))
assert(class1.isDefined, s"Could not find class in ${dir1} for ${g._1}")
assert(class2.isDefined, s"Could not find class in ${dir2} for ${g._1}")
if (tasty1.isEmpty || tasty2.isEmpty) Nil
else List(Tuple4(class1.get, tasty1.get, class2.get, tasty2.get))
}.toList
Expand Down