Skip to content

Commit

Permalink
feat(CompareCommand): Add the SEMANTIC_DIFF as a new compare method
Browse files Browse the repository at this point in the history
The new compare method `SEMANTIC_DIFF` can be used for comparing the
ORT results on the object level. Currently, it only checks whether
the provided ORT results are equal. There will a improved comparison
of the results in the upcoming commit(s).

Signed-off-by: Onur Demirci <[email protected]>
  • Loading branch information
bs-ondem committed Nov 27, 2023
1 parent d652de6 commit d6857a9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugins/commands/compare/src/main/kotlin/CompareCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.enum
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.rendering.Theme
import com.github.difflib.DiffUtils
import com.github.difflib.UnifiedDiffUtils

Expand Down Expand Up @@ -105,6 +106,22 @@ class CompareCommand : OrtCommand(
val resultB = deserializer.readValue<OrtResult>(fileB)

when (method) {
CompareMethod.SEMANTIC_DIFF -> {
echo(
Theme.Default.warning(
"The '${CompareMethod.SEMANTIC_DIFF}' compare method is not fully implemented. Some " +
"properties may not be taken into account in the comparison."
)
)

if (resultA == resultB) {
echo("The ORT results are the same.")
throw ProgramResult(0)
}

throw ProgramResult(1)
}

CompareMethod.TEXT_DIFF -> {
val textA = deserializer.writeValueAsString(resultA)
val textB = deserializer.writeValueAsString(resultB)
Expand Down Expand Up @@ -149,6 +166,7 @@ class CompareCommand : OrtCommand(
}

private enum class CompareMethod {
SEMANTIC_DIFF,
TEXT_DIFF
}

Expand Down

0 comments on commit d6857a9

Please sign in to comment.