Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions project.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* project.scala */
//> using scala 2.13.13
//> using dep org.scalameta::scalameta:4.9.1
//> using test.dep org.scalameta::munit::0.7.29
//> using scala "2.13.13"
//> using dep "org.scalameta::scalameta:4.11.0"
//> using test.dep "org.scalameta::munit::0.7.29"
//> using resourceDir "./resources"
//> using dep com.lihaoyi::upickle::3.2.0
//> using dep "com.lihaoyi::upickle::4.0.2"
2 changes: 2 additions & 0 deletions resources/V10.scala_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@deriving(ResourceWriter, ResourceReader)
case class User(id: Int, name: String, email: String)
2 changes: 2 additions & 0 deletions resources/V10.scala_test.prev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@deriving(ReadWriter)
case class User(id: Int, name: String, email: String)
32 changes: 18 additions & 14 deletions src/BreakingChangeDetector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,24 @@ object BreakingChangeDetector {
private def checkIfDerivingAnnotationWasChanged(
oldClass: ClassInfo,
newClass: ClassInfo
): Boolean =
oldClass.annotations
): Boolean = {
val isOldClassContainsSerializable = !(oldClass.annotations
.filter(_.name == "deriving")
.forall(oldAnnotation =>
newClass.annotations
.find(_.name == "deriving")
.exists(newAnnotation =>
newAnnotation.args.contains(oldAnnotation.args)
)
) &&
!(oldClass.annotations
.filter(_.name == "deriving")
.flatMap(_.args)
.filter(x => serializableClasses.contains(x))
.length == 0)
.flatMap(_.args)
.filter(x => serializableClasses.contains(x))
.length == 0)

val oldClassDerivingAnnotations =
oldClass.annotations.filter(_.name == "deriving")
val newClassDerivingAnnotations =
newClass.annotations.find(_.name == "deriving")

isOldClassContainsSerializable &&
!oldClassDerivingAnnotations
.forall(oldAnnotation =>
newClassDerivingAnnotations.exists(newAnnotation => {
oldAnnotation.args.toSet.subsetOf(newAnnotation.args.toSet)
})
)
}
}
29 changes: 29 additions & 0 deletions test/BreakingChangeDetector.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,33 @@ class BreakingChangeDetectorTest extends munit.FunSuite {
compared.find(_.isBreakingChange).isEmpty
)
}

test("Should detect ReaderWriter changed to ResourceWriter, ResourceReader") {
def runWithFiles(olfFileName: String, newFileName: String) = {
val oldFile = Thread
.currentThread()
.getContextClassLoader
.getResource("V10.scala_test.prev")
.getPath
val oldFileParsed = FileParser.fromPathToClassDef(oldFile)
val newFile = Thread
.currentThread()
.getContextClassLoader
.getResource("V10.scala_test")
.getPath
val newFileParsed = FileParser.fromPathToClassDef(newFile)
val compared =
BreakingChangeDetector.detectBreakingChange(
oldFileParsed,
newFileParsed
)
println(compared)
assert(
compared.find(_.isBreakingChange).nonEmpty
)
}

runWithFiles("V10.scala_test.prev", "V10.scala_test")
runWithFiles("V10.scala_test", "V10.scala_test.prev")
}
}
Loading