-
Notifications
You must be signed in to change notification settings - Fork 185
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
16 changed files
with
127 additions
and
40 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
41 changes: 41 additions & 0 deletions
41
scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixTestUtility.scala
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,41 @@ | ||
package scalafix.sbt | ||
|
||
import sbt.Keys.TaskStreams | ||
|
||
/** | ||
* Created by ollie on 02/01/17. | ||
*/ | ||
object ScalafixTestUtility { | ||
// returns true if test succeeded, else false. | ||
def assertContentMatches(streams: TaskStreams)( | ||
file: String, | ||
expectedUntrimmed: String): Boolean = { | ||
val expected = expectedUntrimmed.trim | ||
val obtained = new String( | ||
java.nio.file.Files.readAllBytes( | ||
java.nio.file.Paths.get( | ||
new java.io.File(file).toURI | ||
)) | ||
).trim | ||
|
||
if (obtained.diff(expected).nonEmpty || | ||
expected.diff(obtained).nonEmpty) { | ||
val msg = | ||
s"""File: $file | ||
|Obtained output: | ||
|$obtained | ||
|Expected: | ||
|$expected | ||
|Diff: | ||
|${obtained.diff(expected)} | ||
|${expected.diff(obtained)} | ||
|""".stripMargin | ||
streams.log.error(file) | ||
streams.log.error(msg) | ||
false | ||
} else { | ||
streams.log.success(file) | ||
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
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,22 @@ | ||
scalaVersion := "2.11.8" | ||
|
||
scalafixConfig in ThisBuild := Some(file("myscalafix.conf")) | ||
|
||
TaskKey[Unit]("check") := { | ||
val assertContentMatches: ((String, String) => Boolean) = | ||
scalafix.sbt.ScalafixTestUtility.assertContentMatches(streams.value) _ | ||
val expected = | ||
"""object Main { | ||
| implicit val x = 2 | ||
| @volatile lazy val y = 2 | ||
| def main(args: Array[String]) { | ||
| println("hello") | ||
| } | ||
|}""".stripMargin | ||
assert( | ||
assertContentMatches( | ||
"src/main/scala/Test.scala", | ||
expected | ||
) | ||
) | ||
} |
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 @@ | ||
rewrites = [VolatileLazyVal] |
2 changes: 2 additions & 0 deletions
2
scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/build.properties
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,2 @@ | ||
sbt.version=0.13.13 | ||
|
1 change: 1 addition & 0 deletions
1
scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/plugins.sbt
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 @@ | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
7 changes: 7 additions & 0 deletions
7
scalafix-sbt/src/sbt-test/sbt-scalafix/config/src/main/scala/Test.scala
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 @@ | ||
object Main { | ||
implicit val x = 2 | ||
lazy val y = 2 | ||
def main(args: Array[String]) { | ||
println("hello") | ||
} | ||
} |
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,5 @@ | ||
# compile should not affect scalafix | ||
> compile | ||
> scalafix | ||
> check | ||
|
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,20 @@ | ||
scalaVersion := "2.11.8" | ||
|
||
TaskKey[Unit]("check") := { | ||
val assertContentMatches: ((String, String) => Boolean) = | ||
scalafix.sbt.ScalafixTestUtility.assertContentMatches(streams.value) _ | ||
val expected = | ||
"""object Main { | ||
| implicit val x: Int = 2 | ||
| lazy val y = 2 | ||
| def main(args: Array[String]): Unit = { | ||
| println("hello") | ||
| } | ||
|}""".stripMargin | ||
assert( | ||
assertContentMatches( | ||
"src/main/scala/Test.scala", | ||
expected | ||
) | ||
) | ||
} |
2 changes: 2 additions & 0 deletions
2
scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/build.properties
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,2 @@ | ||
sbt.version=0.13.13 | ||
|
1 change: 1 addition & 0 deletions
1
scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/plugins.sbt
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 @@ | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
7 changes: 7 additions & 0 deletions
7
scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/src/main/scala/Test.scala
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 @@ | ||
object Main { | ||
implicit val x = 2 | ||
lazy val y = 2 | ||
def main(args: Array[String]) { | ||
println("hello") | ||
} | ||
} |
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,5 @@ | ||
# compile should not affect scalafix | ||
> compile | ||
> scalafix | ||
> check | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version in ThisBuild := "0.2.2-SNAPSHOT" |