TestGenerationDSL: cleanup code

This commit is contained in:
Dmitry Gridin
2019-08-19 19:55:23 +07:00
parent bddf768d59
commit 65ce4aed1a
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.generators.tests.generator package org.jetbrains.kotlin.generators.tests.generator
@@ -19,7 +8,6 @@ package org.jetbrains.kotlin.generators.tests.generator
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
import java.io.File import java.io.File
import java.lang.IllegalArgumentException
import java.util.* import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
@@ -61,32 +49,38 @@ class TestGroup(private val testsRoot: String, val testDataRoot: String, val tes
filenameStartsLowerCase: Boolean? = null, filenameStartsLowerCase: Boolean? = null,
skipIgnored: Boolean = false skipIgnored: Boolean = false
) { ) {
val rootFile = File(testDataRoot + "/" + relativeRootPath) val rootFile = File("$testDataRoot/$relativeRootPath")
val compiledPattern = Pattern.compile(pattern) val compiledPattern = Pattern.compile(pattern)
val className = testClassName ?: TestGeneratorUtil.fileNameToJavaIdentifier(rootFile) val className = testClassName ?: TestGeneratorUtil.fileNameToJavaIdentifier(rootFile)
testModels.add( testModels.add(
if (singleClass) { if (singleClass) {
if (excludeDirs.isNotEmpty()) error("excludeDirs is unsupported for SingleClassTestModel yet") if (excludeDirs.isNotEmpty()) error("excludeDirs is unsupported for SingleClassTestModel yet")
SingleClassTestModel(rootFile, compiledPattern, filenameStartsLowerCase, testMethod, className, targetBackend, SingleClassTestModel(
skipIgnored, testRunnerMethodName) rootFile, compiledPattern, filenameStartsLowerCase, testMethod, className, targetBackend,
} skipIgnored, testRunnerMethodName
else { )
SimpleTestClassModel(rootFile, recursive, excludeParentDirs, } else {
SimpleTestClassModel(
rootFile, recursive, excludeParentDirs,
compiledPattern, filenameStartsLowerCase, testMethod, className, compiledPattern, filenameStartsLowerCase, testMethod, className,
targetBackend, excludeDirs, skipIgnored, testRunnerMethodName) targetBackend, excludeDirs, skipIgnored, testRunnerMethodName
)
} }
) )
} }
} }
} }
fun testGroup(testsRoot: String, testDataRoot: String, testRunnerMethodName: String = RunTestMethodModel.METHOD_NAME, init: TestGroup.() -> Unit) { fun testGroup(
testsRoot: String,
testDataRoot: String,
testRunnerMethodName: String = RunTestMethodModel.METHOD_NAME,
init: TestGroup.() -> Unit
) {
TestGroup(testsRoot, testDataRoot, testRunnerMethodName).init() TestGroup(testsRoot, testDataRoot, testRunnerMethodName).init()
} }
fun getDefaultSuiteTestClassName(baseTestClassName: String): String { fun getDefaultSuiteTestClassName(baseTestClassName: String): String {
if (!baseTestClassName.startsWith("Abstract")) { require(baseTestClassName.startsWith("Abstract")) { "Doesn't start with \"Abstract\": $baseTestClassName" }
throw IllegalArgumentException("Doesn't start with \"Abstract\": $baseTestClassName")
}
return baseTestClassName.substringAfter("Abstract") + "Generated" return baseTestClassName.substringAfter("Abstract") + "Generated"
} }