Skip to content

Commit ef83e13

Browse files
authored
Python and JS support #1197 (#1199)
1 parent 3ac0bc7 commit ef83e13

File tree

260 files changed

+17190
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+17190
-445
lines changed

docs/ChoosingLanguageSpecificIDE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Choosing language specific IDE
2+
3+
Some language-specific modules depends on specific IntelliJ IDE:
4+
* Python can work with IntelliJ Community, IntelliJ Ultimate, PyCharm Community, PyCharm Professional
5+
* JavaScript can work with IntelliJ Ultimate, PyCharm Professional and WebStorm
6+
* Java and Kotlin - IntelliJ Community and IntelliJ Ultimate
7+
8+
You should select correct IDE in `gradle.properties` file:
9+
```
10+
ideType=<IU>
11+
ideVersion=<222.4167.29>
12+
```
13+
14+
### IDE marking
15+
16+
| Mark | Full name | Supported plugin |
17+
|------|----------------------|----------------------------------------|
18+
| IC | IntelliJ Community | JVM, Python, AndroidStudio |
19+
| IU | IntelliJ Ultimate | JVM, Python, JavaScript, AndroidStudio |
20+
| PC | PyCharm Community | Python |
21+
| PY | PyCharm Professional | Python, JavaScript |
22+
23+
[IntelliJ Platform Plugin SDK documentation](https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#tasks-runpluginverifier)

docs/UtbotFamilyChanges.md

+87
Large diffs are not rendered by default.

gradle.properties

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
kotlin.code.style=official
22

3-
# IU, IC, PC, PY, WS...
3+
# IU, IC, PC, PY
44
# IC for AndroidStudio
55
ideType=IC
6+
ideVersion=222.4167.29
7+
8+
pythonIde=IC,IU,PC,PY
9+
jsIde=IU,PY,WS
610

711
# In order to run Android Studion instead of Intellij Community,
812
# specify the path to your Android Studio installation
913
//androidStudioPath=your_path_to_android_studio
1014

11-
pythonCommunityPluginVersion=222.4167.37
1215
#Version numbers: https://plugins.jetbrains.com/plugin/631-python/versions
16+
pythonCommunityPluginVersion=222.4167.37
1317
pythonUltimatePluginVersion=222.4167.37
1418

19+
kotlinPluginVersion=222-1.7.20-release-201-IJ4167.29
20+
1521
junit5Version=5.8.0-RC1
1622
junit4Version=4.13.2
1723
junit4PlatformVersion=1.9.0

settings.gradle

-34
This file was deleted.

settings.gradle.kts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
val ideType: String by settings
2+
3+
val pythonIde: String by settings
4+
val jsIde: String by settings
5+
6+
pluginManagement {
7+
resolutionStrategy {
8+
eachPlugin {
9+
if (requested.id.name == "rdgen") {
10+
useModule("com.jetbrains.rd:rd-gen:${requested.version}")
11+
}
12+
}
13+
}
14+
}
15+
16+
rootProject.name = "utbot"
17+
18+
include("utbot-core")
19+
include("utbot-framework")
20+
include("utbot-framework-api")
21+
include("utbot-intellij")
22+
include("utbot-sample")
23+
include("utbot-fuzzers")
24+
include("utbot-junit-contest")
25+
include("utbot-analytics")
26+
include("utbot-analytics-torch")
27+
28+
include("utbot-cli")
29+
30+
include("utbot-api")
31+
include("utbot-instrumentation")
32+
include("utbot-instrumentation-tests")
33+
34+
include("utbot-summary")
35+
include("utbot-gradle")
36+
include("utbot-maven")
37+
include("utbot-summary-tests")
38+
include("utbot-framework-test")
39+
include("utbot-rd")
40+
include("utbot-android-studio")
41+
42+
include("utbot-ui-commons")
43+
44+
if (pythonIde.split(",").contains(ideType)) {
45+
include("utbot-python")
46+
include("utbot-cli-python")
47+
include("utbot-intellij-python")
48+
}
49+
50+
if (jsIde.split(",").contains(ideType)) {
51+
include("utbot-js")
52+
include("utbot-cli-js")
53+
include("utbot-intellij-js")
54+
}

utbot-cli-js/build.gradle

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
2+
kotlinOptions {
3+
jvmTarget = JavaVersion.VERSION_11
4+
freeCompilerArgs += ["-Xallow-result-return-type", "-Xsam-conversions=class"]
5+
}
6+
}
7+
8+
tasks.withType(JavaCompile) {
9+
sourceCompatibility = JavaVersion.VERSION_1_8
10+
targetCompatibility = JavaVersion.VERSION_11
11+
}
12+
13+
configurations {
14+
fetchInstrumentationJar
15+
}
16+
17+
dependencies {
18+
implementation project(':utbot-framework')
19+
implementation project(':utbot-cli')
20+
implementation project(':utbot-js')
21+
22+
// Without this dependency testng tests do not run.
23+
implementation group: 'com.beust', name: 'jcommander', version: '1.48'
24+
implementation group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: junit4PlatformVersion
25+
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion
26+
implementation group: 'com.github.ajalt.clikt', name: 'clikt', version: cliktVersion
27+
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit5Version
28+
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version
29+
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2Version
30+
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4j2Version
31+
implementation group: 'org.json', name: 'json', version: '20220320'
32+
//noinspection GroovyAssignabilityCheck
33+
fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration: 'instrumentationArchive')
34+
}
35+
36+
processResources {
37+
from(configurations.fetchInstrumentationJar) {
38+
into "lib"
39+
}
40+
}
41+
42+
task createProperties(dependsOn: processResources) {
43+
doLast {
44+
new File("$buildDir/resources/main/version.properties").withWriter { w ->
45+
Properties properties = new Properties()
46+
//noinspection GroovyAssignabilityCheck
47+
properties['version'] = project.version.toString()
48+
properties.store w, null
49+
}
50+
}
51+
}
52+
53+
classes {
54+
dependsOn createProperties
55+
}
56+
57+
jar {
58+
manifest {
59+
attributes 'Main-Class': 'org.utbot.cli.js.ApplicationKt'
60+
attributes 'Bundle-SymbolicName': 'org.utbot.cli.js'
61+
attributes 'Bundle-Version': "${project.version}"
62+
attributes 'Implementation-Title': 'UtBot JavaScript CLI'
63+
attributes 'JAR-Type': 'Fat JAR'
64+
}
65+
66+
archiveVersion.set(project.version as String)
67+
68+
dependsOn configurations.runtimeClasspath
69+
from {
70+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
71+
}
72+
73+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
74+
}
75+

utbot-cli-js/src/README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Build
2+
3+
.jar file can be built in GitHub Actions with script publish-plugin-and-cli-from-branch.
4+
5+
## Requirements
6+
7+
* NodeJs 10.0.0 or higher (available to download https://nodejs.org/en/download/)
8+
* Java 11 or higher (available to download https://www.oracle.com/java/technologies/downloads/)
9+
* Nyc 15.1.0 or higher (`> npm install -g nyc`)
10+
* Mocha 10.0.0 or higher (`> npm install -g mocha`)
11+
12+
## Basic usage
13+
14+
Generate tests:
15+
16+
java -jar utbot-cli.jar generate_js --source="dir/file_with_sources.js" --output="dir/generated_tests.js"
17+
18+
This will generate tests for top-level functions from `file_with_sources.js`.
19+
20+
Run generated tests:
21+
22+
java -jar utbot-cli.jar run_js --fileOrDir="generated_tests.js"
23+
24+
This will run generated tests from file or directory.
25+
26+
Generate coverage report:
27+
28+
java -jar utbot-cli.jar coverage_js --source=dir/generated_tests.js
29+
30+
This will generate coverage report from generated tests and print in `StdOut`
31+
32+
## `generate_js` options
33+
34+
- `-s, --source <path>`
35+
36+
(required) Source code file for a test generation.
37+
- `-c, --class <classname>`
38+
39+
If not specified, tests for top-level functions or single class are generated, otherwise for the specified class.
40+
41+
- `-o, --output <dir/filename>`
42+
43+
File for generated tests.
44+
- `-p, --print-test`
45+
46+
Specifies whether test should be printed out to `StdOut` (default = false)
47+
- `-t, --timeout <seconds>`
48+
49+
Timeout for a single test case to generate in seconds (default = 15)
50+
- `--coverage-mode <BASIC/FAST>`
51+
52+
Specifies the coverage mode for test generation. Fast mode can't find timeouts, but works faster (default = FAST)
53+
- `--path-to-node <path>`
54+
55+
Sets path to Node.js executable (default = "node")
56+
- `--path-to-nyc <path>`
57+
58+
Sets path to nyc executable (default = "nyc")
59+
- `--path-to-npm <path>`
60+
61+
Sets path to npm executable (default = "npm")
62+
63+
## `run_js` options
64+
65+
- `-f, --fileOrDir`
66+
67+
(required) File or directory with tests.
68+
- `-o, --output`
69+
70+
Specifies output of .txt file for test framework result (If empty prints to `StdOut`)
71+
72+
- `-t, --test-framework <name>`
73+
74+
Test framework of tests to run. (default = "Mocha")
75+
76+
## `coverage_js` options
77+
78+
- `-s, --source <file>`
79+
80+
(required) File with tests to generate a report.
81+
82+
- `-o, --output`
83+
84+
Specifies output .json file for generated tests (If empty prints .json to `StdOut`)
85+
- `--path-to-nyc <path>`
86+
87+
Sets path to nyc executable (default = "nyc")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.utbot.cli.js
2+
3+
import com.github.ajalt.clikt.core.CliktCommand
4+
import com.github.ajalt.clikt.core.subcommands
5+
import com.github.ajalt.clikt.parameters.options.default
6+
import com.github.ajalt.clikt.parameters.options.option
7+
import com.github.ajalt.clikt.parameters.options.versionOption
8+
import com.github.ajalt.clikt.parameters.types.enum
9+
import org.slf4j.event.Level
10+
import org.utbot.cli.getVersion
11+
import org.utbot.cli.setVerbosity
12+
import kotlin.system.exitProcess
13+
14+
class UtBotJsCli : CliktCommand(name = "UnitTestBot JavaScript Command Line Interface") {
15+
private val verbosity by option("--verbosity", help = "Changes verbosity level, case insensitive")
16+
.enum<Level>(ignoreCase = true)
17+
.default(Level.INFO)
18+
19+
override fun run() = setVerbosity(verbosity)
20+
21+
init {
22+
versionOption(getVersion())
23+
}
24+
}
25+
26+
fun main(args: Array<String>) = try {
27+
UtBotJsCli().subcommands(
28+
JsCoverageCommand(),
29+
JsGenerateTestsCommand(),
30+
JsRunTestsCommand(),
31+
).main(args)
32+
} catch (ex: Throwable) {
33+
ex.printStackTrace()
34+
exitProcess(1)
35+
}

0 commit comments

Comments
 (0)