diff --git a/compile/src/test/resources/sbt/compiler/javac/hasstaticfinal.java b/compile/src/test/resources/sbt/compiler/javac/hasstaticfinal.java index 00c21740a..818ca5954 100644 --- a/compile/src/test/resources/sbt/compiler/javac/hasstaticfinal.java +++ b/compile/src/test/resources/sbt/compiler/javac/hasstaticfinal.java @@ -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; } diff --git a/compile/src/test/scala/sbt/compiler/javac/JavaCompilerSpec.scala b/compile/src/test/scala/sbt/compiler/javac/JavaCompilerSpec.scala index 6d2494248..6901010e2 100644 --- a/compile/src/test/scala/sbt/compiler/javac/JavaCompilerSpec.scala +++ b/compile/src/test/scala/sbt/compiler/javac/JavaCompilerSpec.scala @@ -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)))