Test links reference existing files

This commit is contained in:
Nikolay Krasko
2023-02-14 12:53:43 +01:00
committed by teamcity
parent 3c6e64b560
commit 0963bd25a8
2 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ the Kotlin IntelliJ IDEA plugin:
- Origin: Derived from boost special math functions, Copyright Eric Ford & Hubert Holin 2001. - Origin: Derived from boost special math functions, Copyright Eric Ford & Hubert Holin 2001.
- Path: libraries/stdlib/wasm/internal/kotlin/wasm/internal/Number2String.kt - Path: libraries/stdlib/wasm/internal/kotlin/wasm/internal/Number2String.kt
- License: Apache 2 ([third_party/assemblyscript_license.txt][assemblyscript]) - License: Apache 2 ([license/third_party/assemblyscript_license.txt][assemblyscript])
- Origin: Derived from assemblyscript standard library - Origin: Derived from assemblyscript standard library
- Path: plugins/lint/android-annotations - Path: plugins/lint/android-annotations
@@ -5,23 +5,25 @@
package org.jetbrains.kotlin.code package org.jetbrains.kotlin.code
import junit.framework.TestCase
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase.assertEmpty
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
class LicensesTests { class LicensesTests {
companion object {
private const val licenseReadmePath = "license/README.md"
}
@Test @Test
fun testLinksDefinitions() { fun testLinksDefinitions() {
val licenseDir = File("license")
val linkDefinitionRegExp = Regex(pattern = "\\[(\\w+)]:.+") val linkDefinitionRegExp = Regex(pattern = "\\[(\\w+)]:.+")
val linkRegExp = Regex(pattern = "]\\s?\\[(\\w+)]") val linkRegExp = Regex(pattern = "]\\s?\\[(\\w+)]")
val linksUsages = mutableSetOf<String>() val linksUsages = mutableSetOf<String>()
val linksDefinitions = mutableSetOf<String>() val linksDefinitions = mutableSetOf<String>()
val readmeFile = File(licenseDir, "README.md") val readmeFile = File(licenseReadmePath)
readmeFile.useLines { lineSequence -> readmeFile.useLines { lineSequence ->
lineSequence.forEach { line -> lineSequence.forEach { line ->
val definitionMatch = linkDefinitionRegExp.matchEntire(line) val definitionMatch = linkDefinitionRegExp.matchEntire(line)
@@ -39,4 +41,18 @@ class LicensesTests {
linksDefinitions.sorted() linksDefinitions.sorted()
) )
} }
@Test
fun testLicensesAreExistingFiles() {
val licenseReferenceRegexp = Regex("\\[([^]]*third_party/[^]]*\\.txt)]")
val readmeFile = File(licenseReadmePath)
val linkedInReadme = readmeFile.useLines { lineSequence ->
lineSequence.flatMap { line ->
licenseReferenceRegexp.findAll(line).map { it.groups[1]?.value ?: error("Should be present because of match") }
}.toSet()
}
val missingFiles = linkedInReadme.filterNot { path -> File(path).exists() }
assertEmpty("Files for licenses are missing", missingFiles)
}
} }