[minor] Fix classpath from class calculation utility for classes dir

This commit is contained in:
Ilya Chernikov
2019-09-17 16:59:31 +02:00
parent 7592048437
commit bda2e46697
2 changed files with 9 additions and 1 deletions
@@ -15,6 +15,7 @@ import java.util.jar.JarEntry
import java.util.jar.JarOutputStream
import java.util.jar.Manifest
import kotlin.script.experimental.jvm.util.classPathFromTypicalResourceUrls
import kotlin.script.experimental.jvm.util.classpathFromClass
import kotlin.script.experimental.jvm.util.classpathFromClassloader
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrNull
@@ -80,6 +81,13 @@ class ClassPathTest : TestCase() {
tempDir.deleteRecursively()
}
}
@Test
fun testClasspathFromClass() {
val cpFromThis = classpathFromClass(this::class)
val expectedSuffix = "classes/kotlin/test"
assertTrue("Path should end with $expectedSuffix, got: $cpFromThis", cpFromThis!!.first().path.endsWith(expectedSuffix))
}
}
private val emulatedCollectionFiles = arrayOf(
@@ -118,7 +118,7 @@ internal fun ClassLoader.rawClassPathFromKeyResourcePath(keyResourcePath: String
keyResourcePathDepth = keyResourcePath.trim('/').count { it == '/' }
}
var root = file
for (i in 1..keyResourcePathDepth) {
for (i in 0..keyResourcePathDepth) {
root = root.parentFile
}
root