Skip to content

Commit

Permalink
Added tests for transformed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alefedor committed Aug 19, 2020
1 parent 2137074 commit 8b4eab8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #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 : Options<O, *>> O.customize() {
iterations(1)
}

override fun extractState(): Any = canEnterForbiddenBlock
}

internal class CustomException : Throwable()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-
* #%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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #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 extractState(): Any = canEnterForbiddenBlock
}

0 comments on commit 8b4eab8

Please sign in to comment.