mirror of https://github.com/sbt/sbt.git
test cases for Java inherited dependency extraction
This commit is contained in:
parent
626038bece
commit
7088a7dd5a
|
|
@ -20,8 +20,9 @@ object ClassToAPI
|
|||
val defs = c.filter(isTopLevel).flatMap(toDefinitions(cmap))
|
||||
val source = new api.SourceAPI(pkgs.toArray, defs.toArray)
|
||||
cmap.lz.foreach(_.get()) // force thunks to ensure all inherited dependencies are recorded
|
||||
val inDeps = cmap.inherited.toSet
|
||||
cmap.clear()
|
||||
(source, cmap.inherited.toSet)
|
||||
(source, inDeps)
|
||||
}
|
||||
|
||||
// Avoiding implicit allocation.
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
class A implements B.T<Integer>, E {}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
public class B {
|
||||
static interface T<X> extends C {}
|
||||
|
||||
// not public, so this shouldn't be tracked as an inherited dependency
|
||||
private class Q implements E<Integer> {}
|
||||
|
||||
public void x(int i) {
|
||||
// not public, not an inherited dependency
|
||||
D j = new D() {};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
interface C extends D {}
|
||||
|
|
@ -0,0 +1 @@
|
|||
interface D extends G.P {}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public interface E<T> {}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class F {
|
||||
public C q() { return null; }
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class G {
|
||||
static interface P extends J {}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public interface J {}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
lazy val verifyDeps = taskKey[Unit]("verify inherited dependencies are properly extracted")
|
||||
|
||||
verifyDeps := {
|
||||
val a = compile.in(Compile).value
|
||||
same(a.relations.publicInherited.internal.forwardMap, expectedDeps.forwardMap)
|
||||
}
|
||||
|
||||
lazy val expected = Seq(
|
||||
"A" -> Seq("C", "D", "E", "G", "J"),
|
||||
"B" -> Seq("C", "D", "G", "J"),
|
||||
"C" -> Seq("D", "G", "J"),
|
||||
"D" -> Seq("G", "J"),
|
||||
"E" -> Seq(),
|
||||
"F" -> Seq(),
|
||||
"G" -> Seq("J"),
|
||||
"J" -> Seq()
|
||||
)
|
||||
lazy val pairs =
|
||||
expected.map { case (from,tos) =>
|
||||
(toFile(from), tos.map(toFile))
|
||||
}
|
||||
lazy val expectedDeps = (Relation.empty[File,File] /: pairs) { case (r, (x,ys)) => r + (x,ys) }
|
||||
def toFile(s: String) = file(s + ".java").getAbsoluteFile
|
||||
|
||||
def same[T](x: T, y: T) {
|
||||
assert(x == y, s"\nActual: $x, \nExpected: $y")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
> verifyDeps
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class A {
|
||||
public Integer x() { return 3; }
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public class B extends A {}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public class C extends B {}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
public class D {
|
||||
public static final C c = new C();
|
||||
public static String x() { return c.x().toString(); }
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
public class E {
|
||||
public static void main(String[] args) {
|
||||
assert(D.x() == "3");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import complete.DefaultParsers._
|
||||
|
||||
val checkIterations = inputKey[Unit]("Verifies the accumlated number of iterations of incremental compilation.")
|
||||
|
||||
checkIterations := {
|
||||
val expected: Int = (Space ~> NatBasic).parsed
|
||||
val actual: Int = (compile in Compile).value.compilations.allCompilations.size
|
||||
assert(expected == actual, s"Expected $expected compilations, got $actual")
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class A {
|
||||
public String x() { return "3"; }
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# 1 iteration from initial full compile
|
||||
> run
|
||||
$ copy-file changes/A2.java A.java
|
||||
|
||||
# 1 iteration for the initial changes
|
||||
# 1 iteration to recompile all descendents and direct dependencies
|
||||
# no further iteration, because APIs of directs don't change
|
||||
> run
|
||||
> checkIterations 3
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class A {
|
||||
public int x() { return 5; }
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public class B extends A {}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
public class C extends B
|
||||
{
|
||||
public int x() { return super.x() + 3; }
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public class A {}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
> compile
|
||||
|
||||
$ copy-file changes/A2.java A.java
|
||||
-> compile
|
||||
Loading…
Reference in New Issue