Skip to content

Commit

Permalink
test(asciidoc): Use placeholders for the asciidoctor version
Browse files Browse the repository at this point in the history
Remove the need to update the expected result on each upgrade of
Asciidoctor.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed May 22, 2024
1 parent 10d9b6e commit a9b800e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.23">
<meta name="generator" content="Asciidoctor <REPLACE_ASCIIDOCTOR_VERSION>">
<title>Disclosure Document</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<style>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'\" t
.\" Title: Disclosure Document
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.23
.\" Generator: Asciidoctor <REPLACE_ASCIIDOCTOR_VERSION>
.\" Date: <REPLACE_DATE>
.\" Manual: \ \&
.\" Source: \ \&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.reporter.ORT_RESULT
import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.utils.test.getAssetAsString
import org.ossreviewtoolkit.utils.test.getAssetFile
import org.ossreviewtoolkit.utils.test.patchExpectedResult

class HtmlTemplateReporterFunTest : StringSpec({
"HTML report is created from default template" {
val expectedText = getAssetAsString("html-template-reporter-expected-result.html")
val expectedResultFile = getAssetFile("html-template-reporter-expected-result.html")

val reportContent =
HtmlTemplateReporter().generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
val reporter = HtmlTemplateReporter()
val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()

reportContent.patchAsciiDocTemplateResult() shouldBe expectedText
reportContent.patchAsciiDocTemplateResult() shouldBe patchExpectedResult(
expectedResultFile,
custom = mapOf("<REPLACE_ASCIIDOCTOR_VERSION>" to reporter.asciidoctor.asciidoctorVersion())
)
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ import org.ossreviewtoolkit.utils.test.matchExpectedResult
class ManPageTemplateReporterFunTest : StringSpec({
"ManPage report is created from default template" {
val expectedResultFile = getAssetFile("manpage-template-reporter-expected-result.1")
val reporter = ManPageTemplateReporter()

val reportContent =
ManPageTemplateReporter().generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()

reportContent should matchExpectedResult(
expectedResultFile,
custom = mapOf("<REPLACE_DATE>" to "${LocalDate.now()}")
custom = mapOf(
"<REPLACE_DATE>" to "${LocalDate.now()}",
"<REPLACE_ASCIIDOCTOR_VERSION>" to reporter.asciidoctor.asciidoctorVersion()
)
)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class AsciiDocTemplateReporter(private val backend: String, override val ty
ASCII_DOC_FILE_EXTENSION
)

private val asciidoctor by lazy { Asciidoctor.Factory.create() }
internal val asciidoctor by lazy { Asciidoctor.Factory.create() }

/**
* Turn recognized [options] into [Attributes] and remove them from [options] afterwards to mark them as processed.
Expand Down

0 comments on commit a9b800e

Please sign in to comment.