Skip to content

Commit d6a1e30

Browse files
authored
Added a test with a path diversion because of jdk statics (#2067)
1 parent 270ec87 commit d6a1e30

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.utbot.examples.stdlib
2+
3+
import org.junit.jupiter.api.Disabled
4+
import org.junit.jupiter.api.Test
5+
import org.utbot.framework.plugin.api.CodegenLanguage
6+
import org.utbot.framework.plugin.api.util.id
7+
import org.utbot.testcheckers.ge
8+
import org.utbot.testing.FullWithAssumptions
9+
import org.utbot.testing.UtValueTestCaseChecker
10+
import java.io.File
11+
12+
internal class StaticsPathDiversionTest : UtValueTestCaseChecker(
13+
testClass = StaticsPathDiversion::class,
14+
testCodeGeneration = true,
15+
pipelines = listOf(
16+
TestLastStage(CodegenLanguage.JAVA),
17+
TestLastStage(CodegenLanguage.KOTLIN)
18+
)
19+
) {
20+
@Test
21+
@Disabled("See https://github.com/UnitTestBot/UTBotJava/issues/716")
22+
fun testJavaIOFile() {
23+
// TODO Here we have a path diversion example - the static field `java.io.File#separator` is considered as not meaningful,
24+
// so it is not passed to the concrete execution because of absence in the `stateBefore` models.
25+
// So, the symbolic engine has 2 results - true and false, as expected, but the concrete executor may produce 1 or 2,
26+
// depending on the model for the argument of the MUT produced by the solver.
27+
// Such diversion was predicted to some extent - see `org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES`
28+
// and the corresponding issue https://github.com/UnitTestBot/UTBotJava/issues/716
29+
check(
30+
StaticsPathDiversion::separatorEquality,
31+
ge(2), // We cannot guarantee the exact number of branches without minimization
32+
33+
// In the matchers below we check that the symbolic does not change the static field `File.separator` - we should
34+
// change the parameter, not the static field
35+
{ s, separator -> separator == File.separator && s == separator },
36+
{ s, separator -> separator == File.separator && s != separator },
37+
additionalMockAlwaysClasses = setOf(java.io.File::class.id), // From the use-case
38+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
39+
)
40+
}
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.utbot.examples.stdlib;
2+
3+
import org.utbot.api.mock.UtMock;
4+
5+
import java.io.File;
6+
7+
public class StaticsPathDiversion {
8+
@SuppressWarnings({"IfStatementWithIdenticalBranches"})
9+
// In this test we check that the symbolic engine does not change the static field `File.separator`
10+
public String separatorEquality(String s) {
11+
// Ignore this case to make sure we will have not more than 2 executions even without minimization
12+
UtMock.assume(s != null);
13+
14+
// We use if-else here instead of a simple return to get executions for both return values
15+
if (File.separator.equals(s)) {
16+
return File.separator;
17+
} else {
18+
return File.separator;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)