fix KT-9441 Unable to Access Internal Classes from Test Code within Same Module
#KT-9441 Fixed
This commit is contained in:
+15
@@ -134,6 +134,21 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
args.noCallAssertions = kotlinOptions.noCallAssertions
|
||||
args.noParamAssertions = kotlinOptions.noParamAssertions
|
||||
args.moduleName = kotlinOptions.moduleName ?: extraProperties.getOrNull<String>("defaultModuleName")
|
||||
|
||||
if (this.name == "compileTestKotlin") {
|
||||
getLogger().kotlinDebug("try to determine the output directory of corresponding compileKotlin task")
|
||||
val tasks = project.getTasksByName("compileKotlin", false)
|
||||
getLogger().kotlinDebug("tasks for compileKotlin: ${tasks}")
|
||||
if (tasks.size == 1) {
|
||||
val task = tasks.firstOrNull() as? KotlinCompile
|
||||
if (task != null) {
|
||||
getLogger().kotlinDebug("destinantion directory for production = ${task.destinationDir}")
|
||||
args.friendPaths = arrayOf(task.destinationDir.absolutePath)
|
||||
args.moduleName = task.kotlinOptions.moduleName ?: task.extensions.extraProperties.getOrNull<String>("defaultModuleName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getLogger().kotlinDebug("args.moduleName = ${args.moduleName}")
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -90,6 +90,15 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInternalTest() {
|
||||
Project("internalTest", "1.6").build("build") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
assertContains(":compileKotlin", ":compileTestKotlin")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMultiprojectPluginClasspath() {
|
||||
Project("multiprojectClassPathTest", "1.6").build("build") {
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile 'org.testng:testng:6.8'
|
||||
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
test {
|
||||
useTestNG()
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion="1.4"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package demo
|
||||
|
||||
internal val CONST = "CONST"
|
||||
|
||||
class PublicClass {
|
||||
internal fun foo(): String = "foo"
|
||||
internal val bar: String = "bar"
|
||||
}
|
||||
|
||||
internal data class InternalDataClass(val x: Int, val y: Int)
|
||||
|
||||
internal fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package demo
|
||||
|
||||
import org.testng.Assert.*
|
||||
import org.testng.annotations.Test as test
|
||||
|
||||
class TestSource() {
|
||||
@test fun f() {
|
||||
assertEquals("CONST", CONST)
|
||||
|
||||
assertEquals("foo", PublicClass().foo())
|
||||
assertEquals("bar", PublicClass().bar)
|
||||
|
||||
val data = InternalDataClass(10, 20)
|
||||
assertEquals(10, data.x)
|
||||
assertEquals(20, data.y)
|
||||
|
||||
assertEquals(box(), "OK")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-accessToInternal</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>process-test-sources</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
System.out?.println(getGreeting())
|
||||
}
|
||||
|
||||
internal fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
|
||||
internal val CONST = "CONST"
|
||||
|
||||
class PublicClass {
|
||||
internal fun foo(): String = "foo"
|
||||
internal val bar: String = "bar"
|
||||
}
|
||||
|
||||
internal data class InternalDataClass(val x: Int, val y: Int)
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import junit.framework.Assert.assertEquals
|
||||
|
||||
class HelloWorldTest {
|
||||
|
||||
@Test
|
||||
fun greeting() {
|
||||
assertEquals("Hello, World!", getGreeting())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accessToInternal() {
|
||||
assertEquals("CONST", CONST)
|
||||
|
||||
assertEquals("foo", PublicClass().foo())
|
||||
assertEquals("bar", PublicClass().bar)
|
||||
|
||||
val data = InternalDataClass(10, 20)
|
||||
assertEquals(10, data.x)
|
||||
assertEquals(20, data.y)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import java.io.*;
|
||||
|
||||
File file = new File(basedir, "target/test-accessToInternal-0.1-SNAPSHOT.jar");
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
throw new FileNotFoundException("Could not find generated JAR: " + file);
|
||||
}
|
||||
+1
-3
@@ -24,7 +24,6 @@ import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -86,9 +85,8 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
|
||||
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
||||
module = testModule;
|
||||
classpath = testClasspath;
|
||||
arguments.friendPaths = new String[] { output };
|
||||
output = testOutput;
|
||||
moduleName = testModuleName;
|
||||
|
||||
super.configureSpecificCompilerArguments(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user