Skip to content

Commit aef8ccc

Browse files
committed
Fix deriving annotation test
1 parent 830ef14 commit aef8ccc

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

project.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* project.scala */
2-
//> using scala 2.13.13
3-
//> using dep org.scalameta::scalameta:4.9.1
4-
//> using test.dep org.scalameta::munit::0.7.29
2+
//> using scala "2.13.13"
3+
//> using dep "org.scalameta::scalameta:4.11.0"
4+
//> using test.dep "org.scalameta::munit::0.7.29"
55
//> using resourceDir "./resources"
6-
//> using dep com.lihaoyi::upickle::3.2.0
6+
//> using dep "com.lihaoyi::upickle::4.0.2"

resources/V10.scala_test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deriving(ResourceWriter, ResourceReader)
2+
case class User(id: Int, name: String, email: String)

resources/V10.scala_test.prev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deriving(ReadWriter)
2+
case class User(id: Int, name: String, email: String)

src/BreakingChangeDetector.scala

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,24 @@ object BreakingChangeDetector {
9696
private def checkIfDerivingAnnotationWasChanged(
9797
oldClass: ClassInfo,
9898
newClass: ClassInfo
99-
): Boolean =
100-
oldClass.annotations
99+
): Boolean = {
100+
val isOldClassContainsSerializable = !(oldClass.annotations
101101
.filter(_.name == "deriving")
102-
.forall(oldAnnotation =>
103-
newClass.annotations
104-
.find(_.name == "deriving")
105-
.exists(newAnnotation =>
106-
newAnnotation.args.contains(oldAnnotation.args)
107-
)
108-
) &&
109-
!(oldClass.annotations
110-
.filter(_.name == "deriving")
111-
.flatMap(_.args)
112-
.filter(x => serializableClasses.contains(x))
113-
.length == 0)
102+
.flatMap(_.args)
103+
.filter(x => serializableClasses.contains(x))
104+
.length == 0)
105+
106+
val oldClassDerivingAnnotations =
107+
oldClass.annotations.filter(_.name == "deriving")
108+
val newClassDerivingAnnotations =
109+
newClass.annotations.find(_.name == "deriving")
114110

111+
isOldClassContainsSerializable &&
112+
!oldClassDerivingAnnotations
113+
.forall(oldAnnotation =>
114+
newClassDerivingAnnotations.exists(newAnnotation => {
115+
oldAnnotation.args.toSet.subsetOf(newAnnotation.args.toSet)
116+
})
117+
)
118+
}
115119
}

test/BreakingChangeDetector.test.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,33 @@ class BreakingChangeDetectorTest extends munit.FunSuite {
227227
compared.find(_.isBreakingChange).isEmpty
228228
)
229229
}
230+
231+
test("Should detect ReaderWriter changed to ResourceWriter, ResourceReader") {
232+
def runWithFiles(olfFileName: String, newFileName: String) = {
233+
val oldFile = Thread
234+
.currentThread()
235+
.getContextClassLoader
236+
.getResource("V10.scala_test.prev")
237+
.getPath
238+
val oldFileParsed = FileParser.fromPathToClassDef(oldFile)
239+
val newFile = Thread
240+
.currentThread()
241+
.getContextClassLoader
242+
.getResource("V10.scala_test")
243+
.getPath
244+
val newFileParsed = FileParser.fromPathToClassDef(newFile)
245+
val compared =
246+
BreakingChangeDetector.detectBreakingChange(
247+
oldFileParsed,
248+
newFileParsed
249+
)
250+
println(compared)
251+
assert(
252+
compared.find(_.isBreakingChange).nonEmpty
253+
)
254+
}
255+
256+
runWithFiles("V10.scala_test.prev", "V10.scala_test")
257+
runWithFiles("V10.scala_test", "V10.scala_test.prev")
258+
}
230259
}

0 commit comments

Comments
 (0)