From 959bd3f634d6906c019837298243f1622d984914 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Tue, 20 Feb 2024 09:17:21 +0000 Subject: [PATCH 1/2] build(deps): update scalameta from 4.8.15 to 4.9.0 --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 048522bbb..972a4160d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -27,7 +27,7 @@ object Dependencies { val mutationTestingElements = "3.0.2" val mutationTestingMetrics = "3.0.2" val pureconfig = "0.17.5" - val scalameta = "4.8.15" + val scalameta = "4.9.0" val slf4j = "2.0.11" val sttp = "3.9.2" val testInterface = "1.0" From 7086678b8e4c28554ee44750eb3af99e9c3cbb9e Mon Sep 17 00:00:00 2001 From: Hugo van Rijswijk Date: Tue, 20 Feb 2024 15:19:54 +0100 Subject: [PATCH 2/2] Update --- .../mutants/tree/InstrumenterOptions.scala | 2 +- .../mutants/AddAllMutationsTest.scala | 2 +- .../mutants/tree/MutantInstrumenterTest.scala | 30 +++++++++++-------- .../stryker4s/testkit/Stryker4sSuite.scala | 8 ++++- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/modules/core/src/main/scala/stryker4s/mutants/tree/InstrumenterOptions.scala b/modules/core/src/main/scala/stryker4s/mutants/tree/InstrumenterOptions.scala index 9fc4f2ad2..cf0e816cd 100644 --- a/modules/core/src/main/scala/stryker4s/mutants/tree/InstrumenterOptions.scala +++ b/modules/core/src/main/scala/stryker4s/mutants/tree/InstrumenterOptions.scala @@ -20,7 +20,7 @@ object InstrumenterOptions { def testRunner = InstrumenterOptions( ActiveMutationContext.testRunner, - pattern = i => p"$i", + pattern = Lit.Int(_), condition = Some(ids => q"_root_.stryker4s.coverage.coverMutant(..${ids.map(Lit.Int(_)).toList})") ) } diff --git a/modules/core/src/test/scala/stryker4s/mutants/AddAllMutationsTest.scala b/modules/core/src/test/scala/stryker4s/mutants/AddAllMutationsTest.scala index 0c29687c6..2e145f69d 100644 --- a/modules/core/src/test/scala/stryker4s/mutants/AddAllMutationsTest.scala +++ b/modules/core/src/test/scala/stryker4s/mutants/AddAllMutationsTest.scala @@ -116,7 +116,7 @@ class AddAllMutationsTest extends Stryker4sIOSuite with LogMatchers { file.mutants.toVector.map { mutant => file.mutatedSource .find(mutant.mutatedCode.mutatedStatement) - .flatMap(_ => file.mutatedSource.find(p"${Lit.Int(mutant.id.value)}")) + .flatMap(_ => file.mutatedSource.find(Lit.Int(mutant.id.value))) .getOrElse( fail( s"Could not find mutant ${mutant.id} `${mutant.mutatedCode.metadata.replacement}` (original `${mutant.mutatedCode.metadata.original}`) in mutated tree ${file.mutatedSource}" diff --git a/modules/core/src/test/scala/stryker4s/mutants/tree/MutantInstrumenterTest.scala b/modules/core/src/test/scala/stryker4s/mutants/tree/MutantInstrumenterTest.scala index 4d27f32f3..d6c679e0c 100644 --- a/modules/core/src/test/scala/stryker4s/mutants/tree/MutantInstrumenterTest.scala +++ b/modules/core/src/test/scala/stryker4s/mutants/tree/MutantInstrumenterTest.scala @@ -30,18 +30,18 @@ class MutantInstrumenterTest extends Stryker4sSuite with TestData with LogMatche ) val sut = new MutantInstrumenter(InstrumenterOptions.testRunner) - // // Act + // Act val mutatedSource = sut.instrumentFile(context, mutants).mutatedSource val result = mutatedSource.collectFirst { case t: Term.Match => t }.value - // // Assert + // Assert assertEquals(result.expr, q"_root_.stryker4s.activeMutation") assertEquals( - result.cases.map(_.syntax), + result.cases, List( - p"case 0 => x > 15".syntax, - p"case 1 => x <= 15".syntax, - p"case _ if _root_.stryker4s.coverage.coverMutant(0, 1) => x >= 15".syntax + p"case 0 => x > 15", + p"case 1 => x <= 15", + p"case _ if _root_.stryker4s.coverage.coverMutant(0, 1) => x >= 15" ) ) val expected = source"""class Foo { @@ -82,11 +82,11 @@ class MutantInstrumenterTest extends Stryker4sSuite with TestData with LogMatche // // Assert assertEquals(result.expr, q"_root_.stryker4s.activeMutation") assertEquals( - result.cases.map(_.syntax), + result.cases, List( - p"case 0 => true".syntax, - p"case 1 => false".syntax, - p"case _ if _root_.stryker4s.coverage.coverMutant(0, 1) => bar".syntax + p"case 0 => true", + p"case 1 => false", + p"case _ if _root_.stryker4s.coverage.coverMutant(0, 1) => bar" ) ) val expected = source"""class Foo { @@ -123,8 +123,14 @@ class MutantInstrumenterTest extends Stryker4sSuite with TestData with LogMatche // // Assert assertEquals(result.expr, q"_root_.scala.sys.env.get(${Lit.String("ACTIVE_MUTATION")})") - assertEquals(result.cases.head.pat, p"Some(${Lit.String("0")})") - assertEquals(result.cases.map(_.syntax).last, p"case _ => x >= 15".syntax) + assertEquals( + result.cases, + List( + p"case Some(${Lit.String("0")}) => x > 15", + p"case Some(${Lit.String("1")}) => x <= 15", + p"case _ => x >= 15" + ) + ) } // describe("buildNewSource") { diff --git a/modules/testkit/src/main/scala/stryker4s/testkit/Stryker4sSuite.scala b/modules/testkit/src/main/scala/stryker4s/testkit/Stryker4sSuite.scala index 3e638bcee..c91926dc4 100644 --- a/modules/testkit/src/main/scala/stryker4s/testkit/Stryker4sSuite.scala +++ b/modules/testkit/src/main/scala/stryker4s/testkit/Stryker4sSuite.scala @@ -90,9 +90,15 @@ sealed trait Stryker4sAssertions { /** Compare 2 trees by structure. */ - implicit def treeCompare[A <: Tree, B <: Tree]: Compare[A, B] = (obtained: A, expected: B) => + implicit def treeCompare[A <: Tree, B <: Tree]: Compare[A, B] = (obtained, expected) => obtained == expected || obtained.structure == expected.structure + implicit def listCompare[A, B](implicit compare: Compare[A, B]): Compare[List[A], List[B]] = + (obtained, expected) => + obtained.size == expected.size && + obtained.zip(expected).forall { case (obtained, expected) => + compare.isEqual(obtained, expected) + } } abstract protected[stryker4s] class Stryker4sSuite extends FunSuite with Stryker4sAssertions