Make IgnoreTests fail correctly when directive is outdated
`Outdated` means green test with `IGNORE_FIR` directive, or red test with `FIR_COMPARISON` directive Also, invoke directive insertion only when it is appropriate
This commit is contained in:
+18
-7
@@ -97,7 +97,7 @@ object IgnoreTests {
|
|||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (testIsEnabled) {
|
if (testIsEnabled) {
|
||||||
if (directive is EnableOrDisableTestDirective.Disable) {
|
if (directive is EnableOrDisableTestDirective.Disable) {
|
||||||
handleTestWithWrongDirective(testFile, directive, directivePosition, additionalFiles)
|
handleTestWithWrongDirective(testPasses = false, testFile, directive, directivePosition, additionalFiles)
|
||||||
}
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
@@ -105,23 +105,33 @@ object IgnoreTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!testIsEnabled) {
|
if (!testIsEnabled) {
|
||||||
handleTestWithWrongDirective(testFile, directive, directivePosition, additionalFiles)
|
handleTestWithWrongDirective(testPasses = true, testFile, directive, directivePosition, additionalFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
private fun handleTestWithWrongDirective(
|
private fun handleTestWithWrongDirective(
|
||||||
|
testPasses: Boolean,
|
||||||
testFile: Path,
|
testFile: Path,
|
||||||
directive: EnableOrDisableTestDirective,
|
directive: EnableOrDisableTestDirective,
|
||||||
directivePosition: DirectivePosition,
|
directivePosition: DirectivePosition,
|
||||||
additionalFiles: List<Path>,
|
additionalFiles: List<Path>,
|
||||||
) {
|
) {
|
||||||
val verb = when (directive) {
|
val verb = when (testPasses) {
|
||||||
is EnableOrDisableTestDirective.Disable -> "do not pass"
|
false -> "do not pass"
|
||||||
is EnableOrDisableTestDirective.Enable -> "passes"
|
true -> "passes"
|
||||||
}
|
}
|
||||||
if (INSERT_DIRECTIVE_AUTOMATICALLY) {
|
|
||||||
|
val directiveIsOutdated = when {
|
||||||
|
!testPasses && directive is EnableOrDisableTestDirective.Enable -> true
|
||||||
|
testPasses && directive is EnableOrDisableTestDirective.Disable -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
val directiveIsMissing = !directiveIsOutdated
|
||||||
|
|
||||||
|
if (directiveIsMissing && INSERT_DIRECTIVE_AUTOMATICALLY) {
|
||||||
testFile.insertDirectivesToFileAndAdditionalFile(directive, additionalFiles, directivePosition)
|
testFile.insertDirectivesToFileAndAdditionalFile(directive, additionalFiles, directivePosition)
|
||||||
val filesWithDirectiveAdded = buildList {
|
val filesWithDirectiveAdded = buildList {
|
||||||
add(testFile.fileName.toString())
|
add(testFile.fileName.toString())
|
||||||
@@ -131,7 +141,8 @@ object IgnoreTests {
|
|||||||
"Looks like the test $verb, ${directive.directiveText} was added to the ${filesWithDirectiveAdded.joinToString()}"
|
"Looks like the test $verb, ${directive.directiveText} was added to the ${filesWithDirectiveAdded.joinToString()}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (directive is EnableOrDisableTestDirective.Enable) {
|
|
||||||
|
if (directiveIsOutdated) {
|
||||||
throw AssertionError(
|
throw AssertionError(
|
||||||
"Looks like the test $verb, please ${directive.fixDirectiveMessage} the ${testFile.fileName}"
|
"Looks like the test $verb, please ${directive.fixDirectiveMessage} the ${testFile.fileName}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user