Skip to content

Commit 2704c1b

Browse files
chore: add log assertions on IO
1 parent e0e517c commit 2704c1b

12 files changed

Lines changed: 195 additions & 211 deletions

File tree

maven/src/test/scala/stryker4s/maven/runner/MavenTestDiscoveryTest.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class MavenTestDiscoveryTest extends Stryker4sIOSuite with LogMatchers {
3030
test("warns when no test frameworks are found on the classpath") {
3131
MavenTestDiscovery
3232
.discover(Seq(testClassesDir), fullClasspath, frameworkNames = Seq("does.not.Exist"))
33-
.map { groups =>
34-
assertEquals(groups, Seq.empty)
35-
assertLoggedWarn("No sbt.testing test frameworks found on the test classpath")
36-
assertLoggedWarn("Will likely result in no tests being run and a NoCoverage result for all mutants.")
37-
}
33+
.assertEquals(Seq.empty)
34+
.assertLoggedWarn("No sbt.testing test frameworks found on the test classpath")
35+
.assertLoggedWarn("Will likely result in no tests being run and a NoCoverage result for all mutants.")
3836
}
3937

4038
test("a framework name that resolves to a non-Framework class is skipped without failing") {

modules/core/src/test/scala/stryker4s/config/ConfigLoaderTest.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import stryker4s.testkit.{LogMatchers, Stryker4sIOSuite}
99
class ConfigLoaderTest extends Stryker4sIOSuite with LogMatchers {
1010
test("combines a ConfigSource into Config") {
1111
val result = ConfigLoader.loadAll[IO](List.empty)
12-
result.assertEquals(Config.default) *>
13-
IO(
14-
assertLoggedInfo(
15-
"Loading config. Read how to configure Stryker4s here: https://stryker-mutator.io/docs/stryker4s/configuration/"
16-
)
12+
result
13+
.assertEquals(Config.default)
14+
.assertLoggedInfo(
15+
"Loading config. Read how to configure Stryker4s here: https://stryker-mutator.io/docs/stryker4s/configuration/"
1716
)
1817
}
1918

modules/core/src/test/scala/stryker4s/config/source/AggregateConfigSourceTest.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@ class AggregateConfigSourceTest extends Stryker4sIOSuite with LogMatchers {
2020
val aggregate = new AggregateConfigSource[IO](NonEmptyList.of(file, cli, defaults))
2121

2222
// file
23-
aggregate.timeout.load.assertEquals(6.seconds) *>
24-
IO(assertLoggedDebug(s"Loaded ${Color.Magenta("timeout")} from ${Color.Cyan("file config")}: 6 seconds")) *>
23+
aggregate.timeout.load
24+
.assertEquals(6.seconds)
25+
.assertLoggedDebug(s"Loaded ${Color.Magenta("timeout")} from ${Color.Cyan("file config")}: 6 seconds") *>
2526
// cli
26-
aggregate.baseDir.load.assertEquals(Path("/tmp/project")) *>
27-
IO(assertLoggedDebug(s"Loaded ${Color.Magenta("baseDir")} from ${Color.Cyan("CLI arguments")}: $path")) *>
27+
aggregate.baseDir.load
28+
.assertEquals(Path("/tmp/project"))
29+
.assertLoggedDebug(s"Loaded ${Color.Magenta("baseDir")} from ${Color.Cyan("CLI arguments")}: $path") *>
2830
// defaults
29-
aggregate.thresholdsHigh.load.assertEquals(80) *>
30-
IO(assertLoggedDebug(s"Loaded ${Color.Magenta("thresholdsHigh")} from ${Color.Cyan("defaults")}: 80"))
31+
aggregate.thresholdsHigh.load
32+
.assertEquals(80)
33+
.assertLoggedDebug(s"Loaded ${Color.Magenta("thresholdsHigh")} from ${Color.Cyan("defaults")}: 80")
3134
}
3235

3336
test("aggregate combines given sources and defaults") {
3437
val cli = new CliConfigSource[IO](Seq("--base-dir=/tmp/project"))
35-
ConfigSource.aggregate(List(cli)).flatMap { conf =>
36-
conf.baseDir.load.assertEquals(Path("/tmp/project")) *>
37-
conf.thresholdsHigh.load.assertEquals(80)
38-
} *> IO(
39-
assertLoggedDebug(
40-
s"Loaded config sources '${Color.Cyan("CLI arguments")}', '${Color.Cyan("file config")}'"
41-
)
42-
)
38+
ConfigSource
39+
.aggregate(List(cli))
40+
.flatMap { conf =>
41+
conf.baseDir.load.assertEquals(Path("/tmp/project")) *>
42+
conf.thresholdsHigh.load.assertEquals(80)
43+
}
44+
.assertLoggedDebug(s"Loaded config sources '${Color.Cyan("CLI arguments")}', '${Color.Cyan("file config")}'")
4345
}
4446
}

modules/core/src/test/scala/stryker4s/mutants/MutatorTest.scala

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ class MutatorTest extends Stryker4sIOSuite with LogMatchers {
107107
)
108108
val files = Stream(FileUtil.getResource("scalaFiles/simpleFile.scala"))
109109

110-
sut.go(files).asserting { _ =>
111-
assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
112-
assertLoggedInfo(s"${Cyan("4")} mutant(s) generated. Of which ${LightRed("3")} mutant(s) are excluded.")
113-
assertNotLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
114-
assertNotLoggedWarn("If this is not intended, please check your configuration and try again.")
115-
}
110+
sut
111+
.go(files)
112+
.assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
113+
.assertLoggedInfo(s"${Cyan("4")} mutant(s) generated. Of which ${LightRed("3")} mutant(s) are excluded.")
114+
.assertNotLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
115+
.assertNotLoggedWarn("If this is not intended, please check your configuration and try again.")
116+
116117
}
117118

118119
test("should log a warning if no mutants are found") {
@@ -124,12 +125,12 @@ class MutatorTest extends Stryker4sIOSuite with LogMatchers {
124125
)
125126
val files = Stream(FileUtil.getResource("fileTests/filledDir/src/main/scala/package/someFile.scala"))
126127

127-
sut.go(files).asserting { _ =>
128-
assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
129-
assertLoggedInfo(s"${Cyan("0")} mutant(s) generated.")
130-
assertLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
131-
assertLoggedWarn("If this is not intended, please check your configuration and try again.")
132-
}
128+
sut
129+
.go(files)
130+
.assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
131+
.assertLoggedInfo(s"${Cyan("0")} mutant(s) generated.")
132+
.assertLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
133+
.assertLoggedWarn("If this is not intended, please check your configuration and try again.")
133134
}
134135

135136
test("should log if all mutations are excluded") {
@@ -143,16 +144,16 @@ class MutatorTest extends Stryker4sIOSuite with LogMatchers {
143144
)
144145
val files = Stream(FileUtil.getResource("scalaFiles/simpleFile.scala"))
145146

146-
sut.go(files).asserting { _ =>
147-
assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
148-
assertLoggedInfo(s"${Cyan("4")} mutant(s) generated. Of which ${LightRed("4")} mutant(s) are excluded.")
149-
assertLoggedWarn(
147+
sut
148+
.go(files)
149+
.assertLoggedInfo(s"Found ${Cyan("1")} file(s) to be mutated.")
150+
.assertLoggedInfo(s"${Cyan("4")} mutant(s) generated. Of which ${LightRed("4")} mutant(s) are excluded.")
151+
.assertLoggedWarn(
150152
s"""All found mutations are excluded. Stryker4s will perform a dry-run without actually mutating anything.
151153
|You can configure the `mutate` or `excluded-mutations` property in your configuration""".stripMargin
152154
)
153-
assertNotLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
154-
assertNotLoggedWarn("If this is not intended, please check your configuration and try again.")
155-
}
155+
.assertNotLoggedWarn("Files to be mutated are found, but no mutations were found in those files.")
156+
.assertNotLoggedWarn("If this is not intended, please check your configuration and try again.")
156157
}
157158
}
158159
}

modules/core/src/test/scala/stryker4s/mutants/findmutants/MutantFinderTest.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ class MutantFinderTest extends Stryker4sIOSuite with LogMatchers {
7272
sut
7373
.parseFile(noFile)
7474
.intercept[ParseException]
75-
.asserting { _ =>
76-
assertLoggedError(
77-
s"Error while parsing file '${noFile.relativePath}', illegal start of definition `identifier`"
78-
)
79-
}
75+
.assertLoggedError(
76+
s"Error while parsing file '${noFile.relativePath}', illegal start of definition `identifier`"
77+
)
8078
}
8179
}
8280
}

modules/core/src/test/scala/stryker4s/report/AggregateReporterTest.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class AggregateReporterTest extends Stryker4sIOSuite with LogMatchers with TestD
4141
Stream(MutantTestedEvent(1), MutantTestedEvent(2))
4242
.through(sut.mutantTested)
4343
.compile
44-
.drain *> IO.cede >> {
45-
assertLoggedError("Reporter failed to report, java.lang.RuntimeException: Something happened")
46-
reporter1.mutantTestedCalls.assert(_.length == 2)
47-
}
44+
.drain *> IO.cede
45+
.assertLoggedError(
46+
"Reporter failed to report, java.lang.RuntimeException: Something happened"
47+
) >> reporter1.mutantTestedCalls.assert(_.length == 2)
4848
}
4949
}
5050

@@ -92,8 +92,9 @@ class AggregateReporterTest extends Stryker4sIOSuite with LogMatchers with TestD
9292
val sut = new AggregateReporter(List(consoleReporterStub, reporter1))
9393

9494
sut.onRunFinished(runReport) >>
95-
consoleReporterStub.onRunFinishedCalls.assert(_.length == 1) >>
96-
IO(assertNotLoggedWarn("Reporter failed to report"))
95+
consoleReporterStub.onRunFinishedCalls
96+
.assert(_.length == 1)
97+
.assertNotLoggedWarn("Reporter failed to report")
9798
}
9899
}
99100
}

0 commit comments

Comments
 (0)