buildSrc: Use SourceSet to define test output directory.
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ kotstd/kotstd.iml
|
|||||||
*.kt.S
|
*.kt.S
|
||||||
*.kt.exe
|
*.kt.exe
|
||||||
*.log
|
*.log
|
||||||
**/test-result.md
|
testOutput
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
|
|||||||
@@ -13,7 +13,20 @@ dependencies {
|
|||||||
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
||||||
}
|
}
|
||||||
|
|
||||||
def logFileName = "test-result.md"
|
allprojects {
|
||||||
|
// Root directories for test output (logs, compiled files, statistics etc). Only single path must be in each set.
|
||||||
|
sourceSets {
|
||||||
|
// :backend.native:tests
|
||||||
|
testOutputLocal {
|
||||||
|
output.dir(rootProject.file("testOutput/local"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// :backend.native:tests:external
|
||||||
|
testOutputExternal {
|
||||||
|
output.dir(rootProject.file("testOutput/external"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task regenerate_external_tests() {
|
task regenerate_external_tests() {
|
||||||
doLast {
|
doLast {
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package org.jetbrains.kotlin
|
package org.jetbrains.kotlin
|
||||||
|
|
||||||
import groovy.io.FileType
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter
|
|
||||||
import org.gradle.api.tasks.ParallelizableTask
|
import org.gradle.api.tasks.ParallelizableTask
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.gradle.api.tasks.testing.Test
|
|
||||||
|
|
||||||
abstract class KonanTest extends DefaultTask {
|
abstract class KonanTest extends DefaultTask {
|
||||||
protected String source
|
protected String source
|
||||||
@@ -17,6 +14,8 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
|
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
|
||||||
def stdlibKtBc = new File("${dist.canonicalPath}/lib/stdlib.kt.bc").absolutePath
|
def stdlibKtBc = new File("${dist.canonicalPath}/lib/stdlib.kt.bc").absolutePath
|
||||||
def mainC = 'main.c'
|
def mainC = 'main.c'
|
||||||
|
def outputSourceSetName = "testOutputLocal"
|
||||||
|
String outputDirectory = null
|
||||||
String goldValue = null
|
String goldValue = null
|
||||||
String testData = null
|
String testData = null
|
||||||
List<String> arguments = null
|
List<String> arguments = null
|
||||||
@@ -27,10 +26,25 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
this.enabled = !value
|
this.enabled = !value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uses directory defined in $outputSourceSetName source set.
|
||||||
|
// If such source set doesn't exist, uses temporary directory.
|
||||||
|
public void createOutputDirectory() {
|
||||||
|
if (outputDirectory != null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
def outputSourceSet = project.sourceSets.findByName(getOutputSourceSetName())
|
||||||
|
if (outputSourceSet != null) {
|
||||||
|
outputDirectory = outputSourceSet.output.getDirs().getSingleFile().absolutePath + "/$name"
|
||||||
|
project.file(outputDirectory).mkdirs()
|
||||||
|
} else {
|
||||||
|
outputDirectory = getTemporaryDir().absolutePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public KonanTest(){
|
public KonanTest(){
|
||||||
// TODO: that's a long reach up the project tree.
|
// TODO: that's a long reach up the project tree.
|
||||||
// May be we should reorganize a little.
|
// May be we should reorganize a little.
|
||||||
//dependsOn(project.parent.parent.tasks['dist'])
|
|
||||||
dependsOn(project.rootProject.tasks['dist'])
|
dependsOn(project.rootProject.tasks['dist'])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +79,7 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
|
|
||||||
String buildExePath() {
|
String buildExePath() {
|
||||||
def exeName = project.file(source).name.replace(".kt", ".kt.exe")
|
def exeName = project.file(source).name.replace(".kt", ".kt.exe")
|
||||||
def tempDir = temporaryDir.absolutePath
|
return "$outputDirectory/$exeName"
|
||||||
return "$tempDir/$exeName"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> buildCompileList() {
|
List<String> buildCompileList() {
|
||||||
@@ -75,6 +88,7 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
void executeTest() {
|
void executeTest() {
|
||||||
|
createOutputDirectory()
|
||||||
def exe = buildExePath()
|
def exe = buildExePath()
|
||||||
|
|
||||||
compileTest(buildCompileList(), exe)
|
compileTest(buildCompileList(), exe)
|
||||||
@@ -123,10 +137,11 @@ class LinkKonanTest extends KonanTest {
|
|||||||
class RunExternalTestGroup extends RunKonanTest {
|
class RunExternalTestGroup extends RunKonanTest {
|
||||||
|
|
||||||
def groupDirectory = "."
|
def groupDirectory = "."
|
||||||
def logFileName = "${name}.md"
|
def outputSourceSetName = "testOutputExternal"
|
||||||
String filter = project.findProperty("filter")
|
String filter = project.findProperty("filter")
|
||||||
String goldValue = "OK"
|
String goldValue = "OK"
|
||||||
|
|
||||||
|
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
List<String> buildCompileList() {
|
List<String> buildCompileList() {
|
||||||
def result = []
|
def result = []
|
||||||
@@ -137,15 +152,14 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
def srcFile = project.file(source)
|
def srcFile = project.file(source)
|
||||||
def srcText = srcFile.text
|
def srcText = srcFile.text
|
||||||
def matcher = filePattern.matcher(srcText)
|
def matcher = filePattern.matcher(srcText)
|
||||||
def tmpDir = temporaryDir.absolutePath
|
|
||||||
|
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
// There is only one file in the input
|
// There is only one file in the input
|
||||||
project.copy{
|
project.copy{
|
||||||
from srcFile.absolutePath
|
from srcFile.absolutePath
|
||||||
into tmpDir
|
into outputDirectory
|
||||||
}
|
}
|
||||||
def newFile ="$tmpDir/${srcFile.name}"
|
def newFile ="$outputDirectory/${srcFile.name}"
|
||||||
if (srcText =~ boxPattern && srcText =~ packagePattern){
|
if (srcText =~ boxPattern && srcText =~ packagePattern){
|
||||||
boxPackage = (srcText =~ packagePattern)[0][1]
|
boxPackage = (srcText =~ packagePattern)[0][1]
|
||||||
boxPackage += '.'
|
boxPackage += '.'
|
||||||
@@ -156,7 +170,7 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
def processedChars = 0
|
def processedChars = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
def filePath = matcher.group(1)
|
def filePath = matcher.group(1)
|
||||||
filePath = "$tmpDir/$filePath"
|
filePath = "$outputDirectory/$filePath"
|
||||||
def start = processedChars
|
def start = processedChars
|
||||||
def nextFileExists = matcher.find()
|
def nextFileExists = matcher.find()
|
||||||
def end = nextFileExists ? matcher.start() : srcText.length()
|
def end = nextFileExists ? matcher.start() : srcText.length()
|
||||||
@@ -171,8 +185,8 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
if (!nextFileExists) break
|
if (!nextFileExists) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createLauncherFile("$tmpDir/_launcher.kt", boxPackage)
|
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
||||||
result.add("$tmpDir/_launcher.kt")
|
result.add("$outputDirectory/_launcher.kt")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +230,8 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
@TaskAction
|
@TaskAction
|
||||||
@Override
|
@Override
|
||||||
void executeTest() {
|
void executeTest() {
|
||||||
def logFile = project.file(logFileName)
|
createOutputDirectory()
|
||||||
|
def logFile = project.file("${outputDirectory}/result.md")
|
||||||
logFile.append("\n$groupDirectory\n\n")
|
logFile.append("\n$groupDirectory\n\n")
|
||||||
logFile.append("|Test|Status|Comment|\n|----|------|-------|\n")
|
logFile.append("|Test|Status|Comment|\n|----|------|-------|\n")
|
||||||
def ktFiles = project.file(groupDirectory).listFiles(new FileFilter() {
|
def ktFiles = project.file(groupDirectory).listFiles(new FileFilter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user