From 0963bd25a860e97a4b387c2871a5d495257bf4e5 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 14 Feb 2023 12:53:43 +0100 Subject: [PATCH] Test links reference existing files --- license/README.md | 2 +- .../jetbrains/kotlin/code/LicensesTests.kt | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/license/README.md b/license/README.md index 5158863fa87..57715b9c906 100644 --- a/license/README.md +++ b/license/README.md @@ -94,7 +94,7 @@ the Kotlin IntelliJ IDEA plugin: - Origin: Derived from boost special math functions, Copyright Eric Ford & Hubert Holin 2001. - 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 - Path: plugins/lint/android-annotations diff --git a/repo/codebase-tests/tests/org/jetbrains/kotlin/code/LicensesTests.kt b/repo/codebase-tests/tests/org/jetbrains/kotlin/code/LicensesTests.kt index d75f86da803..dd88631ce86 100644 --- a/repo/codebase-tests/tests/org/jetbrains/kotlin/code/LicensesTests.kt +++ b/repo/codebase-tests/tests/org/jetbrains/kotlin/code/LicensesTests.kt @@ -5,23 +5,25 @@ package org.jetbrains.kotlin.code -import junit.framework.TestCase import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase +import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase.assertEmpty import org.junit.Test import java.io.File class LicensesTests { + companion object { + private const val licenseReadmePath = "license/README.md" + } + @Test fun testLinksDefinitions() { - val licenseDir = File("license") - val linkDefinitionRegExp = Regex(pattern = "\\[(\\w+)]:.+") val linkRegExp = Regex(pattern = "]\\s?\\[(\\w+)]") val linksUsages = mutableSetOf() val linksDefinitions = mutableSetOf() - val readmeFile = File(licenseDir, "README.md") + val readmeFile = File(licenseReadmePath) readmeFile.useLines { lineSequence -> lineSequence.forEach { line -> val definitionMatch = linkDefinitionRegExp.matchEntire(line) @@ -39,4 +41,18 @@ class LicensesTests { 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) + } } \ No newline at end of file