diff --git a/src/test/groovy/cz/alenkacz/gradle/scalafmt/ProjectMother.groovy b/src/test/groovy/cz/alenkacz/gradle/scalafmt/ProjectMother.groovy index 33194db..f2788ff 100644 --- a/src/test/groovy/cz/alenkacz/gradle/scalafmt/ProjectMother.groovy +++ b/src/test/groovy/cz/alenkacz/gradle/scalafmt/ProjectMother.groovy @@ -22,6 +22,23 @@ class ProjectMother { return testProject } + static def basicProjectWithIncorrectTestFile() { + TestProject testProject = null + File.createTempDir().with { + deleteOnExit() + def srcFolder = new File(absoluteFile, testSourceFilePath) + srcFolder.mkdirs() + def srcFile = Files.createFile(Paths.get(srcFolder.absolutePath, "Test.scala")) + srcFile.write """ + |object Test { + | if(true){} + |} + |""".stripMargin() + testProject = new TestProject(absoluteFile, srcFile.toFile()) + } + return testProject + } + static def basicProject() { TestProject testProject = null File.createTempDir().with { @@ -40,6 +57,7 @@ class ProjectMother { | b)} """.stripMargin() private static def sourceFilePath = "src/main/scala/cz/alenkacz/gradle/scalafmt/test" + private static def testSourceFilePath = "src/test/scala/cz/alenkacz/gradle/scalafmt/test" static def projectWithConfig() { TestProject testProject = null diff --git a/src/test/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTaskTest.groovy b/src/test/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTaskTest.groovy index 2e70c09..ab519dc 100644 --- a/src/test/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTaskTest.groovy +++ b/src/test/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTaskTest.groovy @@ -31,4 +31,21 @@ class ScalafmtTestTaskTest extends Specification { then: noExceptionThrown() } + + def "ignore source files in test"() { + given: + def testProject = ProjectMother.basicProjectWithIncorrectTestFile() + def project = ProjectBuilder.builder().withProjectDir(testProject.projectRoot).build() + + project.plugins.apply 'scalafmt' + project.plugins.apply 'scala' + project.scalafmt.sourceSets = [project.sourceSets.main] + + when: + project.evaluate() + project.tasks.scalafmtTest.format() + + then: + noExceptionThrown() + } }