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