Skip to content

Commit

Permalink
refactor(helper-cli): Replace the custom runMain with `CliktCommand…
Browse files Browse the repository at this point in the history
….test`

Note that a future version of clikt will also support a vararg for `test`
for convenience [1]. According code can be migrated once that version is
available.

[1]: ajalt/clikt#451

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Sep 13, 2023
1 parent 7e812fe commit 2e3249d
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.ossreviewtoolkit.helper.commands

import com.github.ajalt.clikt.core.ProgramResult
import com.github.ajalt.clikt.testing.test

import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe
Expand All @@ -39,12 +39,14 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
val outputFile = createOrtTempDir().resolve("analyzer-result.yml")
val expectedOutputFile = getAssetFile("create-analyzer-result-from-pkg-list-expected-output.yml")

runMain(
"create-analyzer-result-from-package-list",
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
outputFile.absolutePath
HelperMain().test(
listOf(
"create-analyzer-result-from-package-list",
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
outputFile.absolutePath
)
)

outputFile.readValue<OrtResult>().patchAnalyzerResult() shouldBe
Expand All @@ -53,15 +55,6 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
}
})

private fun runMain(vararg args: String) {
@Suppress("SwallowedException")
try {
HelperMain().parse(args.asList())
} catch (e: ProgramResult) {
// Ignore exceptions that just propagate the program result.
}
}

private fun OrtResult.patchAnalyzerResult(): OrtResult =
copy(
analyzer = analyzer?.copy(environment = Environment()),
Expand Down

0 comments on commit 2e3249d

Please sign in to comment.