From 2e3249db0c52c668cfd5b1315f21e42e5e665b33 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 13 Sep 2023 08:58:41 +0200 Subject: [PATCH] refactor(helper-cli): Replace the custom `runMain` with `CliktCommand.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]: https://github.com/ajalt/clikt/pull/451 Signed-off-by: Sebastian Schuberth --- ...yzerResultFromPackageListCommandFunTest.kt | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt b/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt index ce3c7dc6cf5f8..5853a631dc3af 100644 --- a/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt +++ b/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt @@ -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 @@ -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().patchAnalyzerResult() shouldBe @@ -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()),