@@ -7,78 +7,62 @@ import scala.reflect.io.Directory
77import scala .util .{ Failure , Success , Try }
88
99import com .typesafe .config .ConfigFactory
10- import com .typesafe .tools .mima .core .{ Problem , ProblemFilters }
10+ import com .typesafe .tools .mima .core .{ ProblemFilter , ProblemFilters }
1111import coursier ._
12- import munit .GenericTest
1312
14- object IntegrationTests {
15- def main (args : Array [String ]): Unit = fromArgs(args.toList).unsafeRunTest()
16- def munitTests (): List [GenericTest [Unit ]] = fromArgs(Nil ).munitTests
13+ import CollectProblemsTest ._ , IntegrationTests ._
1714
18- def fromArgs (args : List [String ]): Tests = {
19- val dirs = Directory (" functional-tests/src/it" ).dirs.filter(args match {
20- case Seq () => dir => dir.files.exists(_.name == " test.conf" )
21- case names => dir => names.contains(dir.name)
22- }).toList.sortBy(_.path)
23- Tests (dirs.map(dir => Test (dir.name, testIntegration(dir))))
15+ object IntegrationTests {
16+ def testIntegrationDir (baseDir : Directory ): Try [Unit ] = {
17+ val conf = ConfigFactory .parseFile((baseDir / " test.conf" ).jfile)
18+ .withFallback(ConfigFactory .parseString(" filter.problems = []" ))
19+ .resolve()
20+ val problemFilter = conf.getConfigList(" filter.problems" ).asScala.map { conf =>
21+ ProblemFilters .exclude(conf.getString(" problemName" ), conf.getString(" matchName" ))
22+ }.foldAll
23+ val direction = Backwards
24+ testIntegration(
25+ conf.getString(" groupId" ),
26+ conf.getString(" artifactId" ),
27+ conf.getString(" v1" ),
28+ conf.getString(" v2" ),
29+ )(readOracleFile((baseDir / direction.oracleFile).jfile), problemFilter)
2430 }
2531
26- def testIntegration (baseDir : Directory ): Try [Unit ] = {
27- val conf = ConfigFactory .parseFile((baseDir / " test.conf" ).jfile).resolve()
28- val groupId = conf.getString(" groupId" )
29- val artifactId = conf.getString(" artifactId" )
32+ def testIntegration (groupId : String , artifactId : String , v1 : String , v2 : String )(
33+ expected : List [String ] = Nil ,
34+ problemFilter : ProblemFilter = _ => true ,
35+ excludeAnnots : List [String ] = Nil ,
36+ moduleAttrs : Map [String , String ] = Map .empty,
37+ ) = {
38+ val module = Module (Organization (groupId), ModuleName (artifactId), moduleAttrs)
3039 for {
31- (v1, _) <- getArtifact(groupId, artifactId, conf.getString(" v1" ))
32- (v2, cp) <- getArtifact(groupId, artifactId, conf.getString(" v2" ))
33- problemFilter <- getProblemFilter(baseDir.jfile)
34- () <- testCollectProblems(baseDir, problemFilter, cp, v1, v2, Backwards )
35- // () <- testCollectProblems(baseDir, problemFilter, cp, v1, v2, Forwards)
40+ (v1, _) <- fetchArtifact(Dependency (module, v1))
41+ (v2, cp) <- fetchArtifact(Dependency (module, v2))
42+ () <- collectAndDiff(cp, v1, v2)(expected, problemFilter, excludeAnnots)
3643 } yield ()
3744 }
3845
39- def getArtifact (groupId : String , artifactId : String , version : String ): Try [(File , Seq [File ])] = {
40- fetchArtifact(Dependency (Module (Organization (groupId), ModuleName (artifactId)), version))
41- }
42-
4346 def fetchArtifact (dep : Dependency ): Try [(File , Seq [File ])] = {
4447 Coursier .fetch(dep) match {
45- case Nil => Failure (sys.error(s " Could not resolve artifact: $dep" ))
4648 case Seq (jar, cp @ _* ) => Success ((jar, cp))
49+ case _ => Failure (sys.error(s " Could not resolve artifact: $dep" ))
4750 }
4851 }
4952
50- def getProblemFilter (baseDir : File ): Try [Problem => Boolean ] = Try {
51- val configFile = new File (baseDir, " test.conf" )
52- val configFallback = ConfigFactory .parseString(" filter { problems = [] }" )
53- val config = ConfigFactory .parseFile(configFile).withFallback(configFallback).resolve()
54- val filters = for (conf <- config.getConfigList(" filter.problems" ).asScala)
55- yield ProblemFilters .exclude(conf.getString(" problemName" ), conf.getString(" matchName" ))
56- (p : Problem ) => filters.forall(filter => filter(p))
57- }
58-
59- def testCollectProblems (baseDir : Directory , problemFilter : Problem => Boolean , cp : Seq [File ], v1 : File , v2 : File , direction : Direction ): Try [Unit ] = {
60- val problems = CollectProblemsTest .collectProblems(cp, v1, v2, direction).filter(problemFilter)
61- val expected = CollectProblemsTest .readOracleFile((baseDir / direction.oracleFile).jfile)
62- CollectProblemsTest .diffProblems(problems, expected, direction)
53+ implicit class PredicatesOps [A ](private val ps : Iterable [A => Boolean ]) extends AnyVal {
54+ def foldAll : A => Boolean = (x : A ) => ps.forall(p => p(x))
55+ def foldAny : A => Boolean = (x : A ) => ps.exists(p => p(x))
6356 }
6457}
6558
6659object CompareJars {
6760 def main (args : Array [String ]): Unit = args.toList match {
68- case Seq (file) => runTry(compare(new File (file), new File (file), Nil ))
69- case Seq (groupId, artifactId, version1, version2, attrStrs @ _* ) =>
61+ case Seq (file) =>
62+ runTry(collectAndDiff(Nil , new File (file), new File (file))())
63+ case Seq (groupId, artifactId, v1, v2, attrStrs @ _* ) =>
7064 val attrs = attrStrs.map { s => val Array (k, v) = s.split('=' ); k -> v }.toMap
71- val module = Module (Organization (groupId), ModuleName (artifactId)).withAttributes(attrs)
72- runTry(for {
73- (v1, _) <- IntegrationTests .fetchArtifact(Dependency (module, version1))
74- (v2, cp) <- IntegrationTests .fetchArtifact(Dependency (module, version2))
75- () <- compare(v1, v2, cp)
76- } yield ())
77- }
78-
79- def compare (v1 : File , v2 : File , cp : Seq [File ], direction : Direction = Backwards ): Try [Unit ] = {
80- val problems = CollectProblemsTest .collectProblems(cp, v1, v2, direction)
81- CollectProblemsTest .diffProblems(problems, Nil , direction)
65+ runTry(testIntegration(groupId, artifactId, v1, v2)(moduleAttrs = attrs))
8266 }
8367
8468 def runTry (tri : Try [Unit ]) = tri match {
0 commit comments