diff --git a/build.sbt b/build.sbt index 8e32c1a70..b21edd6fb 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,6 @@ import sbt.ScriptedPlugin import sbt.ScriptedPlugin._ organization in ThisBuild := "ch.epfl.scala" -version in ThisBuild := "0.2.1" lazy val crossVersions = Seq( "2.11.8", @@ -68,7 +67,7 @@ lazy val publishSettings = Seq( "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), homepage := Some(url("https://github.com/scalacenter/scalafix")), autoAPIMappings := true, - apiURL := Some(url("https://scalacenter.github.io/scalafix/docs/")), + apiURL := Some(url("https://scalacenter.github.io/scalafix/")), scmInfo := Some( ScmInfo( url("https://github.com/scalacenter/scalafix"), @@ -86,6 +85,7 @@ lazy val publishSettings = Seq( ) lazy val noPublish = Seq( + publishArtifact := false, publish := {}, publishLocal := {} ) @@ -94,6 +94,7 @@ lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq( buildInfoKeys := Seq[BuildInfoKey]( name, version, + "stableVersion" -> version.value, // TODO(olafur) customize. scalaVersion, sbtVersion ), diff --git a/scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixTestUtility.scala b/scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixTestUtility.scala new file mode 100644 index 000000000..5eec1463f --- /dev/null +++ b/scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixTestUtility.scala @@ -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 + } + } +} diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/basic/build.sbt b/scalafix-sbt/src/sbt-test/sbt-scalafix/basic/build.sbt index 277e91a24..825cf0794 100644 --- a/scalafix-sbt/src/sbt-test/sbt-scalafix/basic/build.sbt +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/basic/build.sbt @@ -1,5 +1,3 @@ -scalafixConfig in ThisBuild := Some(baseDirectory.value / ".scalafix.conf") - lazy val root = project .in(file(".")) .aggregate( @@ -13,36 +11,8 @@ lazy val p2 = project.settings(scalaVersion := "2.10.5") lazy val p3 = project.settings(scalaVersion := "2.12.1") TaskKey[Unit]("check") := { - // returns true if test succeeded, else false. - def assertContentMatches(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.value.log.error(file) - streams.value.log.error(msg) - false - } else { - streams.value.log.success(file) - true - } - } + val assertContentMatches: ((String, String) => Boolean) = + scalafix.sbt.ScalafixTestUtility.assertContentMatches(streams.value) _ val expected = """object Main { | implicit val x: Int = 2 diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/build.sbt b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/build.sbt new file mode 100644 index 000000000..3cbff5cb2 --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/build.sbt @@ -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 + ) + ) +} diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/myscalafix.conf b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/myscalafix.conf new file mode 100644 index 000000000..7062903ac --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/myscalafix.conf @@ -0,0 +1 @@ +rewrites = [VolatileLazyVal] \ No newline at end of file diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/build.properties b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/build.properties new file mode 100644 index 000000000..24be09b28 --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/build.properties @@ -0,0 +1,2 @@ +sbt.version=0.13.13 + diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/plugins.sbt b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/plugins.sbt new file mode 100644 index 000000000..843726faf --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/src/main/scala/Test.scala b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/src/main/scala/Test.scala new file mode 100644 index 000000000..06e0855ee --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/src/main/scala/Test.scala @@ -0,0 +1,7 @@ +object Main { + implicit val x = 2 + lazy val y = 2 + def main(args: Array[String]) { + println("hello") + } +} diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/config/test b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/test new file mode 100644 index 000000000..bb99e9ff9 --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/config/test @@ -0,0 +1,5 @@ +# compile should not affect scalafix +> compile +> scalafix +> check + diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/build.sbt b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/build.sbt new file mode 100644 index 000000000..d1b95cf0d --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/build.sbt @@ -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 + ) + ) +} diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/build.properties b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/build.properties new file mode 100644 index 000000000..24be09b28 --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/build.properties @@ -0,0 +1,2 @@ +sbt.version=0.13.13 + diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/plugins.sbt b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/plugins.sbt new file mode 100644 index 000000000..843726faf --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/src/main/scala/Test.scala b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/src/main/scala/Test.scala new file mode 100644 index 000000000..06e0855ee --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/src/main/scala/Test.scala @@ -0,0 +1,7 @@ +object Main { + implicit val x = 2 + lazy val y = 2 + def main(args: Array[String]) { + println("hello") + } +} diff --git a/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/test b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/test new file mode 100644 index 000000000..bb99e9ff9 --- /dev/null +++ b/scalafix-sbt/src/sbt-test/sbt-scalafix/noconfig/test @@ -0,0 +1,5 @@ +# compile should not affect scalafix +> compile +> scalafix +> check + diff --git a/scalafix-tests/src/test/scala/scalafix/tests/IntegrationPropertyTest.scala b/scalafix-tests/src/test/scala/scalafix/tests/IntegrationPropertyTest.scala index d5d4ebf18..1868f3c24 100644 --- a/scalafix-tests/src/test/scala/scalafix/tests/IntegrationPropertyTest.scala +++ b/scalafix-tests/src/test/scala/scalafix/tests/IntegrationPropertyTest.scala @@ -101,6 +101,11 @@ abstract class IntegrationPropertyTest(t: ItTest, skip: Boolean = false) case class FailOk(cmd: String, msg: String) extends Exception(msg) def check(): Unit = { + + def assertDiffIsNonEmpty(): Unit = { + %%("git", "diff", "--name-only")(t.workingPath).out.lines + .exists(_.endsWith(".scala")) + } def sbt(cmd: String): Unit = { val id = s"${t.name}/$cmd" logger.info(s"Running $id") @@ -111,12 +116,8 @@ abstract class IntegrationPropertyTest(t: ItTest, skip: Boolean = false) } val testFun: () => Any = { () => setup(t) - try { - t.cmds.map(_.cmd).foreach(sbt) - } catch { - case FailOk(cmd, msg) => - logger.warn(s"Failed to run $cmd, error $msg") - } + t.cmds.map(_.cmd).foreach(sbt) + assertDiffIsNonEmpty() } if (skip) ignore(t.name)(testFun()) diff --git a/version.sbt b/version.sbt new file mode 100644 index 000000000..990431131 --- /dev/null +++ b/version.sbt @@ -0,0 +1 @@ +version in ThisBuild := "0.2.2-SNAPSHOT"