Skip to content

Allow to use JAR files in classpatch during CLI test generation #2343

Open
@tyuldashev

Description

@tyuldashev

Description

Currently when using CLI UTBot user has to specify folder which contains compiled classes of app under test. It would be convenient if it also accept JAR files. Currently it cannot and fails with error (see the exception and steps to reproduce at the end of the issue).

Example: I'm running UTBot over public libraries like Guava, which have source code and compiled JAR available, but compilation process could be cumbersome and time consuming, so it would be helpful if I can supply JAR directly to the UTBot.

Expected behavior

--classpath (-cp) accepts path to JAR files.

Potential alternatives

Currently I have to manually unzip JAR file and point UTBot to folder with unpacked classes.

Steps to reproduce

  1. Download UTBot CLI, use this action to build it if needed - https://github.com/UnitTestBot/UTBotJava/actions/workflows/publish-cli-from-branch.yml
  2. Download and unpack attached project, it contains one source file and JAR build from that source calc.zip
  3. Run CLI with command /java -jar utbot-cli-pele-2023.6.1.jar generate --classpath ./calc.jar --source ./Calc.java --output ./test/Calc.java org.test.Calc
  4. Exception is thrown (Ubuntu)
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
16:54:32.050 | ERROR | withUtContext | java.lang.RuntimeException: java.lang.RuntimeException: java.nio.file.NoSuchFileException: /home/utbot/jazzer/pdfbox/utbot/file
16:54:32.054 | ERROR | GenerateTestsCommand | An error has occurred while generating test for snippet org.test.Calc : java.lang.RuntimeException: java.lang.RuntimeException: java.nio.file.NoSuchFileException: /home/utbot/jazzer/pdfbox/utbot/file
java.lang.RuntimeException: java.lang.RuntimeException: java.nio.file.NoSuchFileException: /home/utbot/jazzer/pdfbox/utbot/file
        at soot.asm.AllInMemoryClassProvider.<init>(AllInMemoryClassProvider.java:61)
        at soot.SourceLocator.setupClassProviders(SourceLocator.java:272)
        at soot.SourceLocator.getClassSource(SourceLocator.java:214)
        at soot.Scene.tryLoadClass(Scene.java:978)
        at soot.Scene.loadBasicClasses(Scene.java:1830)
        at soot.Scene.loadNecessaryClasses(Scene.java:1949)
        at org.utbot.framework.util.SootUtilsKt.initSoot(SootUtils.kt:90)
        at org.utbot.framework.util.SootUtilsKt.access$initSoot(SootUtils.kt:1)
        at org.utbot.framework.util.SootUtils.runSoot(SootUtils.kt:45)
        at org.utbot.framework.plugin.api.TestCaseGenerator.<init>(TestCaseGenerator.kt:107)
        at org.utbot.framework.plugin.api.TestCaseGenerator.<init>(TestCaseGenerator.kt:62)
        at org.utbot.cli.GenerateTestsAbstractCommand.initializeGenerator(GenerateTestsAbstractCommand.kt:201)
        at org.utbot.cli.GenerateTestsCommand.run(GenerateTestsCommand.kt:105)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:204)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:213)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:17)
        at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:396)
        at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:393)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:411)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:436)
        at org.utbot.cli.ApplicationKt.main(Application.kt:31)
Caused by: java.lang.RuntimeException: java.nio.file.NoSuchFileException: /home/utbot/jazzer/pdfbox/utbot/file
        at soot.asm.AllInMemoryClassProvider.loadDir(AllInMemoryClassProvider.java:108)
        at soot.asm.AllInMemoryClassProvider.load(AllInMemoryClassProvider.java:84)
        at soot.asm.AllInMemoryClassProvider.<init>(AllInMemoryClassProvider.java:57)
        ... 20 more
Caused by: java.nio.file.NoSuchFileException: /home/utbot/jazzer/pdfbox/utbot/file
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
        at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:148)
        at java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
        at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
        at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:220)
        at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:277)
        at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:323)
        at java.base/java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:71)
        at java.base/java.nio.file.Files.walk(Files.java:3918)
        at java.base/java.nio.file.Files.walk(Files.java:3973)
        at soot.asm.AllInMemoryClassProvider.loadDir(AllInMemoryClassProvider.java:93)
        ... 22 more

Metadata

Metadata

Labels

comp-cliIssue related to CLIctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions