Skip to content

Commit a1e01bb

Browse files
bishaboshaWojciechMazur
authored andcommitted
add test to assert classes are still reported
1 parent acbbd42 commit a1e01bb

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

Diff for: sbt-bridge/test/xsbt/ProductsSpecification.scala

+29-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,39 @@ class ProductsSpecification {
2323
val output = compiler.compileSrcsToJar(src)
2424
val srcFile = output.srcFiles.head
2525
val products = output.analysis.productClassesToSources.filter(_._2 == srcFile).keys.toSet
26-
26+
2727
def toPathInJar(className: String): Path =
2828
Paths.get(s"${output.classesOutput}!${className.replace('.', File.separatorChar)}.class")
2929
val expected = Set("example.A", "example.A$B", "example.A$C$1").map(toPathInJar)
3030
assertEquals(products, expected)
3131
}
3232

33+
@Test
34+
def extractNonLocalClassesNoInc = {
35+
val src =
36+
"""package example
37+
|
38+
|class A {
39+
| class B
40+
| def foo =
41+
| class C
42+
|}""".stripMargin
43+
val output = compiler.compileSrcsNoInc(src)
44+
val srcFile = output.srcFiles.head
45+
val (srcNames, binaryNames) = output.analysis.classNames(srcFile).unzip // non local class names
46+
47+
assertFalse(output.analysis.enabled()) // inc phases are disabled
48+
assertTrue(output.analysis.apis.isEmpty) // extract-api did not run
49+
assertTrue(output.analysis.usedNamesAndScopes.isEmpty) // extract-dependencies did not run
50+
51+
// note that local class C is not included, classNames only records non local classes
52+
val expectedBinary = Set("example.A", "example.A$B")
53+
assertEquals(expectedBinary, binaryNames.toSet)
54+
55+
// note that local class C is not included, classNames only records non local classes
56+
val expectedSrc = Set("example.A", "example.A.B")
57+
assertEquals(expectedSrc, srcNames.toSet)
58+
}
59+
3360
private def compiler = new ScalaCompilerForUnitTesting
34-
}
61+
}

Diff for: sbt-bridge/test/xsbt/ScalaCompilerForUnitTesting.scala

+12-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ class ScalaCompilerForUnitTesting {
135135
* The sequence of temporary files corresponding to passed snippets and analysis
136136
* callback is returned as a result.
137137
*/
138-
def compileSrcs(groupedSrcs: List[List[String]], sourcePath: List[String] = Nil, compileToJar: Boolean = false): CompileOutput = {
138+
def compileSrcs(groupedSrcs: List[List[String]], sourcePath: List[String] = Nil, compileToJar: Boolean = false, incEnabled: Boolean = true): CompileOutput = {
139139
val temp = IO.createTemporaryDirectory
140-
val analysisCallback = new TestCallback
140+
val (forceSbtArgs, analysisCallback) =
141+
if (incEnabled)
142+
(Seq("-Yforce-sbt-phases"), new TestCallback)
143+
else
144+
(Seq.empty, new TestCallbackNoInc)
141145
val testProgress = new TestCompileProgress
142-
val classesOutput =
146+
val classesOutput =
143147
if (compileToJar) {
144148
val jar = new File(temp, "classes.jar")
145149
jar.createNewFile()
@@ -174,7 +178,7 @@ class ScalaCompilerForUnitTesting {
174178
bridge.run(
175179
virtualSrcFiles,
176180
new TestDependencyChanges,
177-
Array("-Yforce-sbt-phases", "-classpath", classesOutputPath, "-usejavacp", "-d", classesOutputPath) ++ maybeSourcePath,
181+
(forceSbtArgs ++: Array("-classpath", classesOutputPath, "-usejavacp", "-d", classesOutputPath)) ++ maybeSourcePath,
178182
output,
179183
analysisCallback,
180184
new TestReporter,
@@ -193,6 +197,10 @@ class ScalaCompilerForUnitTesting {
193197
compileSrcs(List(srcs.toList))
194198
}
195199

200+
def compileSrcsNoInc(srcs: String*): CompileOutput = {
201+
compileSrcs(List(srcs.toList), incEnabled = false)
202+
}
203+
196204
def compileSrcsToJar(srcs: String*): CompileOutput =
197205
compileSrcs(List(srcs.toList), compileToJar = true)
198206

@@ -202,4 +210,3 @@ class ScalaCompilerForUnitTesting {
202210
new TestVirtualFile(srcFile.toPath)
203211
}
204212
}
205-

Diff for: sbt-bridge/test/xsbti/TestCallback.scala

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import DependencyContext._
1111
import java.{util => ju}
1212
import ju.Optional
1313

14+
class TestCallbackNoInc extends TestCallback {
15+
override def enabled(): Boolean = false
16+
}
17+
1418
class TestCallback extends AnalysisCallback2 {
1519
case class TestUsedName(name: String, scopes: ju.EnumSet[UseScope])
1620

0 commit comments

Comments
 (0)