mirror of https://github.com/sbt/sbt.git
Add non-string tests
This commit is contained in:
parent
2982018e5a
commit
592b19b35e
|
|
@ -1,4 +1,4 @@
|
|||
public class hasstaticfinal {
|
||||
// the `TEMPLATE` string is replaced with various values during tests
|
||||
public static final String HELLO = "TEMPLATE";
|
||||
// the `TYPE` and `VALUE` strings are replaced with various values during tests
|
||||
public static final TYPE HELLO = VALUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ object JavaCompilerSpec extends Specification {
|
|||
document a java file ${docWorks(forked)}
|
||||
find errors in a java file ${findsDocErrors(forked)}
|
||||
|
||||
Analyzing classes generated by javac should
|
||||
result in matching APIs for stable static-final fields ${analyzeStaticDifference(local, "A", "A")}
|
||||
result in different APIs for changed static-final fields ${analyzeStaticDifference(local, "A", "B")}
|
||||
Analyzing classes generated by javac should result in
|
||||
matching APIs for stable static-final fields ${analyzeStaticDifference("String", "\"A\"", "\"A\"")}
|
||||
different APIs for changed static-final fields ${analyzeStaticDifference("String", "\"A\"", "\"B\"")}
|
||||
"safe" singleton type names ${analyzeStaticDifference("float", "0.123456789f", "0.123456789f")}
|
||||
"""
|
||||
|
||||
def docWorks(compiler: JavaTools) = IO.withTemporaryDirectory { out =>
|
||||
|
|
@ -70,21 +71,23 @@ object JavaCompilerSpec extends Specification {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compiles with the given constant values, and confirms that if the strings are equal, then the
|
||||
* the APIs are equal.
|
||||
* Compiles with the given constant values, and confirms that if the strings mismatch, then the
|
||||
* the APIs mismatch.
|
||||
*/
|
||||
def analyzeStaticDifference(compiler: JavaTools, left: String, right: String) = {
|
||||
def analyzeStaticDifference(typeName: String, left: String, right: String) = {
|
||||
def compileWithPrimitive(templateValue: String) =
|
||||
IO.withTemporaryDirectory { out =>
|
||||
// copy the input file to a temporary location and change the templateValue
|
||||
val input = new File(out, hasStaticFinalFile.getName())
|
||||
IO.writeLines(
|
||||
input,
|
||||
IO.readLines(hasStaticFinalFile).map(_.replace("TEMPLATE", templateValue))
|
||||
IO.readLines(hasStaticFinalFile).map { line =>
|
||||
line.replace("TYPE", typeName).replace("VALUE", templateValue)
|
||||
}
|
||||
)
|
||||
|
||||
// then compile it
|
||||
val (result, problems) = compile(compiler, Seq(input), Seq("-d", out.getAbsolutePath))
|
||||
val (result, problems) = compile(local, Seq(input), Seq("-d", out.getAbsolutePath))
|
||||
val origCompiled = result must beTrue
|
||||
val clazzz = new URLClassLoader(Array(out.toURI.toURL)).loadClass("hasstaticfinal")
|
||||
(origCompiled, ClassToAPI(Seq(clazzz)))
|
||||
|
|
|
|||
Loading…
Reference in New Issue