Add ERRORs check to AbstractOutOfBlockModificationTest

This commit is contained in:
Vladimir Dolzhenko
2019-11-23 23:52:04 +01:00
parent 144f721a44
commit c67222c176
43 changed files with 141 additions and 28 deletions
@@ -12,24 +12,28 @@ import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.test.InTextDirectivesUtils
object DirectiveBasedActionUtils {
fun checkForUnexpectedErrors(file: KtFile) {
fun checkForUnexpectedErrors(file: KtFile, diagnosticsProvider: (KtFile) -> Diagnostics = { it.analyzeWithContent().diagnostics }) {
if (InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// DISABLE-ERRORS").isNotEmpty()) {
return
}
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// ERROR:").sorted()
val actualErrors = file.analyzeWithContent().diagnostics
.filter { it.getSeverity() == Severity.ERROR }
.map { DefaultErrorMessages.render(it).replace("\n", "<br>") }
.sorted()
val diagnostics = diagnosticsProvider(file)
val actualErrors = diagnostics
.filter { it.severity == Severity.ERROR }
.map { DefaultErrorMessages.render(it).replace("\n", "<br>") }
.sorted()
UsefulTestCase.assertOrderedEquals("All actual errors should be mentioned in test data with // ERROR: directive. But no unnecessary errors should be me mentioned",
actualErrors,
expectedErrors)
UsefulTestCase.assertOrderedEquals(
"All actual errors should be mentioned in test data with // ERROR: directive. But no unnecessary errors should be me mentioned",
actualErrors,
expectedErrors
)
}
fun checkAvailableActionsAreExpected(file: PsiFile, availableActions: Collection<IntentionAction>) {