Skip to content

Introduce utbot-framework-test project #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix compilation
  • Loading branch information
EgorkaKulikov committed Aug 30, 2022
commit 37722790b02d7947feff165925dcdb38c8eedf69
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,17 @@ inline fun <reified T> withoutConcrete(block: () -> T): T {
} finally {
UtSettings.useConcreteExecution = prev
}
}
}

/**
* Run [block] with disabled sandbox in the concrete executor
*/
inline fun <reified T> withoutSandbox(block: () -> T): T {
val prev = UtSettings.disableSandbox
UtSettings.disableSandbox = true
try {
return block()
} finally {
UtSettings.disableSandbox = prev
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import org.utbot.tests.infrastructure.DoNotCalculate
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.examples.withoutSandbox
import org.utbot.framework.codegen.CodeGeneration
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.withoutSandbox

internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCrashExamples::class) {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.utbot.examples.unsafe

import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.withoutSandbox
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.UtValueTestCaseChecker

internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeOperations::class) {
@Test
fun checkGetAddressSizeOrZero() {
withoutSandbox {
check(
UnsafeOperations::getAddressSizeOrZero,
eq(1),
{ r -> r!! > 0 },
// Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0)
// TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807
coverage = DoNotCalculate
)
}
}

@Test
fun checkGetAddressSizeOrZeroWithMocks() {
withoutSandbox {
check(
UnsafeOperations::getAddressSizeOrZero,
eq(1),
{ r -> r!! > 0 },
// Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0)
// TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807
coverage = DoNotCalculate,
mockStrategy = MockStrategyApi.OTHER_CLASSES
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2769,21 +2769,3 @@ inline fun <reified T> withSettingsFromTestFrameworkConfiguration(
TestCodeGeneratorPipeline.currentTestFrameworkConfiguration = previousConfig
}
}






/**
* Run [block] with disabled sandbox in the concrete executor
*/
inline fun <reified T> withoutSandbox(block: () -> T): T {
val prev = UtSettings.disableSandbox
UtSettings.disableSandbox = true
try {
return block()
} finally {
UtSettings.disableSandbox = prev
}
}