mirror of https://github.com/sbt/sbt.git
Merge pull request #258 from xuwei-k/config-macro
fix #134 validate Configuration id
This commit is contained in:
commit
bb2c73e183
|
|
@ -110,6 +110,9 @@ private[sbt] object ConfigurationMacro {
|
|||
c,
|
||||
methodName =>
|
||||
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)))
|
||||
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