1 /* <lambda>null2 * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.atomicfu.plugin.gradle 6 7 import org.gradle.testkit.runner.BuildResult 8 import org.gradle.testkit.runner.TaskOutcome 9 import java.io.File 10 import kotlin.test.assertTrue 11 12 fun BuildResult.checkOutcomes(expected: TaskOutcome, vararg tasks: String) { 13 val unexpectedOutcomes = tasks 14 .map { it to task(it)?.outcome } 15 .filter { (_, outcome) -> outcome != expected } 16 if (unexpectedOutcomes.isNotEmpty()) { 17 throw AssertionError("Unexpected outcomes for tasks." + 18 "\nExpected: $expected." + 19 "\nGot:" + 20 "\n${unexpectedOutcomes.joinToString("\n") { (task, outcome) -> "* $task -> $outcome" }}") 21 22 } 23 } 24 checkExistsnull25fun File.checkExists() { 26 assertTrue(exists(), "File does not exist: $canonicalPath") 27 } 28 modifynull29fun File.modify(fn: (String) -> String) { 30 writeText(fn(readText())) 31 } 32 Stringnull33fun String.checkedReplace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String { 34 check(contains(oldValue, ignoreCase)) { "String must contain '$oldValue'" } 35 return replace(oldValue, newValue, ignoreCase) 36 }