Skip to content

Commit 5edd2dc

Browse files
authored
Merge pull request #540 from dwijnand/pre-tweaks
Tweaks in prep for the mixin static forwarders fix
2 parents c493b92 + 2b96d1a commit 5edd2dc

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ val functionalTests = Project("functional-tests", file("functional-tests"))
7373
testFrameworks += new TestFramework("munit.Framework"),
7474
//Test / run / fork := true,
7575
//Test / run / forkOptions := (Test / run / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
76+
// Test / testOnly / watchTriggers += baseDirectory.value.toGlob / "src" / "test" / **,
77+
// ^ disabled b/c of "Build triggered by [..]/target/scala-2.12/v2-classes."
7678
testFunctional := (Test / test).value,
7779
Defaults.itSettings,
7880
mimaFailOnNoPrevious := false,

core/src/main/scala/com/typesafe/tools/mima/core/ClassInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private[mima] sealed abstract class ClassInfo(val owner: PackageInfo) extends In
169169
else superClass.allInterfaces ++ interfaces ++ interfaces.flatMap(_.allInterfaces)
170170
}
171171

172-
/** Does this implementation class have a static implementation of given method `m`? */
172+
/** Does this class's impl class have a static implementation of the given method `m`? */
173173
final def hasStaticImpl(m: MethodInfo): Boolean = {
174174
implClass match {
175175
case _: SyntheticClassInfo => false

functional-tests/src/main/scala/com/typesafe/tools/mima/lib/AppRunTest.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package com.typesafe.tools.mima.lib
22

3-
import com.typesafe.tools.mima.lib.UnitTests._
4-
5-
import scala.util.{ Failure, Success }
3+
import scala.util.{ Failure, Success, Try }
64

75
/** Test running the App, using library v2. */
86
object AppRunTest {
97
def main(args: Array[String]): Unit = TestCli.argsToTests(args.toList, testAppRun).unsafeRunTest()
108

11-
def testAppRun(testCase: TestCase) = for {
9+
def testAppRun(testCase: TestCase): Try[Unit] = for {
1210
() <- testCase.compileThem
1311
pending = testCase.versionedFile("testAppRun.pending").exists
14-
emptyPT = blankFile(testCase.versionedFile("problems.txt"))
12+
emptyPT = testCase.blankFile(testCase.versionedFile("problems.txt"))
1513
() <- testCase.runMain(testCase.outV1) // expect at least v1 to pass, even in the "pending" case
1614
() <- testCase.runMain(testCase.outV2) match {
1715
case Failure(t) if !pending && emptyPT => Failure(t)

functional-tests/src/main/scala/com/typesafe/tools/mima/lib/CollectProblemsTest.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.util.{ Failure, Success, Try }
1111
object CollectProblemsTest {
1212
def main(args: Array[String]): Unit = TestCli.argsToTests(args.toList, testCollectProblems).unsafeRunTest()
1313

14-
def testCollectProblems(testCase: TestCase) = for {
14+
def testCollectProblems(testCase: TestCase): Try[Unit] = for {
1515
() <- testCase.compileThem
1616
problems = collectProblems(testCase.outV1.jfile, testCase.outV2.jfile)
1717
expected = readOracleFile(testCase.versionedFile("problems.txt").jfile)
@@ -26,26 +26,26 @@ object CollectProblemsTest {
2626
Files.lines(oracleFile.toPath).iterator.asScala.filter(!_.startsWith("#")).toList
2727
}
2828

29-
def diffProblems(problems: List[Problem], expected: List[String]): Try[Unit] = {
29+
def diffProblems(problems: List[Problem], expected: List[String], v: String = "new"): Try[Unit] = {
3030
// diff between the oracle and the collected problems
31-
val unexpected = problems.filter(p => !expected.contains(p.description("new")))
32-
val unreported = expected.diff(problems.map(_.description("new")))
31+
val unexpected = problems.filter(p => !expected.contains(p.description(v)))
32+
val unreported = expected.diff(problems.map(_.description(v)))
3333

34-
val msg = new StringBuilder
34+
val msg = new StringBuilder("\n")
3535
def pp(start: String, lines: List[String]) = {
3636
if (lines.isEmpty) ()
3737
else lines.sorted.distinct.addString(msg, s"$start (${lines.size}):\n - ", "\n - ", "\n")
3838
}
3939
pp("The following problem(s) were expected but not reported", unreported)
40-
pp("The following problem(s) were reported but not expected", unexpected.map(_.description("new")))
40+
pp("The following problem(s) were reported but not expected", unexpected.map(_.description(v)))
4141
pp("Filter with:", unexpected.flatMap(_.howToFilter))
4242
pp("Or filter with:", unexpected.flatMap(p => p.matchName.map { matchName =>
4343
s"{ matchName=$dq$matchName$dq , problemName=${p.getClass.getSimpleName} }"
4444
}))
4545

4646
msg.mkString match {
47-
case "" => Success(())
48-
case msg => Failure(new Exception(msg))
47+
case "\n" => Success(())
48+
case msg => Failure(new Exception(msg))
4949
}
5050
}
5151

functional-tests/src/main/scala/com/typesafe/tools/mima/lib/TestCase.scala

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.typesafe.tools.mima.lib
22

3-
import java.io.{ ByteArrayOutputStream, PrintStream }
3+
import java.io.{ ByteArrayOutputStream, File, PrintStream }
44
import java.net.{ URI, URLClassLoader }
55
import javax.tools._
66

77
import scala.collection.JavaConverters._
88
import scala.collection.mutable
9-
import scala.reflect.internal.util.{ BatchSourceFile, SourceFile }
9+
import scala.reflect.internal.util.BatchSourceFile
1010
import scala.reflect.io.{ Directory, Path, PlainFile }
1111
import scala.util.{ Failure, Success, Try }
1212

@@ -25,32 +25,36 @@ final class TestCase(val baseDir: Directory, val scalaCompiler: ScalaCompiler, v
2525
val outApp = (baseDir / s"target/scala-$scalaBinaryVersion/app-classes").toDirectory
2626

2727
lazy val compileThem: Try[Unit] = for {
28-
() <- Try(List(outV1, outV2, outApp).foreach(recreateDir(_)))
29-
() <- compileDir(srcV1, outV1)
30-
() <- compileDir(srcApp, outApp)
31-
() <- compileDir(srcV2, outV2) // run after App, to make sure App links to v1
28+
() <- compileV1()
29+
() <- compileV2()
30+
() <- compileApp(outV1)
3231
} yield ()
3332

34-
def compileDir(srcDir: Directory, out: Directory): Try[Unit] = {
35-
val sourceFiles = srcDir.files.map(f => new BatchSourceFile(new PlainFile(f))).toList
36-
for {
37-
() <- compileScala(sourceFiles, out)
38-
() <- compileJava(sourceFiles.filter(_.isJava), out)
39-
} yield ()
40-
}
33+
def compileV1() = compileDir(srcV1, Nil, outV1)
34+
def compileV2() = compileDir(srcV2, Nil, outV2)
35+
def compileApp(outLib: Directory) = compileDir(srcApp, List(outLib), outApp)
36+
37+
def compileDir(srcDir: Directory, cp: List[Directory], out: Directory): Try[Unit] = for {
38+
() <- Try(recreateDir(out))
39+
() <- compileScala(srcDir, cp, out)
40+
() <- compileJava(srcDir, cp, out)
41+
} yield ()
4142

42-
def compileScala(sourceFiles: List[SourceFile], out: Directory): Try[Unit] = {
43+
def compileScala(srcDir: Directory, cp: List[Directory], out: Directory): Try[Unit] = {
44+
val sourceFiles = lsSrcs(srcDir)
4345
if (sourceFiles.forall(_.isJava)) return Success(())
4446
val bootcp = ClassPath.join(scalaJars.map(_.getPath))
47+
val cpOpt = if (cp.isEmpty) Nil else List("-cp", ClassPath.join(cp.map(_.path)))
4548
val paths = sourceFiles.map(_.path)
46-
val args = "-bootclasspath" :: bootcp :: "-classpath" :: s"$outV1" :: "-d" :: s"$out" :: paths
49+
val args = "-bootclasspath" :: bootcp :: cpOpt ::: "-d" :: s"$out" :: paths
4750
scalaCompiler.compile(args)
4851
}
4952

50-
def compileJava(sourceFiles: List[SourceFile], out: Directory): Try[Unit] = {
53+
def compileJava(srcDir: Directory, cp: List[Directory], out: Directory): Try[Unit] = {
54+
val sourceFiles = lsSrcs(srcDir, _.hasExtension("java"))
5155
if (sourceFiles.isEmpty) return Success(())
52-
val cp = ClassPath.join((scalaJars :+ outV1.jfile).map(_.getPath))
53-
val opts = List("-classpath", cp, "-d", s"$out").asJava
56+
val cpStr = ClassPath.join((scalaJars ++ cp.map(_.jfile)).map(_.getPath))
57+
val opts = List("-classpath", cpStr, "-d", s"$out").asJava
5458
val units = sourceFiles.map { sf =>
5559
new SimpleJavaFileObject(new URI(s"string:///${sf.path}"), JavaFileObject.Kind.SOURCE) {
5660
override def getCharContent(ignoreEncodingErrors: Boolean) = sf.content
@@ -86,6 +90,12 @@ final class TestCase(val baseDir: Directory, val scalaCompiler: ScalaCompiler, v
8690
}
8791
}
8892

93+
def lsSrcs(dir: Directory, cond: Path => Boolean = _.hasExtension("scala", "java")) = {
94+
dir.walkFilter(cond).map(f => new BatchSourceFile(new PlainFile(f))).toList.sortBy(_.path)
95+
}
96+
97+
def blankFile(p: Path): Boolean = p.toFile.lines().forall(_.startsWith("#"))
98+
8999
def versionedFile(path: Path) = {
90100
val p = baseDir.resolve(path).toFile
91101
val p211 = (p.parent / (s"${p.stripExtension}-2.11")).addExtension(p.extension).toFile
@@ -97,10 +107,11 @@ final class TestCase(val baseDir: Directory, val scalaCompiler: ScalaCompiler, v
97107
}
98108
}
99109

100-
def recreateDir(dir: Directory) = {
110+
def recreateDir(dir: Directory): Unit = {
101111
if (dir.exists)
102112
assert(dir.deleteRecursively(), s"failed to delete $dir")
103113
dir.createDirectory()
114+
()
104115
}
105116

106117
override def toString = s"TestCase(baseDir=${baseDir.name}, scalaVersion=${scalaCompiler.version})"

functional-tests/src/main/scala/com/typesafe/tools/mima/lib/TestCli.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ object TestCli {
1515
val allScalaVersions = List(scala211, scala212, scala213)
1616
val testsDir = Directory("functional-tests/src/test")
1717

18-
def argsToTests(argv: List[String], runTestCase: TestCase => Try[Unit]): Tests =
19-
Tests(fromArgs(argv).map(testCaseToTest1(_, runTestCase)))
18+
def argsToTests(args: List[String], runTestCase: TestCase => Try[Unit]): Tests =
19+
Tests(fromArgs(args).map(testCaseToTest1(_, runTestCase)))
2020

2121
def testCaseToTest1(tc: TestCase, runTestCase: TestCase => Try[Unit]): Test1 =
2222
Test(s"${tc.scalaBinaryVersion} / ${tc.name}", runTestCase(tc))
2323

24-
def fromArgs(argv: List[String]): List[TestCase] = fromConf(go(argv, Conf(Nil, Nil)))
24+
def fromArgs(args: List[String]): List[TestCase] = fromConf(go(args, Conf(Nil, Nil)))
2525

2626
@tailrec def postProcessConf(conf: Conf): Conf = conf match {
2727
case Conf(Nil, _) => postProcessConf(conf.copy(scalaVersions = List(hostScalaVersion)))
@@ -31,13 +31,15 @@ object TestCli {
3131

3232
def fromConf(conf: Conf): List[TestCase] = {
3333
val conf1 = postProcessConf(conf)
34-
val javaCompiler = ToolProvider.getSystemJavaCompiler
34+
val javaCompiler = getJavaCompiler
3535
for {
3636
sc <- conf1.scalaVersions.map(new ScalaCompiler(_))
3737
dir <- conf1.dirs
3838
} yield new TestCase(dir, sc, javaCompiler)
3939
}
4040

41+
def getJavaCompiler = ToolProvider.getSystemJavaCompiler
42+
4143
def allTestDirs() = testsDir.dirs.filter(_.files.exists(_.name == "problems.txt")).toList.sortBy(_.path)
4244

4345
final case class Conf(scalaVersions: List[String], dirs: List[Directory])

functional-tests/src/main/scala/com/typesafe/tools/mima/lib/UnitTests.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.typesafe.tools.mima.lib
22

3-
import scala.reflect.io.Path
43
import scala.util.{ Failure, Success, Try }
54

65
import munit.GenericTest
@@ -16,13 +15,11 @@ object UnitTests {
1615
} yield ()
1716

1817
def testNameCheck(testCase: TestCase): Try[Unit] = {
19-
val emptyProblemsTxt = blankFile(testCase.baseDir / "problems.txt")
18+
val emptyProblemsTxt = testCase.blankFile(testCase.baseDir / "problems.txt")
2019
testCase.baseDir.name.takeRight(4).dropWhile(_ != '-') match {
2120
case "-ok" => if (emptyProblemsTxt) Success(()) else Failure(new Exception("OK test with non-empty problems.txt"))
2221
case "-nok" => if (emptyProblemsTxt) Failure(new Exception("NOK test with empty problems.txt")) else Success(())
2322
case _ => Failure(new Exception("Missing '-ok' or '-nok' suffix in project name"))
2423
}
2524
}
26-
27-
def blankFile(p: Path): Boolean = p.toFile.lines().forall(_.startsWith("#"))
2825
}

0 commit comments

Comments
 (0)