-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtFormatException.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cz.alenkacz.gradle.scalafmt | ||
|
||
class ScalafmtFormatException extends Exception { | ||
public ScalafmtFormatException(List<String> filePaths) { | ||
super("Files incorrectly formatted: " + filePaths.join(",")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cz.alenkacz.gradle.scalafmt | ||
|
||
import org.gradle.api.tasks.TaskAction | ||
|
||
class ScalafmtTestTask extends ScalafmtFormatBase { | ||
@TaskAction | ||
def format() { | ||
runScalafmt(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/groovy/cz/alenkacz/gradle/scalafmt/ScalafmtTestTaskTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cz.alenkacz.gradle.scalafmt | ||
|
||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class ScalafmtTestTaskTest extends Specification { | ||
def "fail for badly formatted code"() { | ||
given: | ||
def testProject = ProjectMother.basicProject() | ||
def project = ProjectBuilder.builder().withProjectDir(testProject.projectRoot).build() | ||
project.plugins.apply 'scala' | ||
project.plugins.apply 'scalafmt' | ||
|
||
when: | ||
project.tasks.scalafmtTest.format() | ||
|
||
then: | ||
thrown ScalafmtFormatException | ||
} | ||
|
||
def "not fail for correctly formatted code"() { | ||
given: | ||
def testProject = ProjectMother.basicProjectWithCorrectlyFormattedFile() | ||
def project = ProjectBuilder.builder().withProjectDir(testProject.projectRoot).build() | ||
project.plugins.apply 'scala' | ||
project.plugins.apply 'scalafmt' | ||
|
||
when: | ||
project.tasks.scalafmtTest.format() | ||
|
||
then: | ||
noExceptionThrown() | ||
} | ||
} |