Skip to content

Commit 93e1c5c

Browse files
committed
Update README for test command, run
1 parent e9d3e08 commit 93e1c5c

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# kargo
2-
A command-line build tool for kotlin inspired by rust's [cargo](https://doc.rust-lang.org/cargo/).
2+
3+
A command-line build tool for kotlin inspired by rust's [cargo](https://doc.rust-lang.org/cargo/).
34

45
# Installation
56

@@ -78,6 +79,7 @@ Builds your project using the kotlin CLI compiler. This will produce a jar file
7879
in `target/<project.name>.jar` containing your code and the kotlin runtime.
7980

8081
### run
82+
8183
`kargo run [--script <path to kts script>] [-- <args to main class or script>]`
8284

8385
Run the project's main class with the provided args, or alternately the
@@ -116,6 +118,26 @@ any errors.
116118

117119
Uses [`ktlint`](https://ktlint.github.io/) to format your kotlin sources
118120
in-place. This command is known not to work on java 17.
121+
:w
122+
123+
### test
124+
125+
`kargo test`
126+
Uses JUnit5 to run the project's tests, which should do annotations / assertions via the
127+
standard `kotlin.test` library. (You must also add a
128+
`org.jetbrains.kotlin:kotlin-test-junit5` dependency to `Kargo.toml` for test running.)
129+
130+
To avoid confusion / mistakenly thinking that tests passed when they didn't,
131+
this will run `kargo build` before running tests.
132+
133+
Test discovery requires some knowledge of project layout. By default, kargo will
134+
discover all test files ending in `_test.kt` within the `src` directory. To use
135+
the more conventional `src/{main,test}/kotlin` project layout, add
136+
`project_layout = "classic"` to the package section of the `Kargo.toml` file.
137+
138+
It's a known issue that we currently don't discover functions annotated with
139+
@Test at top-level in test files. As a workaround, place them within classes
140+
whose name starts or ends with `Test`.
119141

120142
## Kargo.toml reference
121143

@@ -131,6 +153,10 @@ in-place. This command is known not to work on java 17.
131153
- `use_serialization_plugin` (optional, default `false`): if you use
132154
`kotlinx.serialization` in your project, set this to `true` to enable the
133155
corresponding compiler plugin.
156+
- `project_layout` (optional, one of `classic` or `flat`, default `flat`): project
157+
layout used to discover tests. `flat` allows test files alongside code, in
158+
files ending in `_test.kt`. `classic` uses the more conventional layout where
159+
tests are in `src/test` (and non-test code is in `src/main`).
134160

135161
`[dependencies]`: this section is required but can be empty
136162

@@ -151,15 +177,18 @@ itself.
151177

152178
### Short-term
153179

154-
- `kargo test` for running tests (and exclusion of test files from builds, etc.)
180+
- test configuration options for running tests by tag, or specific tests
181+
- test discovery for top-level functions
155182
- a number of other configuration options (option to turn off including the
156183
kotlin runtime in the jar, support of other source / test layouts, etc.)
157184

158185
### Medium-term
186+
159187
- better support for building / publishing libraries, rather than just runnable
160188
applications
161189

162190
### Long-term
191+
163192
- kotlin js/native support
164193

165194
## License

src/commands/Run.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ class Run(val script: Path?, val runArgs: List<String>) : Runnable {
3131
KotlinC.script(script, runArgs)
3232
}
3333
}
34-
3534
}

src/tools/JUnitRunner.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package kargo.tools
22

33
import kargo.Config
44
import kargo.Subprocess
5-
import kargo.commands.Run
65
import kargo.recListPath
76
import kargo.toClasspathString
8-
import java.io.File
97
import java.nio.file.Path
108
import kotlin.io.path.absolutePathString
119
import kotlin.io.path.div
@@ -22,10 +20,12 @@ object JUnitRunner : Tool {
2220
fun test() {
2321
KotlinC.buildTests()
2422
val testClasses = recListPath(KotlinC.testOutputDir()).filter { it.extension == "class" }
25-
val classPath = (Config.global.depsJarFiles() + listOf(
26-
KotlinC.outputJar(),
27-
KotlinC.testOutputDir(),
28-
)).toClasspathString()
23+
val classPath = (
24+
Config.global.depsJarFiles() + listOf(
25+
KotlinC.outputJar(),
26+
KotlinC.testOutputDir(),
27+
)
28+
).toClasspathString()
2929
Subprocess.jar(executable().absolutePathString()) {
3030
addArgs("-cp", classPath)
3131
arg("--fail-if-no-tests")

src/tools/KotlinC.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ object KotlinC : ToolZipBundle<KotlinCBundle> {
3636
super.download()
3737
}
3838

39-
4039
fun script(script: Path, scriptArgs: List<String>) {
4140
Subprocess.new {
4241
command = path(KotlinCBundle.KOTLINC).absolutePathString()

0 commit comments

Comments
 (0)