Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for core plugins to be found #7944

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ package org.ossreviewtoolkit.plugins.commands.requirements
import com.github.ajalt.clikt.testing.test

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.shouldNot
import io.kotest.matchers.shouldNotBe

class RequirementsCommandFunTest : StringSpec({
"All tool classes can be instantiated via reflection" {
// Status code 1 is only returned if there was an error while instantiating a class via reflection.
RequirementsCommand().test().statusCode shouldNotBe 1
}

"Core plugins are found" {
val plugins = RequirementsCommand().getPluginsByType()

plugins.keys shouldNot beEmpty()
plugins.values.flatten() shouldNot beEmpty()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class RequirementsCommand : OrtCommand(
}

private fun listPlugins() {
getPluginsByType().toSortedMap().forEach { (name, all) ->
echo(Theme.Default.info("$name plugins:"))
echo(all.joinToString("\n", postfix = "\n") { "${SUCCESS_PREFIX}$it" })
}
}

internal fun getPluginsByType(): Map<String, Set<String>> {
val pluginClasses = reflections.getSubTypesOf(Plugin::class.java)

val pluginTypes = pluginClasses.mapNotNull { clazz ->
Expand All @@ -119,10 +126,7 @@ class RequirementsCommand : OrtCommand(
}
}

pluginTypes.sortedBy { it.first }.forEach { (name, all) ->
echo(Theme.Default.info("$name plugins:"))
echo(all.joinToString("\n", postfix = "\n") { "${SUCCESS_PREFIX}$it" })
}
return pluginTypes.toMap()
}

private fun checkToolVersions(): EnumSet<VersionStatus> {
Expand Down