Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to test scalafmt local snapshot build #1552

Merged
merged 3 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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