Skip to content

Commit

Permalink
test(OrtMainFunTest): Use stderr as clues in case of failures
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Oct 19, 2023
1 parent 612f55c commit c062250
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions cli/src/funTest/kotlin/OrtMainFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.cli

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

import io.kotest.assertions.withClue
import io.kotest.core.spec.Spec
import io.kotest.core.spec.style.StringSpec
import io.kotest.core.test.TestCase
Expand Down Expand Up @@ -79,61 +80,73 @@ class OrtMainFunTest : StringSpec() {
"Enabling only Gradle works" {
val inputDir = tempdir()

val stdout = OrtMain().test(
val result = OrtMain().test(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
)

val stdout = result.stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
if (iterator.next() == "The following 1 package manager(s) are enabled:") break
}

iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe "Gradle"
withClue(result.stderr) {
iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe "Gradle"
}
}

"Disabling only Gradle works" {
val expectedPackageManagers = PackageManager.ENABLED_BY_DEFAULT.filterNot { it.type == "Gradle" }
val markerLine = "The following ${expectedPackageManagers.size} package manager(s) are enabled:"
val inputDir = tempdir()

val stdout = OrtMain().test(
val result = OrtMain().test(
"-c", configFile.path,
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
)

val stdout = result.stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
if (iterator.next() == markerLine) break
}

iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe expectedPackageManagers.joinToString { it.type }
withClue(result.stderr) {
iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe expectedPackageManagers.joinToString { it.type }
}
}

"Disabling a package manager overrides enabling it" {
val inputDir = tempdir()

val stdout = OrtMain().test(
val result = OrtMain().test(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle,NPM",
"-P", "ort.analyzer.disabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path
).stdout.lineSequence()
)

val stdout = result.stdout.lineSequence()
val iterator = stdout.iterator()
while (iterator.hasNext()) {
if (iterator.next() == "The following 1 package manager(s) are enabled:") break
}

iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe "NPM"
withClue(result.stderr) {
iterator.hasNext() shouldBe true
iterator.next().trim() shouldBe "NPM"
}
}

"An Unmanaged project is created if no definition files are found" {
Expand Down Expand Up @@ -177,17 +190,21 @@ class OrtMainFunTest : StringSpec() {
"Output formats are deduplicated" {
val inputDir = tempdir()

val stdout = OrtMain().test(
val result = OrtMain().test(
"-c", configFile.path,
"-P", "ort.analyzer.enabledPackageManagers=Gradle",
"analyze",
"-i", inputDir.path,
"-o", outputDir.path,
"-f", "json,yaml,json"
).stdout.lineSequence()
)

val stdout = result.stdout.lineSequence()
val lines = stdout.filter { it.startsWith("Writing analyzer result to ") }

lines.count() shouldBe 2
withClue(result.stderr) {
lines.count() shouldBe 2
}
}

"Analyzer creates correct output" {
Expand Down

0 comments on commit c062250

Please sign in to comment.