Skip to content

Commit

Permalink
Add sourceSets test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Strnad committed Jan 5, 2017
1 parent 99e528f commit 5ff469e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/groovy/cz/alenkacz/gradle/scalafmt/ProjectMother.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 5ff469e

Please sign in to comment.