Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Fixed the weird logic in the of error messages in SummaryTestCaseGeneratorTest #383#572
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0779b2e
Handled the bad case with the empty paths
amandelpie 6437fea
Improved test messages in the generated meta matchers
amandelpie 493a2d3
Merge branch 'main' into amandelpie/feature_383
amandelpie 07c8e9a
Merge branch 'main' into amandelpie/feature_383
amandelpie File filter
Filter by extension
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
186 changes: 173 additions & 13 deletions
186 utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,6 +25,10 @@ import kotlin.reflect.KFunction3 | ||
| import kotlin.reflect.KFunction4 | ||
| private const val NEW_LINE = "\n" | ||
| private const val POINT_IN_THE_LIST = " * " | ||
| private const val COMMENT_SEPARATOR = "-------------------------------------------------------------" | ||
| @Disabled | ||
| open class SummaryTestCaseGeneratorTest( | ||
| testClass: KClass<*>, | ||
| @@ -120,18 +124,51 @@ open class SummaryTestCaseGeneratorTest( | ||
| return result | ||
| } | ||
| fun List<UtExecution>.checkMatchersWithTextSummary( | ||
| summaryTextKeys: List<String>, | ||
| comments: List<String>, | ||
| ) { | ||
| if (summaryTextKeys.isEmpty()) { | ||
| if (comments.isEmpty()) { | ||
| return | ||
| } | ||
| val notMatchedExecutions = this.filter { execution -> | ||
| summaryTextKeys.none { summaryKey -> val normalize = execution.summary?.toString()?.normalize() | ||
| normalize?.contains(summaryKey.normalize()) == true } | ||
| comments.none { comment -> | ||
| val normalize = execution.summary?.toString()?.normalize() | ||
| normalize?.contains(comment.normalize()) == true | ||
| } | ||
| } | ||
| val notMatchedComments = comments.filter { comment -> | ||
| this.none { execution -> | ||
| val normalize = execution.summary?.toString()?.normalize() | ||
| normalize?.contains(comment.normalize()) == true | ||
| } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty() && notMatchedComments.isEmpty()) { | ||
| buildString { | ||
| if (notMatchedExecutions.isNotEmpty()) { | ||
| append( | ||
| "\nThe following comments were produced by the UTBot, " + | ||
| "but were not found in the list of comments passed in the check() method:\n\n${ | ||
| commentsFromExecutions( | ||
| notMatchedExecutions | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| if (notMatchedComments.isNotEmpty()) { | ||
| append( | ||
| "\nThe following comments were passed in the check() method, " + | ||
amandelpie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "but were not found in the list of comments produced by the UTBot:\n\n${ | ||
| comments( | ||
| notMatchedComments | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched comments ${summaries(notMatchedExecutions)}" } | ||
| } | ||
| fun List<UtExecution>.checkMatchersWithMethodNames( | ||
| @@ -143,7 +180,36 @@ open class SummaryTestCaseGeneratorTest( | ||
| val notMatchedExecutions = this.filter { execution -> | ||
| methodNames.none { methodName -> execution.testMethodName?.equals(methodName) == true } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched test names ${summaries(notMatchedExecutions)}" } | ||
| val notMatchedMethodNames = methodNames.filter { methodName -> | ||
| this.none { execution -> execution.testMethodName?.equals(methodName) == true } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty() && notMatchedMethodNames.isEmpty()) { | ||
| buildString { | ||
| if (notMatchedExecutions.isNotEmpty()) { | ||
| append( | ||
| "\nThe following method names were produced by the UTBot, " + | ||
| "but were not found in the list of method names passed in the check() method:\n\n${ | ||
| methodNamesFromExecutions( | ||
| notMatchedExecutions | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| if (notMatchedMethodNames.isNotEmpty()) { | ||
| append( | ||
| "\nThe following method names were passed in the check() method, " + | ||
| "but were not found in the list of method names produced by the UTBot:\n\n${ | ||
| methodNames( | ||
| notMatchedMethodNames | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| fun List<UtExecution>.checkMatchersWithDisplayNames( | ||
| @@ -155,14 +221,108 @@ open class SummaryTestCaseGeneratorTest( | ||
| val notMatchedExecutions = this.filter { execution -> | ||
| displayNames.none { displayName -> execution.displayName?.equals(displayName) == true } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched display names ${summaries(notMatchedExecutions)}" } | ||
| val notMatchedDisplayNames = displayNames.filter { displayName -> | ||
| this.none { execution -> execution.displayName?.equals(displayName) == true } | ||
| } | ||
| Assertions.assertTrue(notMatchedExecutions.isEmpty() && notMatchedDisplayNames.isEmpty()) { | ||
| buildString { | ||
| if (notMatchedExecutions.isNotEmpty()) { | ||
| append( | ||
| "\nThe following display names were produced by the UTBot, " + | ||
| "but were not found in the list of display names passed in the check() method:\n\n${ | ||
| displayNamesFromExecutions( | ||
| notMatchedExecutions | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| if (notMatchedDisplayNames.isNotEmpty()) { | ||
| append( | ||
| "\nThe following display names were passed in the check() method, " + | ||
| "but were not found in the list of display names produced by the UTBot:\n\n${ | ||
| displayNames( | ||
| notMatchedDisplayNames | ||
| ) | ||
| }" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| private fun summaries(executions: List<UtExecution>): String { | ||
| var result = "" | ||
| executions.forEach { | ||
| result += it.summary?.joinToString(separator = "", postfix = "\n") | ||
| private fun commentsFromExecutions(executions: List<UtExecution>): String { | ||
| return buildString { | ||
| append(COMMENT_SEPARATOR) | ||
| executions.forEach { | ||
| append(NEW_LINE) | ||
| append(NEW_LINE) | ||
| append(it.summary?.joinToString(separator = "", postfix = NEW_LINE)) | ||
| append(COMMENT_SEPARATOR) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| } | ||
| private fun comments(comments: List<String>): String { | ||
| return buildString { | ||
| append(COMMENT_SEPARATOR) | ||
| comments.forEach { | ||
| append(NEW_LINE) | ||
| append(NEW_LINE) | ||
| append(it) | ||
| append(NEW_LINE) | ||
| append(COMMENT_SEPARATOR) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| } | ||
| private fun displayNamesFromExecutions(executions: List<UtExecution>): String { | ||
| return buildString { | ||
| executions.forEach { | ||
| append(POINT_IN_THE_LIST) | ||
| append(it.displayName) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| } | ||
| private fun displayNames(displayNames: List<String>): String { | ||
| return buildString { | ||
| displayNames.forEach { | ||
| append(POINT_IN_THE_LIST) | ||
| append(it) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| } | ||
| private fun methodNamesFromExecutions(executions: List<UtExecution>): String { | ||
| return buildString { | ||
| executions.forEach { | ||
| append(POINT_IN_THE_LIST) | ||
| append(it.testMethodName) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| } | ||
| private fun methodNames(methodNames: List<String>): String { | ||
| return buildString { | ||
| methodNames.forEach { | ||
| append(POINT_IN_THE_LIST) | ||
| append(it) | ||
| append(NEW_LINE) | ||
| } | ||
| append(NEW_LINE) | ||
| } | ||
| return result | ||
| } | ||
| } | ||
6 changes: 3 additions & 3 deletions
6 utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -143,13 +143,13 @@ class SummaryOfMathTest : SummaryTestCaseGeneratorTest( | ||
| "Test then returns from: return acummulator.snapshot();\n" | ||
| val summary6 = "Test calls {@link guava.examples.math.StatsAccumulator#addAll(double[])},\n" + | ||
| " there it iterates the loop for(double value: values) twice,\n" + | ||
| " inside this loop, the test calls StatsAccumulator::add,\n" + | ||
| " inside this loop, the test calls {@link guava.examples.math.StatsAccumulator#add(double)},\n" + | ||
| " there it executes conditions:\n" + | ||
| " (!isFinite(value)): True\n" + | ||
| "Test afterwards calls {@link guava.examples.math.StatsAccumulator#snapshot()},\n" + | ||
| "Test then calls {@link guava.examples.math.StatsAccumulator#snapshot()},\n" + | ||
amandelpie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| " there it returns from: return new Stats(count, mean, sumOfSquaresOfDeltas, min, max);\n" + | ||
| " \n" + | ||
| "Test then returns from: return acummulator.snapshot();\n" | ||
| "Test afterwards returns from: return acummulator.snapshot();\n" | ||
| val summary7 = "Test calls {@link guava.examples.math.StatsAccumulator#addAll(double[])},\n" + | ||
| " there it iterates the loop for(double value: values) twice,\n" + | ||
| " inside this loop, the test calls {@link guava.examples.math.StatsAccumulator#add(double)},\n" + | ||
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.
Uh oh!
There was an error while loading. Please reload this page.