mirror of https://github.com/sbt/sbt.git
Add test for trait as a first parent scenario in dep tracking.
The documentation of `Relations.inheritance` mentions an oddity of Scala's type checker which manifests itself in what is being tracked by that relation in case of traits being first parent for a class/trait. Add a test case which verifies that this oddity actually exists and it's not harmful because it doesn't break an invariant between `memberRef` and `inheritance` relations.
This commit is contained in:
parent
2226fccd4f
commit
331fffbb19
|
|
@ -47,6 +47,24 @@ class DependencySpecification extends Specification {
|
|||
inheritance('D) === Set('B)
|
||||
}
|
||||
|
||||
"Extracted source dependencies with trait as first parent" in {
|
||||
val sourceDependencies = extractSourceDependenciesTraitAsFirstPatent
|
||||
val memberRef = sourceDependencies.memberRef
|
||||
val inheritance = sourceDependencies.inheritance
|
||||
memberRef('A) === Set.empty
|
||||
inheritance('A) === Set.empty
|
||||
memberRef('B) === Set('A)
|
||||
inheritance('B) === Set('A)
|
||||
// verify that memberRef captures the oddity described in documentation of `Relations.inheritance`
|
||||
// we are mainly interested whether dependency on A is captured in `memberRef` relation so
|
||||
// the invariant that says that memberRef is superset of inheritance relation is preserved
|
||||
memberRef('C) === Set('A, 'B)
|
||||
inheritance('C) === Set('A, 'B)
|
||||
// same as above but indirect (C -> B -> A), note that only A is visible here
|
||||
memberRef('D) === Set('A, 'C)
|
||||
inheritance('D) === Set('A, 'C)
|
||||
}
|
||||
|
||||
private def extractSourceDependenciesPublic: ExtractedSourceDependencies = {
|
||||
val srcA = "class A"
|
||||
val srcB = "class B extends D[A]"
|
||||
|
|
@ -79,4 +97,16 @@ class DependencySpecification extends Specification {
|
|||
compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC, 'D -> srcD)
|
||||
sourceDependencies
|
||||
}
|
||||
|
||||
private def extractSourceDependenciesTraitAsFirstPatent: ExtractedSourceDependencies = {
|
||||
val srcA = "class A"
|
||||
val srcB = "trait B extends A"
|
||||
val srcC = "trait C extends B"
|
||||
val srcD = "class D extends C"
|
||||
|
||||
val compilerForTesting = new ScalaCompilerForUnitTesting(memberRefAndInheritanceDeps = true)
|
||||
val sourceDependencies =
|
||||
compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC, 'D -> srcD)
|
||||
sourceDependencies
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue