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