Skip to content

Added a test with a path diversion because of jdk statics #2067

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 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.utbot.examples.stdlib

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.framework.plugin.api.util.id
import org.utbot.testcheckers.ge
import org.utbot.testing.FullWithAssumptions
import org.utbot.testing.UtValueTestCaseChecker
import java.io.File

internal class StaticsPathDiversionTest : UtValueTestCaseChecker(
testClass = StaticsPathDiversion::class,
testCodeGeneration = true,
pipelines = listOf(
TestLastStage(CodegenLanguage.JAVA),
TestLastStage(CodegenLanguage.KOTLIN)
)
) {
@Test
@Disabled("See https://github.com/UnitTestBot/UTBotJava/issues/716")
fun testJavaIOFile() {
// TODO Here we have a path diversion example - the static field `java.io.File#separator` is considered as not meaningful,
// so it is not passed to the concrete execution because of absence in the `stateBefore` models.
// So, the symbolic engine has 2 results - true and false, as expected, but the concrete executor may produce 1 or 2,
// depending on the model for the argument of the MUT produced by the solver.
// Such diversion was predicted to some extent - see `org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES`
// and the corresponding issue https://github.com/UnitTestBot/UTBotJava/issues/716
check(
StaticsPathDiversion::separatorEquality,
ge(2), // We cannot guarantee the exact number of branches without minimization

// In the matchers below we check that the symbolic does not change the static field `File.separator` - we should
// change the parameter, not the static field
{ s, separator -> separator == File.separator && s == separator },
{ s, separator -> separator == File.separator && s != separator },
additionalMockAlwaysClasses = setOf(java.io.File::class.id), // From the use-case
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.utbot.examples.stdlib;

import org.utbot.api.mock.UtMock;

import java.io.File;

public class StaticsPathDiversion {
@SuppressWarnings({"IfStatementWithIdenticalBranches"})
// In this test we check that the symbolic engine does not change the static field `File.separator`
public String separatorEquality(String s) {
// Ignore this case to make sure we will have not more than 2 executions even without minimization
UtMock.assume(s != null);

// We use if-else here instead of a simple return to get executions for both return values
if (File.separator.equals(s)) {
return File.separator;
} else {
return File.separator;
}
}
}