Modify file exists assertion.

Additionally allow to check if file exists in any location, even outside
of the project.

^KT-45745 In Progress
This commit is contained in:
Yahor Berdnikau
2021-06-17 11:52:25 +02:00
parent 18d74e62a6
commit c816d6f2e5
2 changed files with 20 additions and 11 deletions
@@ -20,7 +20,7 @@ class SimpleKotlinGradleIT : KGPBaseTest() {
) {
build("compileDeployKotlin", "build") {
assertOutputContains("Finished executing kotlin compiler using daemon strategy")
assertFileExists("build/reports/tests/test/classes/demo.TestSource.html")
assertFileInProjectExists("build/reports/tests/test/classes/demo.TestSource.html")
assertTasksExecuted(":compileKotlin", ":compileTestKotlin", ":compileDeployKotlin")
}
@@ -87,7 +87,7 @@ class SimpleKotlinGradleIT : KGPBaseTest() {
fun testModuleName(gradleVersion: GradleVersion) {
project("moduleName", gradleVersion) {
build("build") {
assertFileExists("build/classes/kotlin/main/META-INF/FLAG.kotlin_module")
assertFileInProjectExists("build/classes/kotlin/main/META-INF/FLAG.kotlin_module")
assertFileNotExists("build/classes/kotlin/main/META-INF/moduleName.kotlin_module")
assertOutputDoesNotContain("Argument -module-name is passed multiple times")
}
@@ -6,21 +6,30 @@
package org.jetbrains.kotlin.gradle.testbase
import java.nio.file.Files
import java.nio.file.Path
/**
* Asserts file under [file] path exists and is a regular file.
*/
fun TestProject.assertFileExists(
file: Path
) {
assert(Files.exists(file)) {
"File '${file}' does not exist!"
}
assert(Files.isRegularFile(file)) {
"'${file}' is not a regular file!"
}
}
/**
* Asserts file under [pathToFile] relative to the test project exists and is a regular file.
*/
fun TestProject.assertFileExists(
fun TestProject.assertFileInProjectExists(
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!"
}
assertFileExists(projectPath.resolve(pathToFile))
}
/**