Skip to content

Commit

Permalink
Add test for trait as a first parent scenario in dep tracking.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gkossakowski authored and eed3si9n committed Mar 21, 2014
1 parent 110a1e2 commit 454fc91
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -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
}
}

0 comments on commit 454fc91

Please sign in to comment.