GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ToString support for abstract collection using makeSymbolic #391 by CaelmBleidd · Pull Request #402 · UnitTestBot/UTBotJava

ToString support for abstract collection using makeSymbolic #391 #402

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.

Sign up for GitHub

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
CaelmBleidd merged 1 commit into main from caelmbleidd/tostring-for-lists
Jul 4, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

ToString support for abstract collection using makeSymbolic #391 #402

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
9202b80
ToString support for abstract collection using makeSymbolic #391
CaelmBleidd Jul 4, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

13 changes: 13 additions & 0 deletions 13 utbot-framework/src/main/java/org/utbot/engine/overrides/collections/AbstractCollection.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.utbot.engine.overrides.collections;

import org.utbot.api.annotation.UtClassMock;

import static org.utbot.api.mock.UtMock.makeSymbolic;

@UtClassMock(target = java.util.AbstractCollection.class, internalUsage = true)
public abstract class AbstractCollection<E> implements java.util.Collection<E> {
@Override
public String toString() {
return makeSymbolic();
}
}
2 changes: 1 addition & 1 deletion 2 utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtArrayList.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.utbot.engine.overrides.stream.UtStream;

import static org.utbot.api.mock.UtMock.assume;
import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely;
import static org.utbot.engine.ResolverKt.MAX_LIST_SIZE;
import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited;
import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.parameter;
import static org.utbot.engine.overrides.UtOverrideMock.visit;
Expand Down
5 changes: 2 additions & 3 deletions 5 utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashMap.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.jetbrains.annotations.Nullable;

import static org.utbot.api.mock.UtMock.assume;
import static org.utbot.api.mock.UtMock.makeSymbolic;
import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited;
import static org.utbot.engine.overrides.UtOverrideMock.doesntThrow;
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.parameter;
import static org.utbot.engine.overrides.UtOverrideMock.visit;

Expand Down Expand Up @@ -556,8 +556,7 @@ public final boolean remove(Object o) {
// TODO rewrite it JIRA:1604
@Override
public String toString() {
executeConcretely();
return super.toString();
return makeSymbolic();
}

public final class Entry implements Map.Entry<K, V> {
Expand Down
9 changes: 9 additions & 0 deletions 9 utbot-framework/src/main/java/org/utbot/engine/overrides/stream/Arrays.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.utbot.engine.overrides.stream;

import org.utbot.api.annotation.UtClassMock;
import org.utbot.engine.overrides.collections.UtArrayList;

import java.util.List;
import java.util.stream.Stream;

@UtClassMock(target = java.util.Arrays.class, internalUsage = true)
Expand All @@ -16,5 +18,12 @@ public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusi
return new UtStream<>(array, startInclusive, endExclusive);
}

@SuppressWarnings({"unused", "varargs"})
@SafeVarargs
public static <T> List<T> asList(T... a) {
// TODO immutable collection https://github.com/UnitTestBot/UTBotJava/issues/398
return new UtArrayList<>(a);
}

// TODO primitive arrays https://github.com/UnitTestBot/UTBotJava/issues/146
}
17 changes: 12 additions & 5 deletions 17 utbot-framework/src/main/kotlin/org/utbot/engine/CollectionWrappers.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@ abstract class BaseOverriddenWrapper(protected val overriddenClassName: String)
return listOf(GraphResult(method.jimpleBody().graph()))
}

val overriddenMethod = overriddenClass.findMethodOrNull(method.subSignature)

if (overriddenMethod == null) {
// We need to find either an override from the class (for example, implementation
// of the method from the wrapper) or a method from its ancestors.
// Note that the method from the ancestor might have substitutions as well.
// I.e., it is `toString` method for `UtArrayList` that is defined in
// `AbstractCollection` and has its own overridden implementation.
val overriddenMethod = overriddenClass
.findMethodOrNull(method.subSignature)
?.let { typeRegistry.findSubstitutionOrNull(it) ?: it }

return if (overriddenMethod == null) {
// No overridden method has been found, switch to concrete execution
pathLogger.warn("Method ${overriddenClass.name}::${method.subSignature} not found, executing concretely")
return emptyList()
emptyList()
} else {
val jimpleBody = overriddenMethod.jimpleBody()
val graphResult = GraphResult(jimpleBody.graph())
return listOf(graphResult)
listOf(graphResult)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion 3 utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,8 @@ class UtBotSymbolicEngine(
if (methodSignature != makeSymbolicMethod.signature && methodSignature != nonNullableMakeSymbolic.signature) return null

val method = environment.method
val isInternalMock = method.hasInternalMockAnnotation || method.declaringClass.allMethodsAreInternalMocks
val declaringClass = method.declaringClass
val isInternalMock = method.hasInternalMockAnnotation || declaringClass.allMethodsAreInternalMocks || declaringClass.isOverridden
val parameters = resolveParameters(invokeExpr.args, invokeExpr.method.parameterTypes)
val mockMethodResult = mockStaticMethod(invokeExpr.method, parameters)?.single()
?: error("Unsuccessful mock attempt of the `makeSymbolic` method call: $invokeExpr")
Expand Down
4 changes: 4 additions & 0 deletions 4 utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/SootUtils.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import org.utbot.engine.overrides.collections.UtOptional
import org.utbot.engine.overrides.collections.UtOptionalDouble
import org.utbot.engine.overrides.collections.UtOptionalInt
import org.utbot.engine.overrides.collections.UtOptionalLong
import org.utbot.engine.overrides.collections.AbstractCollection
import org.utbot.engine.overrides.stream.Arrays
import org.utbot.engine.overrides.stream.Stream
import org.utbot.engine.overrides.stream.UtStream
import java.io.File
Expand Down Expand Up @@ -91,6 +93,7 @@ private fun addBasicClasses(vararg classes: KClass<*>) {
}

private val classesToLoad = arrayOf(
AbstractCollection::class,
UtMock::class,
UtOverrideMock::class,
UtLogicMock::class,
Expand Down Expand Up @@ -133,6 +136,7 @@ private val classesToLoad = arrayOf(
UtStringBuilder::class,
UtStringBuffer::class,
Stream::class,
Arrays::class,
Collection::class,
List::class,
UtStream::class,
Expand Down
10 changes: 10 additions & 0 deletions 10 utbot-framework/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,14 @@ internal class StringExamplesTest : AbstractTestCaseGeneratorTest(
)
}
}

@Test
fun testListToString() {
check(
StringExamples::listToString,
eq(1),
{ r -> r == "[a, b, c]"},
coverage = DoNotCalculate
)
}
}
6 changes: 6 additions & 0 deletions 6 utbot-sample/src/main/java/org/utbot/examples/strings/StringExamples.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utbot.examples.strings;

import java.util.Arrays;

import static java.lang.Boolean.valueOf;

class IntPair {
Expand Down Expand Up @@ -411,4 +413,8 @@ public String equalsIgnoreCase(String s) {
return "failure";
}
}

public String listToString() {
return Arrays.asList("a", "b", "c").toString();
}
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.