[gradle-plugin] Fix environment variable tests for Windows

This commit is contained in:
Ilya Matveev
2018-03-05 14:19:39 +03:00
committed by ilmat192
parent b20fdb0a0d
commit 763592fe03
3 changed files with 11 additions and 7 deletions
@@ -4,7 +4,6 @@ import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
class BaseKonanSpecification extends Specification {
@Rule
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import spock.lang.Unroll
import static org.jetbrains.kotlin.gradle.plugin.test.KonanProject.escapeBackSlashes
class EnvVariableSpecification extends BaseKonanSpecification {
@@ -32,12 +33,12 @@ class EnvVariableSpecification extends BaseKonanSpecification {
def project = KonanProject.createEmpty(projectDirectory)
def runner = project.createRunner()
// Gradle TestKid doesn't support setting environment variables for runners.
// Gradle TestKit doesn't support setting environment variables for runners.
// So we use the following hack: we create a gradle wrapper, start it as a separate
// process with custom environment variables and check its exit code.
runner.withArguments("wrapper").build()
def classpath = runner.pluginClasspath.collect { "'$it.absolutePath'" }.join(", ")
def classpath = runner.pluginClasspath.collect { "'${escapeBackSlashes(it.absolutePath)}'" }.join(", ")
project.buildFile.write("""\
buildscript {
dependencies {
@@ -136,9 +137,9 @@ class EnvVariableSpecification extends BaseKonanSpecification {
doLast {
konanArtifacts.forEach { artifact ->
artifact.forEach {
if (it.destinationDir.absolutePath != '$newDestinationPath'){
if (it.destinationDir.absolutePath != '${escapeBackSlashes(newDestinationPath)}'){
throw new AssertionError("Unexpected destination dir for \$it.name\\n" +
"expected: $newDestinationPath\\n" +
"expected: ${escapeBackSlashes(newDestinationPath)}\\n" +
"actual: \$it.destinationDir")
}
}
@@ -77,7 +77,7 @@ class KonanProject {
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
}
// Escape windows path separator
this.konanHome = konanHomeDir.canonicalPath.replace('\\', '\\\\')
this.konanHome = escapeBackSlashes(konanHomeDir.canonicalPath)
}
GradleRunner createRunner(boolean withDebug = true) {
@@ -220,7 +220,7 @@ class KonanProject {
* $container.$section.$parameter ${value.canonicalPath.replace(\, \\)}
*/
protected void addSetting(String container, String section, String parameter, File value) {
addSetting(container, section, parameter, "'${value.canonicalPath.replace('\\', '\\\\')}'")
addSetting(container, section, parameter, "'${escapeBackSlashes(value.canonicalPath)}'")
}
/** Sets the given setting of the given konanArtifact */
@@ -342,4 +342,8 @@ class KonanProject {
return result
}
static String escapeBackSlashes(String value) {
return value.replace('\\', '\\\\')
}
}