Skip to content

Commit

Permalink
Merge pull request #1552 from tanishiking/refactor-for-local
Browse files Browse the repository at this point in the history
Make it easier to test scalafmt local snapshot build
  • Loading branch information
tanishiking authored Nov 17, 2019
2 parents 778c75f + f14229d commit 488ddf2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
12 changes: 12 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import Dependencies._
import sbtcrossproject.CrossPlugin.autoImport.crossProject

def parseTagVersion: String = {
import scala.sys.process._
// drop `v` prefix
"git describe --abbrev=0 --tags".!!.drop(1).trim
}
def localSnapshotVersion: String = s"$parseTagVersion-SNAPSHOT"
def isCI = System.getenv("CI") != null

def scala211 = "2.11.12"
def scala212 = "2.12.8"
def scala213 = "2.13.1"

inThisBuild(
List(
version ~= { dynVer =>
if (isCI) dynVer
else localSnapshotVersion // only for local publishng
},
organization := "org.scalameta",
homepage := Some(url("https://github.com/scalameta/scalafmt")),
licenses := List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ScalafmtVersion {
extends Exception(s"Invalid scalafmt version $version")
with NoStackTrace

private val versionRegex = """(\d)\.(\d)\.(\d)(-RC(\d))?""".r
private val versionRegex = """(\d)\.(\d)\.(\d)(-RC(\d))?(?:-SNAPSHOT)?""".r

def parse(version: String): Either[InvalidVersionException, ScalafmtVersion] =
try {
Expand Down
5 changes: 3 additions & 2 deletions scalafmt-dynamic/src/test/scala/tests/DynamicSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ class DynamicSuite extends FunSuite with DiffAssertions {
check("wrong-version") { f =>
f.setVersion("1.0")
f.assertError(
"error: path/.scalafmt.conf: failed to resolve Scalafmt version '1.0'"
"""|error: path/.scalafmt.conf: org.scalafmt.dynamic.exceptions.ScalafmtException: failed to resolve Scalafmt version '1.0'
|Caused by: org.scalafmt.dynamic.ScalafmtVersion$InvalidVersionException: Invalid scalafmt version 1.0""".stripMargin
)
assert(f.downloadLogs.nonEmpty)
assert(f.downloadLogs.isEmpty)
}

check("sbt") { f =>
Expand Down
14 changes: 14 additions & 0 deletions scalafmt-dynamic/src/test/scala/tests/ScalafmtVersionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class ScalafmtVersionSuite extends FunSuite {
ScalafmtVersion.parse("2.0.0-RC4") == Right(ScalafmtVersion(2, 0, 0, 4))
)
assert(ScalafmtVersion.parse("2.1.1") == Right(ScalafmtVersion(2, 1, 1, 0)))
assert(
ScalafmtVersion
.parse("2.2.3-SNAPSHOT") == Right(ScalafmtVersion(2, 2, 3, 0))
)
assert(
ScalafmtVersion.parse("2.0.0-RC1-SNAPSHOT") == Right(
ScalafmtVersion(2, 0, 0, 1)
)
)
}

test("fail on invalid versions") {
Expand Down Expand Up @@ -51,6 +60,11 @@ class ScalafmtVersionSuite extends FunSuite {
ScalafmtVersion
.parse("2.1.0-RC1-M4") == Left(InvalidVersionException("2.1.0-RC1-M4"))
)
assert(
ScalafmtVersion.parse("2.0.0-RC1+metadata") == Left(
InvalidVersionException("2.0.0-RC1+metadata")
)
)
}

test("order versions") {
Expand Down

0 comments on commit 488ddf2

Please sign in to comment.