From 5a6a5ac7e435a9b3e411a7fa8b97403b4817ab54 Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Wed, 19 Aug 2020 21:07:33 +0300 Subject: [PATCH] Added tests for transformed exceptions --- .../ExpectedTransformedExceptionTest.kt | 46 +++++++++++++++++ .../UnexpectedTransformedExceptionTest.kt | 49 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/ExpectedTransformedExceptionTest.kt create mode 100644 src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/UnexpectedTransformedExceptionTest.kt diff --git a/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/ExpectedTransformedExceptionTest.kt b/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/ExpectedTransformedExceptionTest.kt new file mode 100644 index 0000000000..fe6199a2a4 --- /dev/null +++ b/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/ExpectedTransformedExceptionTest.kt @@ -0,0 +1,46 @@ +/*- + * #%L + * Lincheck + * %% + * Copyright (C) 2019 - 2020 JetBrains s.r.o. + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +package org.jetbrains.kotlinx.lincheck.test.transformation + +import org.jetbrains.kotlinx.lincheck.Options +import org.jetbrains.kotlinx.lincheck.annotations.Operation +import org.jetbrains.kotlinx.lincheck.test.AbstractLincheckTest + +class ExpectedTransformedExceptionTest : AbstractLincheckTest() { + var canEnterForbiddenBlock = false + + @Operation(handleExceptionsAsResult = [CustomException::class]) + fun operation() { + canEnterForbiddenBlock = true + canEnterForbiddenBlock = false + if (canEnterForbiddenBlock) + throw CustomException() + } + + override fun > O.customize() { + iterations(1) + } + + override fun extractState(): Any = canEnterForbiddenBlock +} + +internal class CustomException : Throwable() diff --git a/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/UnexpectedTransformedExceptionTest.kt b/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/UnexpectedTransformedExceptionTest.kt new file mode 100644 index 0000000000..286ca33307 --- /dev/null +++ b/src/test/java/org/jetbrains/kotlinx/lincheck/test/transformation/UnexpectedTransformedExceptionTest.kt @@ -0,0 +1,49 @@ +/*- + * #%L + * Lincheck + * %% + * Copyright (C) 2019 - 2020 JetBrains s.r.o. + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ +package org.jetbrains.kotlinx.lincheck.test.transformation + +import org.jetbrains.kotlinx.lincheck.Options +import org.jetbrains.kotlinx.lincheck.annotations.Operation +import org.jetbrains.kotlinx.lincheck.consumeCPU +import org.jetbrains.kotlinx.lincheck.strategy.UnexpectedExceptionFailure +import org.jetbrains.kotlinx.lincheck.test.AbstractLincheckTest + +class UnexpectedTransformedExceptionTest : AbstractLincheckTest(UnexpectedExceptionFailure::class) { + @Volatile + var canEnterForbiddenBlock = false + + @Operation + fun operation(): Int { + canEnterForbiddenBlock = true + consumeCPU(2000) + canEnterForbiddenBlock = false + if (canEnterForbiddenBlock) + throw CustomException() + return 0 + } + + override fun > O.customize() { + iterations(10) + } + + override fun extractState(): Any = canEnterForbiddenBlock +}