Add file or directory exists/does not exist assertions.

^KT-45744 In Progress
This commit is contained in:
Yahor Berdnikau
2021-03-16 15:25:16 +01:00
committed by TeamCityServer
parent 710287920b
commit 9e2cdc7337
3 changed files with 57 additions and 3 deletions
@@ -1,5 +1,4 @@
package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.util.modify
import org.junit.Test
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2021 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.
*/
package org.jetbrains.kotlin.gradle.testbase
import java.nio.file.Files
/**
* Asserts file under [pathToFile] relative to the test project exists and is a regular file.
*/
fun TestProject.assertFileExists(
pathToFile: String
) {
val filePath = projectPath.resolve(pathToFile)
assert(Files.exists(filePath)) {
"File '${filePath}' does not exist!"
}
assert(Files.isRegularFile(filePath)) {
"'${filePath}' is not a regular file!"
}
}
/**
* Asserts file under [pathToFile] relative to the test project does not exist.
*/
fun TestProject.assertFileNotExists(
pathToFile: String
) {
val filePath = projectPath.resolve(pathToFile)
assert(!Files.exists(filePath)) {
"File '${filePath}' exists!"
}
}
/**
* Asserts directory under [pathToDir] relative to the test project exists and is a directory.
*/
fun TestProject.assertDirectoryExists(
pathToDir: String
) {
val dirPath = projectPath.resolve(pathToDir)
assert(Files.exists(dirPath)) {
"Directory '${dirPath}' does not exist!"
}
assert(Files.isDirectory(dirPath)) {
"'${dirPath}' is not a directory!"
}
}
@@ -37,7 +37,8 @@ fun KGPBaseTest.project(
val testProject = TestProject(
gradleRunner,
projectName,
buildOptions
buildOptions,
projectPath
)
testProject.test()
return testProject
@@ -74,7 +75,8 @@ fun TestProject.buildAndFail(
class TestProject(
val gradleRunner: GradleRunner,
val projectName: String,
val buildOptions: KGPBaseTest.BuildOptions
val buildOptions: KGPBaseTest.BuildOptions,
val projectPath: Path
)
private fun TestProject.commonBuildSetup(