[gradle-plugin] Fix environment variable tests for Windows
This commit is contained in:
-1
@@ -4,7 +4,6 @@ import org.junit.Rule
|
|||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
|
|
||||||
|
|
||||||
class BaseKonanSpecification extends Specification {
|
class BaseKonanSpecification extends Specification {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
|||||||
+5
-4
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
|||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import spock.lang.Unroll
|
import spock.lang.Unroll
|
||||||
|
|
||||||
|
import static org.jetbrains.kotlin.gradle.plugin.test.KonanProject.escapeBackSlashes
|
||||||
|
|
||||||
class EnvVariableSpecification extends BaseKonanSpecification {
|
class EnvVariableSpecification extends BaseKonanSpecification {
|
||||||
|
|
||||||
@@ -32,12 +33,12 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
|||||||
def project = KonanProject.createEmpty(projectDirectory)
|
def project = KonanProject.createEmpty(projectDirectory)
|
||||||
def runner = project.createRunner()
|
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
|
// 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.
|
// process with custom environment variables and check its exit code.
|
||||||
runner.withArguments("wrapper").build()
|
runner.withArguments("wrapper").build()
|
||||||
|
|
||||||
def classpath = runner.pluginClasspath.collect { "'$it.absolutePath'" }.join(", ")
|
def classpath = runner.pluginClasspath.collect { "'${escapeBackSlashes(it.absolutePath)}'" }.join(", ")
|
||||||
project.buildFile.write("""\
|
project.buildFile.write("""\
|
||||||
buildscript {
|
buildscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -136,9 +137,9 @@ class EnvVariableSpecification extends BaseKonanSpecification {
|
|||||||
doLast {
|
doLast {
|
||||||
konanArtifacts.forEach { artifact ->
|
konanArtifacts.forEach { artifact ->
|
||||||
artifact.forEach {
|
artifact.forEach {
|
||||||
if (it.destinationDir.absolutePath != '$newDestinationPath'){
|
if (it.destinationDir.absolutePath != '${escapeBackSlashes(newDestinationPath)}'){
|
||||||
throw new AssertionError("Unexpected destination dir for \$it.name\\n" +
|
throw new AssertionError("Unexpected destination dir for \$it.name\\n" +
|
||||||
"expected: $newDestinationPath\\n" +
|
"expected: ${escapeBackSlashes(newDestinationPath)}\\n" +
|
||||||
"actual: \$it.destinationDir")
|
"actual: \$it.destinationDir")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -77,7 +77,7 @@ class KonanProject {
|
|||||||
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
|
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
|
||||||
}
|
}
|
||||||
// Escape windows path separator
|
// Escape windows path separator
|
||||||
this.konanHome = konanHomeDir.canonicalPath.replace('\\', '\\\\')
|
this.konanHome = escapeBackSlashes(konanHomeDir.canonicalPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
GradleRunner createRunner(boolean withDebug = true) {
|
GradleRunner createRunner(boolean withDebug = true) {
|
||||||
@@ -220,7 +220,7 @@ class KonanProject {
|
|||||||
* $container.$section.$parameter ${value.canonicalPath.replace(\, \\)}
|
* $container.$section.$parameter ${value.canonicalPath.replace(\, \\)}
|
||||||
*/
|
*/
|
||||||
protected void addSetting(String container, String section, String parameter, File value) {
|
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 */
|
/** Sets the given setting of the given konanArtifact */
|
||||||
@@ -342,4 +342,8 @@ class KonanProject {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String escapeBackSlashes(String value) {
|
||||||
|
return value.replace('\\', '\\\\')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user