mirror of https://github.com/sbt/sbt.git
fix #134 validate Configuration id
This commit is contained in:
parent
3fcc9e3629
commit
326342cf32
|
|
@ -110,6 +110,9 @@ private[sbt] object ConfigurationMacro {
|
||||||
c,
|
c,
|
||||||
methodName =>
|
methodName =>
|
||||||
s"""$methodName must be directly assigned to a val, such as `val Tooling = $methodName("tooling")`.""")
|
s"""$methodName must be directly assigned to a val, such as `val Tooling = $methodName("tooling")`.""")
|
||||||
|
if (enclosingValName.head.isLower) {
|
||||||
|
c.error(c.enclosingPosition, "configuration id must be capitalized")
|
||||||
|
}
|
||||||
val id = c.Expr[String](Literal(Constant(enclosingValName)))
|
val id = c.Expr[String](Literal(Constant(enclosingValName)))
|
||||||
reify { Configuration.of(id.splice, name.splice) }
|
reify { Configuration.of(id.splice, name.splice) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package sbt.librarymanagement
|
||||||
|
|
||||||
|
import sbt.librarymanagement.Configurations.config
|
||||||
|
import org.scalatest._
|
||||||
|
|
||||||
|
class ConfigMacroTest extends FunSpec with Matchers {
|
||||||
|
describe("Configurations.config") {
|
||||||
|
it("should validate the ID in compile time") {
|
||||||
|
"""val A = config("a")""" should compile
|
||||||
|
"""val b = config("b")""" shouldNot compile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue