Skip to content

Commit

Permalink
Reorder arguments in assertEquals according to the spec:
Browse files Browse the repository at this point in the history
asserEquals(expected, found)
  • Loading branch information
allanrenucci committed Mar 29, 2018
1 parent e78a3fb commit 5c4dead
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 82 deletions.
101 changes: 50 additions & 51 deletions sbt-bridge/test/xsbt/DependencySpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ class DependencySpecification {
val classDependencies = extractClassDependenciesPublic
val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
assertEquals(memberRef("A"), Set.empty)
assertEquals(inheritance("A"), Set.empty)
assertEquals(memberRef("B"), Set("A", "D"))
assertEquals(inheritance("B"), Set("D"))
assertEquals(memberRef("C"), Set("A"))
assertEquals(inheritance("C"), Set.empty)
assertEquals(memberRef("D"), Set.empty)
assertEquals(inheritance("D"), Set.empty)
assertEquals(memberRef("E"), Set.empty)
assertEquals(inheritance("E"), Set.empty)
assertEquals(memberRef("F"), Set("A", "B", "D", "E", "G", "C")) // C is the underlying type of MyC
assertEquals(inheritance("F"), Set("A", "E"))
assertEquals(memberRef("H"), Set("B", "E", "G"))
// aliases and applied type constructors are expanded so we have inheritance dependency on B
assertEquals(inheritance("H"), Set("B", "E"))
assertEquals(Set.empty, memberRef("A"))
assertEquals(Set.empty, inheritance("A"))
assertEquals(Set("A", "D"), memberRef("B"))
assertEquals(Set("D"), inheritance("B"))
assertEquals(Set("A"), memberRef("C"))
assertEquals(Set.empty, inheritance("C"))
assertEquals(Set.empty, memberRef("D"))
assertEquals(Set.empty, inheritance("D"))
assertEquals(Set.empty, memberRef("E"))
assertEquals(Set.empty, inheritance("E"))
assertEquals(Set("A", "B", "D", "E", "G", "C"), memberRef("F")) // C is the underlying type of MyC
assertEquals(Set("A", "E"), inheritance("F"))
assertEquals(Set("B", "E", "G"), memberRef("H"))// aliases and applied type constructors are expanded so we have inheritance dependency on B
assertEquals(Set("B", "E"), inheritance("H"))
}

@Test
Expand All @@ -35,37 +34,37 @@ class DependencySpecification {
val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
val localInheritance = classDependencies.localInheritance
assertEquals(memberRef("A"), Set.empty)
assertEquals(inheritance("A"), Set.empty)
assertEquals(memberRef("B"), Set.empty)
assertEquals(inheritance("B"), Set.empty)
assertEquals(memberRef("C.Inner1"), Set("A"))
assertEquals(inheritance("C.Inner1"), Set("A"))
assertEquals(memberRef("D"), Set("B"))
assertEquals(inheritance("D"), Set.empty)
assertEquals(localInheritance("D"), Set("B"))
assertEquals(memberRef("E"), Set("B"))
assertEquals(inheritance("E"), Set.empty)
assertEquals(localInheritance("E"), Set("B"))
assertEquals(Set.empty, memberRef("A"))
assertEquals(Set.empty, inheritance("A"))
assertEquals(Set.empty, memberRef("B"))
assertEquals(Set.empty, inheritance("B"))
assertEquals(Set("A"), memberRef("C.Inner1"))
assertEquals(Set("A"), inheritance("C.Inner1"))
assertEquals(Set("B"), memberRef("D"))
assertEquals(Set.empty, inheritance("D"))
assertEquals(Set("B"), localInheritance("D"))
assertEquals(Set("B"), memberRef("E"))
assertEquals(Set.empty, inheritance("E"))
assertEquals(Set("B"), localInheritance("E"))
}

@Test
def extractedClassDependenciesWithTraitAsFirstParent = {
val classDependencies = extractClassDependenciesTraitAsFirstPatent
val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
assertEquals(memberRef("A"), Set.empty)
assertEquals(inheritance("A"), Set.empty)
assertEquals(memberRef("B"), Set("A"))
assertEquals(inheritance("B"), Set("A"))
assertEquals(Set.empty, memberRef("A"))
assertEquals(Set.empty, inheritance("A"))
assertEquals(Set("A"), memberRef("B"))
assertEquals(Set("A"), inheritance("B"))
// 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
assertEquals(memberRef("C"), Set("A", "B"))
assertEquals(inheritance("C"), Set("A", "B"))
assertEquals(Set("A", "B"), memberRef("C"))
assertEquals(Set("A", "B"), inheritance("C"))
// same as above but indirect (C -> B -> A), note that only A is visible here
assertEquals(memberRef("D"), Set("A", "C"))
assertEquals(inheritance("D"), Set("A", "C"))
assertEquals(Set("A", "C"), memberRef("D"))
assertEquals(Set("A", "C"), inheritance("D"))
}

@Test
Expand All @@ -80,10 +79,10 @@ class DependencySpecification {

val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
assertEquals(memberRef("Outer"), Set.empty)
assertEquals(inheritance("Outer"), Set.empty)
assertEquals(memberRef("Bar"), Set("Outer", "Outer$.Inner"))
assertEquals(inheritance("Bar"), Set.empty)
assertEquals(Set.empty, memberRef("Outer"))
assertEquals(Set.empty, inheritance("Outer"))
assertEquals(Set("Outer", "Outer$.Inner"), memberRef("Bar"))
assertEquals(Set.empty, inheritance("Bar"))
}

@Test
Expand All @@ -100,10 +99,10 @@ class DependencySpecification {

val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
assertEquals(memberRef("A"), Set("B"))
assertEquals(inheritance("A"), Set.empty)
assertEquals(memberRef("B"), Set.empty)
assertEquals(inheritance("B"), Set.empty)
assertEquals(Set("B"), memberRef("A"))
assertEquals(Set.empty, inheritance("A"))
assertEquals(Set.empty, memberRef("B"))
assertEquals(Set.empty, inheritance("B"))
}

@Test
Expand Down Expand Up @@ -135,14 +134,14 @@ class DependencySpecification {
.extractDependenciesFromSrcs(srcA, srcB, srcC, srcD, srcE, srcF, srcG, srcH)
.memberRef

assertEquals(deps("A"), Set.empty)
assertEquals(deps("B"), Set("abc.A", "abc.A$.Inner"))
assertEquals(deps("C"), Set("abc.A", "abc.A2"))
assertEquals(deps("D"), Set("abc.A2"))
assertEquals(deps("E"), Set("abc.A"))
assertEquals(deps("F"), Set.empty)
assertEquals(deps("foo.bar.G"), Set("abc.A"))
assertEquals(deps("H"), Set("abc.A"))
assertEquals(Set.empty, deps("A"))
assertEquals(Set("abc.A", "abc.A$.Inner"), deps("B"))
assertEquals(Set("abc.A", "abc.A2"), deps("C"))
assertEquals(Set("abc.A2"), deps("D"))
assertEquals(Set("abc.A"), deps("E"))
assertEquals(Set.empty, deps("F"))
assertEquals(Set("abc.A"), deps("foo.bar.G"))
assertEquals(Set("abc.A"), deps("H"))
}

private def extractClassDependenciesPublic: ExtractedClassDependencies = {
Expand Down
16 changes: 8 additions & 8 deletions sbt-bridge/test/xsbt/ExtractAPISpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ExtractAPISpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src)
val Seq(fooClassApi) = apis.toSeq
assertEquals(fooClassApi.definitionType, DefinitionType.PackageModule)
assertEquals(DefinitionType.PackageModule, fooClassApi.definitionType)
}

@Test
Expand All @@ -47,7 +47,7 @@ class ExtractAPISpecification {
|}""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src).map(c => c.name -> c).toMap
assertEquals(apis.keys, Set("A", "A.B"))
assertEquals(Set("A", "A.B"), apis.keys)
}

@Test
Expand All @@ -59,7 +59,7 @@ class ExtractAPISpecification {
|class D { def foo: Unit = { new B {} } }""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src).map(c => c.name -> c).toMap
assertEquals(apis.keys, Set("A", "B", "C", "D"))
assertEquals(Set("A", "B", "C", "D"), apis.keys)
}

@Ignore
Expand Down Expand Up @@ -93,7 +93,7 @@ class ExtractAPISpecification {
|""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src).map(c => c.name -> c).toMap
assertEquals(apis.keys, Set("A", "B", "B.Inner1"))
assertEquals(Set("A", "B", "B.Inner1"), apis.keys)
}

@Test
Expand Down Expand Up @@ -165,7 +165,7 @@ class ExtractAPISpecification {
""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src).map(a => a.name -> a).toMap
assertEquals(apis.keySet, Set("A", "A.AA", "B", "B.AA"))
assertEquals(Set("A", "A.AA", "B", "B.AA"), apis.keySet)
assertNotEquals(apis("A.AA"), apis("B.AA"))
}

Expand All @@ -181,7 +181,7 @@ class ExtractAPISpecification {
""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val apis = compilerForTesting.extractApiFromSrc(src).map(a => a.name -> a).toMap
assertEquals(apis.keySet, Set("abc.package", "abc.package$.BuildInfoKey", "abc.package$.BuildInfoKey$.Entry"))
assertEquals(Set("abc.package", "abc.package$.BuildInfoKey", "abc.package$.BuildInfoKey$.Entry"), apis.keySet)
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ class ExtractAPISpecification {
def hasSelfType(c: ClassLike): Boolean =
c.selfType != emptyType
val (withSelfType, withoutSelfType) = apis.partition(hasSelfType)
assertEquals(withSelfType.map(_.name).toSet, Set("C3", "C4", "C5", "C6"))
assertEquals(withoutSelfType.map(_.name).toSet, Set("X", "Y", "C1", "C2", "C8"))
assertEquals(Set("C3", "C4", "C5", "C6"), withSelfType.map(_.name).toSet)
assertEquals(Set("X", "Y", "C1", "C2", "C8"), withoutSelfType.map(_.name).toSet)
}
}
46 changes: 23 additions & 23 deletions sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExtractUsedNamesSpecification {
val expectedNames = standardNames ++ Set("a", "A", "A2", "b")
// names used at top level are attributed to the first class defined in a compilation unit

assertEquals(usedNames("a.A"), expectedNames)
assertEquals(expectedNames, usedNames("a.A"))
}

// test covers https://github.com/gkossakowski/sbt/issues/6
Expand All @@ -44,7 +44,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
val expectedNames = standardNames ++ Set("a", "c", "A", "B", "C", "D", "b", "BB")
assertEquals(usedNames("b.X"), expectedNames)
assertEquals(expectedNames, usedNames("b.X"))
}

// test for https://github.com/gkossakowski/sbt/issues/5
Expand All @@ -59,7 +59,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
val expectedNames = standardNames ++ Set("A", "a", "=", "Int")
assertEquals(usedNames("B"), expectedNames)
assertEquals(expectedNames, usedNames("B"))
}

@Test
Expand All @@ -83,11 +83,11 @@ class ExtractUsedNamesSpecification {
val namesB = Set("A", "Int", "A;init;", "Unit")
val namesC = Set("B;init;", "B", "Unit")
val namesD = standardNames ++ Set("C", "X", "foo", "Int", "T")
assertEquals(usedNames("A"), namesA)
assertEquals(usedNames("A.X"), namesAX)
assertEquals(usedNames("B"), namesB)
assertEquals(usedNames("C"), namesC)
assertEquals(usedNames("D"), namesD)
assertEquals(namesA, usedNames("A"))
assertEquals(namesAX, usedNames("A.X"))
assertEquals(namesB, usedNames("B"))
assertEquals(namesC, usedNames("C"))
assertEquals(namesD, usedNames("D"))
}

// See source-dependencies/types-in-used-names-a for an example where
Expand Down Expand Up @@ -147,11 +147,11 @@ class ExtractUsedNamesSpecification {
"Predef",
"???",
"Nothing")
assertEquals(usedNames("Test_lista"), expectedNames_lista)
assertEquals(usedNames("Test_at"), expectedNames_at)
assertEquals(usedNames("Test_as"), expectedNames_as)
assertEquals(usedNames("Test_foo"), expectedNames_foo)
assertEquals(usedNames("Test_bar"), expectedNames_bar)
assertEquals(expectedNames_lista, usedNames("Test_lista"))
assertEquals(expectedNames_at, usedNames("Test_at"))
assertEquals(expectedNames_as, usedNames("Test_as"))
assertEquals(expectedNames_foo, usedNames("Test_foo"))
assertEquals(expectedNames_bar, usedNames("Test_bar"))
}

@Test
Expand All @@ -168,7 +168,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcFoo, srcBar)
val expectedNames = standardNames ++ Set("Outer", "TypeInner", "Inner", "Int")
assertEquals(usedNames("Bar"), expectedNames)
assertEquals(expectedNames, usedNames("Bar"))
}

// test for https://github.com/gkossakowski/sbt/issues/3
Expand All @@ -178,7 +178,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)
val expectedNames = standardNames ++ Set("A", "foo", "Int")
assertEquals(usedNames("A"), expectedNames)
assertEquals(expectedNames, usedNames("A"))
}

// pending test for https://issues.scala-lang.org/browse/SI-7173
Expand All @@ -188,7 +188,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)
val expectedNames = standardNames ++ Set("A", "foo", "Int")
assertEquals(usedNames("A"), expectedNames)
assertEquals(expectedNames, usedNames("A"))
}

// test for https://github.com/gkossakowski/sbt/issues/4
Expand All @@ -203,7 +203,7 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
val expectedNames = standardNames ++ Set("A", "a", "Int", "selectDynamic", "bla")
assertEquals(usedNames("B"), expectedNames)
assertEquals(expectedNames, usedNames("B"))
}

@Test
Expand Down Expand Up @@ -242,12 +242,12 @@ class ExtractUsedNamesSpecification {
|}
""".stripMargin

assertEquals(findPatMatUsages(classWithPatMatOfType()), Set(sealedClassName))
assertEquals(Set(sealedClassName), findPatMatUsages(classWithPatMatOfType()))
// Option is sealed
assertEquals(findPatMatUsages(classWithPatMatOfType(s"Option[$sealedClassName]")),
Set(sealedClassName, "Option"))
assertEquals(Set(sealedClassName, "Option"),
findPatMatUsages(classWithPatMatOfType(s"Option[$sealedClassName]")))
// Seq and Set is not
assertEquals(findPatMatUsages(classWithPatMatOfType(s"Seq[Set[$sealedClassName]]")), Set(sealedClassName))
assertEquals(Set(sealedClassName), findPatMatUsages(classWithPatMatOfType(s"Seq[Set[$sealedClassName]]")))

def inNestedCase(tpe: String) =
s"""package client
Expand All @@ -259,7 +259,7 @@ class ExtractUsedNamesSpecification {
| }
|}""".stripMargin

assertEquals(findPatMatUsages(inNestedCase(sealedClassName)), Set())
assertEquals(Set(), findPatMatUsages(inNestedCase(sealedClassName)))

val notUsedInPatternMatch =
s"""package client
Expand All @@ -272,7 +272,7 @@ class ExtractUsedNamesSpecification {
| val aa: $sealedClassName = ???
|}""".stripMargin

assertEquals(findPatMatUsages(notUsedInPatternMatch), Set())
assertEquals(Set(), findPatMatUsages(notUsedInPatternMatch))
}

/**
Expand Down

0 comments on commit 5c4dead

Please sign in to comment.