- 
                Notifications
    You must be signed in to change notification settings 
- Fork 45
Added simple custom JavaDocs for the tests produced by Fuzzer #1069
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
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fe4c6d1
              
                Added an initial solution
              
              
                amandelpie 20bf0ab
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie b92b198
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie 6ada057
              
                Added a method and class references
              
              
                amandelpie 408e87e
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie a5ca42b
              
                Refactor to avoid bugs with private methods
              
              
                amandelpie bd2fdbb
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie f94554a
              
                Handled empty values
              
              
                amandelpie 326da42
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie 51ca8de
              
                Fixed tests and add a TODO ticket
              
              
                amandelpie 8829071
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie 0a95f29
              
                Fixed review comments
              
              
                amandelpie 92b8da0
              
                Merge remote-tracking branch 'origin/amandelpie/feature-601-2' into a…
              
              
                amandelpie 983fce9
              
                Merge branch 'main' into amandelpie/feature-601-2
              
              
                amandelpie File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
        
          
          
            70 changes: 0 additions & 70 deletions
          
          70 
        
  utbot-summary/src/main/kotlin/org/utbot/summary/comment/CustomJavaDocTagProvider.kt
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
          
            18 changes: 18 additions & 0 deletions
          
          18 
        
  ...n/org/utbot/summary/comment/classic/fuzzer/SimpleCommentForTestProducedByFuzzerBuilder.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 | 
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.utbot.summary.comment.classic.fuzzer | ||
|  | ||
| import org.utbot.framework.plugin.api.DocPreTagStatement | ||
| import org.utbot.framework.plugin.api.DocStatement | ||
| import org.utbot.framework.plugin.api.UtExecutionResult | ||
| import org.utbot.fuzzer.FuzzedMethodDescription | ||
| import org.utbot.fuzzer.FuzzedValue | ||
|  | ||
| // TODO: https://github.com/UnitTestBot/UTBotJava/issues/1127 | ||
| class SimpleCommentForTestProducedByFuzzerBuilder( | ||
| description: FuzzedMethodDescription, | ||
| values: List<FuzzedValue>, | ||
| result: UtExecutionResult? | ||
| ) { | ||
| fun buildDocStatements(): List<DocStatement> { | ||
| return listOf<DocStatement>(DocPreTagStatement(emptyList())) | ||
| } | ||
| } | 
  
    
      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
    
  
  
    
              
            File renamed without changes.
          
    
        
          
          
            5 changes: 3 additions & 2 deletions
          
          5 
        
  ...SymbolicExecutionClusterCommentBuilder.kt → ...SymbolicExecutionClusterCommentBuilder.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
    
  
  
    
              
        
          
          
            106 changes: 106 additions & 0 deletions
          
          106 
        
  ...-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomJavaDocTagProvider.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 | 
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package org.utbot.summary.comment.customtags.symbolic | ||
|  | ||
| import org.utbot.framework.plugin.api.DocRegularStmt | ||
| import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzer | ||
|  | ||
| /** | ||
| * Provides a list of supported custom JavaDoc tags. | ||
| */ | ||
| class CustomJavaDocTagProvider { | ||
| // The tags' order is important because plugin builds final JavaDoc comment according to it. | ||
| fun getPluginCustomTags(): List<CustomJavaDocTag> = | ||
| listOf( | ||
| CustomJavaDocTag.ClassUnderTest, | ||
| CustomJavaDocTag.MethodUnderTest, | ||
| CustomJavaDocTag.ExpectedResult, | ||
| CustomJavaDocTag.ActualResult, | ||
| CustomJavaDocTag.Executes, | ||
| CustomJavaDocTag.Invokes, | ||
| CustomJavaDocTag.Iterates, | ||
| CustomJavaDocTag.SwitchCase, | ||
| CustomJavaDocTag.Recursion, | ||
| CustomJavaDocTag.ReturnsFrom, | ||
| CustomJavaDocTag.CaughtException, | ||
| CustomJavaDocTag.ThrowsException, | ||
| ) | ||
| } | ||
|  | ||
| sealed class CustomJavaDocTag( | ||
| val name: String, | ||
| val message: String, | ||
| private val valueRetriever: (CustomJavaDocComment) -> Any, | ||
| private val valueRetrieverFuzzer: ((CommentWithCustomTagForTestProducedByFuzzer) -> Any)? // TODO: remove after refactoring | ||
| ) { | ||
| object ClassUnderTest : | ||
| CustomJavaDocTag( | ||
| "utbot.classUnderTest", | ||
| "Class under test", | ||
| CustomJavaDocComment::classUnderTest, | ||
| CommentWithCustomTagForTestProducedByFuzzer::classUnderTest | ||
| ) | ||
|  | ||
| object MethodUnderTest : | ||
| CustomJavaDocTag( | ||
| "utbot.methodUnderTest", | ||
| "Method under test", | ||
| CustomJavaDocComment::methodUnderTest, | ||
| CommentWithCustomTagForTestProducedByFuzzer::methodUnderTest | ||
| ) | ||
|  | ||
| object ExpectedResult : | ||
| CustomJavaDocTag("utbot.expectedResult", "Expected result", CustomJavaDocComment::expectedResult, null) | ||
|  | ||
| object ActualResult : | ||
| CustomJavaDocTag("utbot.actualResult", "Actual result", CustomJavaDocComment::actualResult, null) | ||
|  | ||
| object Executes : | ||
| CustomJavaDocTag("utbot.executesCondition", "Executes condition", CustomJavaDocComment::executesCondition, null) | ||
|  | ||
| object Invokes : CustomJavaDocTag("utbot.invokes", "Invokes", CustomJavaDocComment::invokes, null) | ||
| object Iterates : CustomJavaDocTag("utbot.iterates", "Iterates", CustomJavaDocComment::iterates, null) | ||
| object SwitchCase : | ||
| CustomJavaDocTag("utbot.activatesSwitch", "Activates switch", CustomJavaDocComment::switchCase, null) | ||
|  | ||
| object Recursion : | ||
| CustomJavaDocTag("utbot.triggersRecursion", "Triggers recursion ", CustomJavaDocComment::recursion, null) | ||
|  | ||
| object ReturnsFrom : CustomJavaDocTag("utbot.returnsFrom", "Returns from", CustomJavaDocComment::returnsFrom, null) | ||
| object CaughtException : | ||
| CustomJavaDocTag("utbot.caughtException", "Caught exception", CustomJavaDocComment::caughtException, null) | ||
|  | ||
| object ThrowsException : | ||
| CustomJavaDocTag("utbot.throwsException", "Throws exception", CustomJavaDocComment::throwsException, null) | ||
|  | ||
| fun generateDocStatement(comment: CustomJavaDocComment): DocRegularStmt? = | ||
| when (val value = valueRetriever.invoke(comment)) { | ||
| is String -> value.takeIf { it.isNotEmpty() }?.let { | ||
| DocRegularStmt("@$name $value\n") | ||
| } | ||
| is List<*> -> value.takeIf { it.isNotEmpty() }?.let { | ||
| val valueToString = value.joinToString(separator = "\n", postfix = "\n") { "@$name $it" } | ||
|  | ||
| DocRegularStmt(valueToString) | ||
| } | ||
| else -> null | ||
| } | ||
|  | ||
| // TODO: could be universal with the function above after creation of hierarchy data classes related to the comments | ||
| fun generateDocStatementForTestProducedByFuzzer(comment: CommentWithCustomTagForTestProducedByFuzzer): DocRegularStmt? { | ||
| if (valueRetrieverFuzzer != null) { //TODO: it required only when we have two different retrievers | ||
| return when (val value = valueRetrieverFuzzer!!.invoke(comment)) { // TODO: unsafe !! - resolve | ||
| is String -> value.takeIf { it.isNotEmpty() }?.let { | ||
| DocRegularStmt("@$name $value\n") | ||
| } | ||
|  | ||
| is List<*> -> value.takeIf { it.isNotEmpty() }?.let { | ||
| val valueToString = value.joinToString(separator = ",\n", postfix = "\n") | ||
|  | ||
| DocRegularStmt("@$name $valueToString") | ||
| } | ||
|  | ||
| else -> null | ||
| } | ||
| } | ||
| return null | ||
| } | ||
| } | 
        
          
          
            68 changes: 68 additions & 0 deletions
          
          68 
        
  utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomTagsUtil.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 | 
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package org.utbot.summary.comment.customtags | ||
|  | ||
| import org.utbot.framework.plugin.api.ClassId | ||
| import soot.Type | ||
|  | ||
| /** | ||
| * Returns a reference to the invoked method. IDE can't resolve references to private methods in comments, | ||
| * so we add @link tag only if the invoked method is not private. | ||
| * | ||
| * It looks like {@link packageName.className#methodName(type1, type2)}. | ||
| * | ||
| * In case when an enclosing class in nested, we need to replace '$' with '.' | ||
| * to render the reference. | ||
| */ | ||
| fun getMethodReference( | ||
| className: String, | ||
| methodName: String, | ||
| methodParameterTypes: List<Type>, | ||
| isPrivate: Boolean | ||
| ): String { | ||
| val prettyClassName: String = className.replace("$", ".") | ||
|  | ||
| val text = if (methodParameterTypes.isEmpty()) { | ||
| "$prettyClassName#$methodName()" | ||
| } else { | ||
| val methodParametersAsString = methodParameterTypes.joinToString(",") | ||
| "$prettyClassName#$methodName($methodParametersAsString)" | ||
| } | ||
|  | ||
| return if (isPrivate) { | ||
| text | ||
| } else { | ||
| "{@link $text}" | ||
| } | ||
| } | ||
|  | ||
| /** | ||
| * Returns a reference to the class. | ||
| * Replaces '$' with '.' in case a class is nested. | ||
| */ | ||
| fun getClassReference(fullClassName: String): String { | ||
| return "{@link ${fullClassName.replace("$", ".")}}" | ||
| } | ||
|  | ||
| /** | ||
| * Returns a reference to the invoked method. | ||
| * | ||
| * It looks like {@link packageName.className#methodName(type1, type2)}. | ||
| * | ||
| * In case when an enclosing class in nested, we need to replace '$' with '.' | ||
| * to render the reference. | ||
| */ | ||
| fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List<ClassId>, isPrivate: Boolean): String { | ||
| val prettyClassName: String = className.replace("$", ".") | ||
|  | ||
| val text = if (methodParameterTypes.isEmpty()) { | ||
| "$prettyClassName#$methodName()" | ||
| } else { | ||
| val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName } | ||
| "$prettyClassName#$methodName($methodParametersAsString)" | ||
| } | ||
|  | ||
| return if (isPrivate) { | ||
| text | ||
| } else { | ||
| "{@link $text}" | ||
| } | ||
| } | ||
        
          
          
            15 changes: 15 additions & 0 deletions
          
          15 
        
  ...rg/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzer.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 | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.utbot.summary.comment.customtags.fuzzer | ||
|  | ||
| import org.utbot.summary.comment.EMPTY_STRING | ||
|  | ||
| /** | ||
| * Represents a set of plugin's custom JavaDoc tags. | ||
| */ | ||
| data class CommentWithCustomTagForTestProducedByFuzzer( | ||
| val classUnderTest: String = EMPTY_STRING, | ||
| val methodUnderTest: String = EMPTY_STRING, | ||
| val expectedResult: String = EMPTY_STRING, | ||
| val actualResult: String = EMPTY_STRING, | ||
| var returnsFrom: String = EMPTY_STRING, | ||
| var throwsException: String = EMPTY_STRING | ||
| ) | 
      
      Oops, something went wrong.
        
    
  
  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.