1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.tools
import org.junit.*
import org.junit.rules.*
import java.io.*
class CasesPublicAPITest {
companion object {
val visibilities by lazy { readKotlinVisibilities(File(System.getProperty("testCasesDeclarations")!!)) }
val baseClassPaths: List<File> =
System.getProperty("testCasesClassesDirs")
.let { requireNotNull(it) { "Specify testCasesClassesDirs with a system property" } }
.split(File.pathSeparator)
.map { File(it, "cases").canonicalFile }
val baseOutputPath = File("test/cases")
}
@Rule
@JvmField
val testName = TestName()
@Test
fun companions() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun inline() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun interfaces() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun internal() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun java() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun localClasses() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun nestedClasses() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun private() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun protected() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun public() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun special() {
snapshotAPIAndCompare(testName.methodName)
}
@Test
fun whenMappings() {
snapshotAPIAndCompare(testName.methodName)
}
private fun snapshotAPIAndCompare(testClassRelativePath: String) {
val testClassPaths = baseClassPaths.map { it.resolve(testClassRelativePath) }
val testClasses = testClassPaths.flatMap { it.listFiles().orEmpty().asIterable() }
check(testClasses.isNotEmpty()) { "No class files are found in paths: $testClassPaths" }
val testClassStreams = testClasses.asSequence().filter { it.name.endsWith(".class") }.map { it.inputStream() }
val api = getBinaryAPI(testClassStreams, visibilities).filterOutNonPublic()
val target = baseOutputPath.resolve(testClassRelativePath).resolve(testName.methodName + ".txt")
api.dumpAndCompareWith(target)
}
}
|