Skip to content

Commit 598f48a

Browse files
committed
Add tests for checking dependant modules for compiler-tests
1 parent 354db68 commit 598f48a

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2010-2016 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.kotlin.code
18+
19+
import com.intellij.openapi.util.io.FileUtil
20+
import junit.framework.TestCase
21+
import java.io.File
22+
import java.util.*
23+
import java.util.regex.Pattern
24+
25+
class ModulesDependenciesTest : TestCase() {
26+
val COMPILER_TESTS_MODULE_FILE = File("compiler/tests/compiler-tests.iml")
27+
val GENERATORS_MODULE_FILE = File("generators/generators.iml")
28+
val COMPILER_TESTS_JAVA8_MODULE_FILE = File("compiler/tests-java8/compiler-tests-java8.iml")
29+
val NON_COMPILER_TESTS_MODULE_FILE = File("non-compiler-tests/non-compiler-tests.iml")
30+
31+
val COMPILER_TESTS_MODULE_NAME = COMPILER_TESTS_MODULE_FILE.nameWithoutExtension
32+
val MODULES_CAN_DEPEND_ON_COMPILER_TESTS = listOf(COMPILER_TESTS_JAVA8_MODULE_FILE, GENERATORS_MODULE_FILE)
33+
34+
fun testModulesPresent() {
35+
val modules = listOf(
36+
COMPILER_TESTS_MODULE_FILE, GENERATORS_MODULE_FILE, COMPILER_TESTS_JAVA8_MODULE_FILE, NON_COMPILER_TESTS_MODULE_FILE
37+
)
38+
39+
for (module in modules) {
40+
TestCase.assertTrue("Module $module was moved or renamed without update in this test", module.exists())
41+
}
42+
}
43+
44+
fun testNoCompilerModuleReferences() {
45+
val badModulesList = ArrayList<File>()
46+
47+
for (moduleFile in FileUtil.findFilesByMask(Pattern.compile(".+\\.iml"), File("."))) {
48+
if (MODULES_CAN_DEPEND_ON_COMPILER_TESTS.any { FileUtil.isAncestor(it, moduleFile, false) }) continue
49+
50+
val moduleText = moduleFile.readText()
51+
if (moduleText.contains("\"$COMPILER_TESTS_MODULE_NAME\"")) {
52+
badModulesList.add(moduleFile)
53+
}
54+
}
55+
56+
TestCase.assertTrue("Number of modules have dependencies to module $COMPILER_TESTS_MODULE_NAME. Such dependencies can cause multiple " +
57+
"tests execution on teamcity when running configuration with 'Search tests across module dependencies' enabled:\n" +
58+
"${badModulesList.joinToString(separator = "\n")}",
59+
badModulesList.isEmpty())
60+
}
61+
62+
fun testNoBadReferencesInNonCompilerTests() {
63+
val FORBIDDEN_MODULE_NAMES = MODULES_CAN_DEPEND_ON_COMPILER_TESTS.map { it.nameWithoutExtension }
64+
65+
val moduleText = NON_COMPILER_TESTS_MODULE_FILE.readText()
66+
val nonCompilerTestsHasForbiddenDependencies = FORBIDDEN_MODULE_NAMES.none { moduleText.contains(it) }
67+
68+
TestCase.assertTrue("${NON_COMPILER_TESTS_MODULE_FILE.nameWithoutExtension} has a dependency to modules that can depend on " +
69+
"$COMPILER_TESTS_MODULE_NAME module. This can cause multiple execution of compiler tests on teamcity.\n" +
70+
"Check modules:\n${MODULES_CAN_DEPEND_ON_COMPILER_TESTS.joinToString("\n")}",
71+
nonCompilerTestsHasForbiddenDependencies)
72+
}
73+
}

0 commit comments

Comments
 (0)