Add tests for 'jdk' compiler option for CLI, maven and gradle.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
$TESTDATA_DIR$/simple.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-jdk
|
||||
$TESTDATA_DIR$
|
||||
-no-jdk
|
||||
@@ -0,0 +1,2 @@
|
||||
warning: the '-jdk' option with a path to JDK is ignored because '-no-jdk' is specified
|
||||
OK
|
||||
@@ -265,6 +265,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("warningJdkWithNoJdk.args")
|
||||
public void testWarningJdkWithNoJdk() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningJdkWithNoJdk.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("warningsInDummy.args")
|
||||
public void testWarningsInDummy() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/warningsInDummy.args");
|
||||
|
||||
+9
@@ -107,6 +107,15 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCustomJdk() {
|
||||
Project("customJdk", "1.6").build("build") {
|
||||
assertFailed()
|
||||
assertContains("Unresolved reference: stream")
|
||||
assertNotContains("AutoCloseable")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGradleSubplugin() {
|
||||
val project = Project("kotlinGradleSubplugin", "1.6")
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
srcDir 'src'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.jdk = System.getenv("JDK_17")
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = "1.4"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// available in JDK 1.7
|
||||
fun java.lang.AutoCloseable.silentClose() {
|
||||
|
||||
}
|
||||
|
||||
// available in JDK 1.8, should be an error with JDK 1.7
|
||||
fun <T> java.util.stream.Stream<T>.count(): Int {
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
invoker.buildResult = failure
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>test-customJdk</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<kotlin.compiler.jdk>${env.JDK_18}</kotlin.compiler.jdk>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
// available in JDK 1.7
|
||||
fun java.lang.AutoCloseable.silentClose() {
|
||||
|
||||
}
|
||||
|
||||
// available in JDK 1.8, should be an error with JDK 1.7
|
||||
fun <T> java.util.stream.Stream<T>.count(): Int {
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath());
|
||||
|
||||
assertBuildLogHasLine("[INFO] BUILD FAILURE");
|
||||
assertBuildLogHasNoLineThatContains("AutoCloseable");
|
||||
assertBuildLogHasLineThatContains("Unresolved reference: stream");
|
||||
@@ -1,38 +1,50 @@
|
||||
File buildLog = new File(basedir, "build.log");
|
||||
String[] getBuildLogLines() {
|
||||
File buildLog = new File(basedir, "build.log");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(buildLog));
|
||||
List result = new ArrayList();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null){
|
||||
line=line.replaceAll("\\u001b[^m]*m","");
|
||||
result.add(line);
|
||||
}
|
||||
reader.close();
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
|
||||
String[] buildLog = getBuildLogLines();
|
||||
|
||||
|
||||
void assertBuildLogHasLine(String expectedLine) {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(buildLog));
|
||||
try {
|
||||
String line;
|
||||
int i = 0;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.replaceAll("\\u001b[^m]*m", "");
|
||||
i++;
|
||||
if (line.equals(expectedLine)) {
|
||||
print("Expected line was found at line " + i + " of build log: " + "\"" + expectedLine + "\"");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < buildLog.length; i++) {
|
||||
String line = buildLog[i];
|
||||
if (line.equals(expectedLine)) {
|
||||
print("Expected line was found at line " + i + " of build log: " + "\"" + expectedLine + "\"");
|
||||
return;
|
||||
}
|
||||
throw new Exception("Expected build log to contain line: \"" + expectedLine + "\"");
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
throw new Exception("Expected build log to contain line: \"" + expectedLine + "\"");
|
||||
}
|
||||
|
||||
void assertBuildLogHasLineThatContains(String content) {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(buildLog));
|
||||
try {
|
||||
String line;
|
||||
int i = 0;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
i++;
|
||||
if (line.contains(content)) {
|
||||
print("Expected content " + "\"" + content + "\"" + " was found at line " + i + " of build log: " + "\"" + line + "\"");
|
||||
return;
|
||||
}
|
||||
}
|
||||
int line = findBuildLogLineThatContains(content);
|
||||
if (line >= 0)
|
||||
print("Expected content " + "\"" + content + "\"" + " was found at line " + (line+1) + " of build log: " + "\"" + buildLog[line] + "\"");
|
||||
else
|
||||
throw new Exception("Expected build log to contain: \"" + content + "\"");
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
void assertBuildLogHasNoLineThatContains(String content) {
|
||||
int line = findBuildLogLineThatContains(content);
|
||||
if (line >= 0)
|
||||
throw new Exception("Expected build log not to contain content " + "\"" + content + "\"" + ", but was found at line " + (line+1) + ": " + "\"" + buildLog[line] + "\"");
|
||||
}
|
||||
|
||||
int findBuildLogLineThatContains(String content) {
|
||||
for (int i = 0; i < buildLog.length; i++) {
|
||||
String line = buildLog[i];
|
||||
if (line.contains(content)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user