Skip to content

Commit 8cc445b

Browse files
Merge pull request #5130 from melekhove/issue/5129
Fix #5129: Use system-dependent path separator
2 parents 8a9770b + f7946bb commit 8cc445b

File tree

7 files changed

+61
-49
lines changed

7 files changed

+61
-49
lines changed

compiler/test/dotty/tools/dotc/FromTastyTests.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package dotc
55
import org.junit.{AfterClass, Test}
66
import vulpix._
77

8+
import java.io.{File => JFile}
9+
810
import scala.concurrent.duration._
911

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

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

4244
implicit val testGroup: TestGroup = TestGroup("runTestFromTasty")
43-
compileTastyInDir("tests/run", defaultOptions,
45+
compileTastyInDir(s"tests${JFile.separator}run", defaultOptions,
4446
fromTastyFilter = FileFilter.exclude(TestSources.runFromTastyBlacklisted),
4547
decompilationFilter = FileFilter.exclude(TestSources.runDecompilationBlacklisted),
4648
recompilationFilter = FileFilter.include(TestSources.runRecompilationWhitelist)

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
5454
def outDir: JFile
5555
def flags: TestFlags
5656

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

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

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

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

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

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

433434
val reporter =
@@ -531,17 +532,19 @@ trait ParallelTesting extends RunnerOrchestration { self =>
531532
}.headOption
532533
checkFileOpt match {
533534
case Some(checkFile) =>
535+
val ignoredFilePathLine = "/** Decompiled from"
534536
val stripTrailingWhitespaces = "(.*\\S|)\\s+".r
535-
val output = Source.fromFile(outDir.getParent + "_decompiled/" + outDir.getName + "/decompiled.scala").getLines().map {line =>
537+
val output = Source.fromFile(outDir.getParent + "_decompiled" + JFile.separator + outDir.getName
538+
+ JFile.separator + "decompiled.scala").getLines().map {line =>
536539
stripTrailingWhitespaces.unapplySeq(line).map(_.head).getOrElse(line)
537-
}.mkString("\n")
538-
539-
val check: String = Source.fromFile(checkFile).getLines().mkString("\n")
540+
}
540541

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

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

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

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

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

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

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

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

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

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

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

12931296
override def buildInstructions(errors: Int, warnings: Int): String = {
1294-
val runOrPos = if (file.getPath.startsWith("tests/run/")) "run" else "pos"
1297+
val runOrPos = if (file.getPath.startsWith(s"tests${JFile.separator}run${JFile.separator}")) "run" else "pos"
12951298
val listName = if (fromTasty) "from-tasty" else "decompilation"
12961299
s"""|
12971300
|Test '$title' compiled with $errors error(s) and $warnings warning(s),
12981301
|the test can be reproduced by running:
12991302
|
13001303
| sbt "testFromTasty $file"
13011304
|
1302-
|This tests can be disabled by adding `${file.getName}` to `compiler/test/dotc/$runOrPos-$listName.blacklist`
1305+
|This tests can be disabled by adding `${file.getName}` to `compiler${JFile.separator}test${JFile.separator}dotc${JFile.separator}$runOrPos-$listName.blacklist`
13031306
|
13041307
|""".stripMargin
13051308
}
@@ -1378,7 +1381,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
13781381
* tests.
13791382
*/
13801383
def compileShallowFilesInDir(f: String, flags: TestFlags)(implicit testGroup: TestGroup): CompilationTest = {
1381-
val outDir = defaultOutputDir + testGroup + "/"
1384+
val outDir = defaultOutputDir + testGroup + JFile.separator
13821385
val sourceDir = new JFile(f)
13831386
checkRequirements(f, sourceDir, outDir)
13841387

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

13961399
object ParallelTesting {
13971400

1398-
def defaultOutputDir: String = "out/"
1401+
def defaultOutputDir: String = "out"+JFile.separator
13991402

14001403
def isSourceFile(f: JFile): Boolean = {
14011404
val name = f.getName

compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ trait RunnerOrchestration {
156156
* scala library.
157157
*/
158158
private def createProcess: Process = {
159-
val sep = sys.props("file.separator")
159+
val sep = JFile.separator
160160
val cp =
161-
classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation.getFile + ":" +
161+
classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation.getFile + JFile.pathSeparator +
162162
Properties.scalaLibrary
163163
val javaBin = sys.props("java.home") + sep + "bin" + sep + "java"
164164
new ProcessBuilder(javaBin, "-Xmx1g", "-cp", cp, "dotty.tools.vulpix.ChildJVMMain")

compiler/test/dotty/tools/vulpix/TestFlags.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dotty.tools.vulpix
22

3+
import java.io.{File => JFile}
4+
35
final case class TestFlags(
46
defaultClassPath: String,
57
runClassPath: String, // class path that is used when running `run` tests (not compiling)
@@ -12,10 +14,10 @@ final case class TestFlags(
1214
TestFlags(defaultClassPath, runClassPath, options diff flags)
1315

1416
def withClasspath(classPath: String): TestFlags =
15-
TestFlags(s"$defaultClassPath:$classPath", runClassPath, options)
17+
TestFlags(s"$defaultClassPath${JFile.pathSeparator}$classPath", runClassPath, options)
1618

1719
def withRunClasspath(classPath: String): TestFlags =
18-
TestFlags(defaultClassPath, s"$runClassPath:$classPath", options)
20+
TestFlags(defaultClassPath, s"$runClassPath${JFile.pathSeparator}$classPath", options)
1921

2022
def all: Array[String] = Array("-classpath", defaultClassPath) ++ options
2123
}

compiler/test/dotty/tools/vulpix/VulpixUnitTests.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools
22
package vulpix
33

4+
import java.io.{File => JFile}
45
import org.junit.Assert._
56
import org.junit.Test
67

@@ -86,12 +87,13 @@ class VulpixUnitTests extends ParallelTesting {
8687
}
8788

8889
@Test def runTimeout: Unit = {
90+
val fileName = s"tests${JFile.separatorChar}vulpix-tests${JFile.separatorChar}unit${JFile.separatorChar}timeout.scala"
8991
try {
90-
compileFile("tests/vulpix-tests/unit/timeout.scala", defaultOptions).checkRuns()
92+
compileFile(fileName, defaultOptions).checkRuns()
9193
fail()
9294
} catch {
9395
case ae: AssertionError =>
94-
assertEquals("Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test 'tests/vulpix-tests/unit/timeout.scala' timed out",
96+
assertEquals(s"Run test failed, but should not, reasons:\n\n - encountered 1 test failures(s) - test '${fileName}' timed out",
9597
ae.getMessage)
9698
}
9799
}

doc-tool/test/dotty/tools/dottydoc/staticsite/SiteTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class SiteTests extends DottyDocTest with SourceFileOps with CheckFromSource {
7878
}
7979

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

8484
val expectedAssets = Set(
8585
"css/toolbar.css",

tests/idempotency/IdempotencyCheck.scala

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

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

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

1617
def checkIdempotency(dir1: String, dir2: String): Unit = {
1718
var failed = 0
1819
var total = 0
20+
val dir1Path = JPaths.get(dir1)
21+
val dir2Path = JPaths.get(dir2)
22+
val dir1String = dir1Path.toString
23+
val dir2String= dir2Path.toString
1924

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

33-
groups.filterNot(x => blacklisted(x._1)).valuesIterator.flatMap { g =>
36+
groups.filterNot(x => blacklisted(x._1)).iterator.flatMap { g =>
3437
def pred(f: JPath, dir: String, isTasty: Boolean) =
3538
f.toString.contains(dir) && f.toString.endsWith(if (isTasty) ".tasty" else ".class")
36-
val class1 = g.find(f => pred(f, dir1, isTasty = false))
37-
val class2 = g.find(f => pred(f, dir2, isTasty = false))
38-
val tasty1 = g.find(f => pred(f, dir1, isTasty = true))
39-
val tasty2 = g.find(f => pred(f, dir2, isTasty = true))
40-
assert(class1.isDefined, s"Could not find class in ${dir1} for $class2")
41-
assert(class2.isDefined, s"Could not find class in ${dir2} for $class1")
39+
val class1 = g._2.find(f => pred(f, dir1String, isTasty = false))
40+
val class2 = g._2.find(f => pred(f, dir2String, isTasty = false))
41+
val tasty1 = g._2.find(f => pred(f, dir1String, isTasty = true))
42+
val tasty2 = g._2.find(f => pred(f, dir2String, isTasty = true))
43+
assert(class1.isDefined, s"Could not find class in ${dir1} for ${g._1}")
44+
assert(class2.isDefined, s"Could not find class in ${dir2} for ${g._1}")
4245
if (tasty1.isEmpty || tasty2.isEmpty) Nil
4346
else List(Tuple4(class1.get, tasty1.get, class2.get, tasty2.get))
4447
}.toList

0 commit comments

Comments
 (0)