Skip to content

Commit

Permalink
buildSrc: Use SourceSet to define test output directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmat192 committed Jan 25, 2017
1 parent 99a962d commit a4c4b1e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kotstd/kotstd.iml
*.kt.S
*.kt.exe
*.log
**/test-result.md
testOutput

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
15 changes: 14 additions & 1 deletion backend.native/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ dependencies {
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() {
doLast {
Expand Down
43 changes: 29 additions & 14 deletions buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.jetbrains.kotlin

import groovy.io.FileType
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.TaskAction
import org.gradle.api.tasks.testing.Test

abstract class KonanTest extends DefaultTask {
protected String source
Expand All @@ -17,6 +14,8 @@ abstract class KonanTest extends DefaultTask {
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
def stdlibKtBc = new File("${dist.canonicalPath}/lib/stdlib.kt.bc").absolutePath
def mainC = 'main.c'
def outputSourceSetName = "testOutputLocal"
String outputDirectory = null
String goldValue = null
String testData = null
List<String> arguments = null
Expand All @@ -27,10 +26,25 @@ abstract class KonanTest extends DefaultTask {
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(){
// TODO: that's a long reach up the project tree.
// May be we should reorganize a little.
//dependsOn(project.parent.parent.tasks['dist'])
dependsOn(project.rootProject.tasks['dist'])
}

Expand Down Expand Up @@ -65,8 +79,7 @@ abstract class KonanTest extends DefaultTask {

String buildExePath() {
def exeName = project.file(source).name.replace(".kt", ".kt.exe")
def tempDir = temporaryDir.absolutePath
return "$tempDir/$exeName"
return "$outputDirectory/$exeName"
}

List<String> buildCompileList() {
Expand All @@ -75,6 +88,7 @@ abstract class KonanTest extends DefaultTask {

@TaskAction
void executeTest() {
createOutputDirectory()
def exe = buildExePath()

compileTest(buildCompileList(), exe)
Expand Down Expand Up @@ -123,10 +137,11 @@ class LinkKonanTest extends KonanTest {
class RunExternalTestGroup extends RunKonanTest {

def groupDirectory = "."
def logFileName = "${name}.md"
def outputSourceSetName = "testOutputExternal"
String filter = project.findProperty("filter")
String goldValue = "OK"


// TODO refactor
List<String> buildCompileList() {
def result = []
Expand All @@ -137,15 +152,14 @@ class RunExternalTestGroup extends RunKonanTest {
def srcFile = project.file(source)
def srcText = srcFile.text
def matcher = filePattern.matcher(srcText)
def tmpDir = temporaryDir.absolutePath

if (!matcher.find()) {
// There is only one file in the input
project.copy{
from srcFile.absolutePath
into tmpDir
into outputDirectory
}
def newFile ="$tmpDir/${srcFile.name}"
def newFile ="$outputDirectory/${srcFile.name}"
if (srcText =~ boxPattern && srcText =~ packagePattern){
boxPackage = (srcText =~ packagePattern)[0][1]
boxPackage += '.'
Expand All @@ -156,7 +170,7 @@ class RunExternalTestGroup extends RunKonanTest {
def processedChars = 0
while (true) {
def filePath = matcher.group(1)
filePath = "$tmpDir/$filePath"
filePath = "$outputDirectory/$filePath"
def start = processedChars
def nextFileExists = matcher.find()
def end = nextFileExists ? matcher.start() : srcText.length()
Expand All @@ -171,8 +185,8 @@ class RunExternalTestGroup extends RunKonanTest {
if (!nextFileExists) break
}
}
createLauncherFile("$tmpDir/_launcher.kt", boxPackage)
result.add("$tmpDir/_launcher.kt")
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
result.add("$outputDirectory/_launcher.kt")
return result
}

Expand Down Expand Up @@ -216,7 +230,8 @@ class RunExternalTestGroup extends RunKonanTest {
@TaskAction
@Override
void executeTest() {
def logFile = project.file(logFileName)
createOutputDirectory()
def logFile = project.file("${outputDirectory}/result.md")
logFile.append("\n$groupDirectory\n\n")
logFile.append("|Test|Status|Comment|\n|----|------|-------|\n")
def ktFiles = project.file(groupDirectory).listFiles(new FileFilter() {
Expand Down

0 comments on commit a4c4b1e

Please sign in to comment.