Skip to content

Commit a2f5eda

Browse files
dwestheidehugo-vrijswijk
authored andcommitted
Fix glob pattern for collection files to be mutated (#219)
Make sure files in root of Scala source directory get mutated
1 parent e30645e commit a2f5eda

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

core/src/main/scala/stryker4s/config/Config.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import better.files._
44
import pureconfig.ConfigWriter
55
import pureconfig.generic.auto._
66

7-
case class Config(mutate: Seq[String] = Seq("**/main/scala/**/*.scala"),
7+
case class Config(mutate: Seq[String] = Seq("**/main/scala/**.scala"),
88
baseDir: File = File.currentWorkingDirectory,
99
reporters: Seq[ReporterType] = Seq(ConsoleReporterType, HtmlReporterType),
1010
files: Option[Seq[String]] = None,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
object Foo {}

core/src/test/scala/stryker4s/config/ConfigReaderTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ConfigReaderTest extends Stryker4sSuite with LogMatchers with ConfigReader
3838
val result = ConfigReader.readConfig(confPath)
3939

4040
result.baseDir shouldBe File.currentWorkingDirectory
41-
result.mutate shouldBe Seq("**/main/scala/**/*.scala")
41+
result.mutate shouldBe Seq("**/main/scala/**.scala")
4242
result.reporters should contain inOrderOnly (ConsoleReporterType, HtmlReporterType)
4343
}
4444

core/src/test/scala/stryker4s/config/ConfigTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ConfigTest extends Stryker4sSuite {
1414
s"""base-dir="${File.currentWorkingDirectory.pathAsString.replace("\\", "\\\\")}"
1515
|excluded-mutations=[]
1616
|mutate=[
17-
| "**/main/scala/**/*.scala"
17+
| "**/main/scala/**.scala"
1818
|]
1919
|reporters=[
2020
| console,

core/src/test/scala/stryker4s/mutants/findmutants/FileCollectorTest.scala

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.util.{Failure, Try}
1212
class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatchers {
1313

1414
private val filledDirPath: File = FileUtil.getResource("fileTests/filledDir")
15-
private val basePath: File = filledDirPath / "src/main/scala/package"
15+
private val basePath: File = filledDirPath / "src/main/scala"
1616

1717
assume(filledDirPath.exists(), "Filled test dir does not exist")
1818
assume(basePath.exists(), "Basepath dir does not exist")
@@ -40,8 +40,8 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
4040

4141
val results = sut.collectFilesToMutate()
4242

43-
results should have size 3
44-
results should contain only (basePath / "someFile.scala", basePath / "secondFile.scala", basePath / "target.scala")
43+
results should have size 4
44+
results should contain only (basePath / "fileInRootSourceDir.scala", basePath / "package" / "someFile.scala", basePath / "package" / "secondFile.scala", basePath / "package" / "target.scala")
4545
}
4646

4747
it("should find matching files with custom config match pattern") {
@@ -52,7 +52,7 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
5252
val results = sut.collectFilesToMutate()
5353
val onlyResult = results.loneElement
5454

55-
onlyResult should equal(basePath / "secondFile.scala")
55+
onlyResult should equal(basePath / "package" / "secondFile.scala")
5656
}
5757

5858
it("should find no matches with a non-matching glob") {
@@ -73,18 +73,18 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
7373
val results = sut.collectFilesToMutate()
7474

7575
results should have size 2
76-
results should contain only (basePath / "someFile.scala", basePath / "secondFile.scala")
76+
results should contain only (basePath / "package" / "someFile.scala", basePath / "package" / "secondFile.scala")
7777
}
7878

7979
it("should only add a glob once even when it matches twice") {
8080
implicit val config: Config =
81-
Config(mutate = Seq("**/someFile.scala", "**/*.scala"), baseDir = filledDirPath)
81+
Config(mutate = Seq("**/someFile.scala", "src/main/scala/**/*.scala"), baseDir = filledDirPath)
8282
val sut = new FileCollector(TestProcessRunner())
8383

8484
val results = sut.collectFilesToMutate()
8585

8686
results should have size 3
87-
results should contain only (basePath / "someFile.scala", basePath / "secondFile.scala", basePath / "target.scala")
87+
results should contain only (basePath / "package" / "someFile.scala", basePath / "package" / "secondFile.scala", basePath / "package" / "target.scala")
8888
}
8989

9090
it("should not find a file twice when the patterns match on the same file twice") {
@@ -110,7 +110,7 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
110110
val results = sut.collectFilesToMutate()
111111

112112
results should have size 1
113-
results should contain only (basePath / "secondFile.scala")
113+
results should contain only (basePath / "package" / "secondFile.scala")
114114
}
115115

116116
it("Should exclude all files specified in the excluded files config") {
@@ -145,8 +145,8 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
145145

146146
val results = sut.collectFilesToMutate()
147147

148-
results should have size 3
149-
results should contain only (basePath / "someFile.scala", basePath / "secondFile.scala", basePath / "target.scala")
148+
results should have size 4
149+
results should contain only (basePath / "fileInRootSourceDir.scala", basePath / "package" / "someFile.scala", basePath / "package" / "secondFile.scala", basePath / "package" / "target.scala")
150150
}
151151

152152
it("Should not exclude a non existing file") {
@@ -160,7 +160,7 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
160160
val results = sut.collectFilesToMutate()
161161

162162
results should have size 2
163-
results should contain only (basePath / "someFile.scala", basePath / "secondFile.scala")
163+
results should contain only (basePath / "package" / "someFile.scala", basePath / "package" / "secondFile.scala")
164164
}
165165
}
166166
}
@@ -202,7 +202,9 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
202202
it("Should copy the files from the files config key") {
203203
implicit val config: Config =
204204
Config(baseDir = filledDirPath, files = Some(Seq("**/main/scala/**/*.scala")))
205-
val expectedFileList = Seq(basePath / "someFile.scala", basePath / "secondFile.scala", basePath / "target.scala")
205+
val expectedFileList = Seq(basePath / "package" / "someFile.scala",
206+
basePath / "package" / "secondFile.scala",
207+
basePath / "package" / "target.scala")
206208

207209
val sut = new FileCollector(processRunnerMock)
208210

@@ -213,12 +215,12 @@ class FileCollectorTest extends Stryker4sSuite with MockitoSuite with LogMatcher
213215

214216
it(
215217
"Should copy files out of the target folders when no files config key is found and target repo is not a git repo") {
216-
implicit val config: Config = Config(baseDir = basePath, files = None)
218+
implicit val config: Config = Config(baseDir = basePath / "package", files = None)
217219
val expectedFileList =
218-
Seq(basePath / "someFile.scala",
219-
basePath / "secondFile.scala",
220-
basePath / "otherFile.notScala",
221-
basePath / "target.scala")
220+
Seq(basePath / "package" / "someFile.scala",
221+
basePath / "package" / "secondFile.scala",
222+
basePath / "package" / "otherFile.notScala",
223+
basePath / "package" / "target.scala")
222224
val gitProcessResult = Failure(new Exception("Exception"))
223225
when(processRunnerMock(any[Command], any[File])).thenReturn(gitProcessResult)
224226

0 commit comments

Comments
 (0)