Skip to content

Commit a9b800e

Browse files
committed
test(asciidoc): Use placeholders for the asciidoctor version
Remove the need to update the expected result on each upgrade of Asciidoctor. Signed-off-by: Frank Viernau <[email protected]>
1 parent 10d9b6e commit a9b800e

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

plugins/reporters/asciidoc/src/funTest/assets/html-template-reporter-expected-result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="generator" content="Asciidoctor 2.0.23">
7+
<meta name="generator" content="Asciidoctor <REPLACE_ASCIIDOCTOR_VERSION>">
88
<title>Disclosure Document</title>
99
<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">
1010
<style>

plugins/reporters/asciidoc/src/funTest/assets/manpage-template-reporter-expected-result.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'\" t
22
.\" Title: Disclosure Document
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.23
4+
.\" Generator: Asciidoctor <REPLACE_ASCIIDOCTOR_VERSION>
55
.\" Date: <REPLACE_DATE>
66
.\" Manual: \ \&
77
.\" Source: \ \&

plugins/reporters/asciidoc/src/funTest/kotlin/HtmlTemplateReporterFunTest.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ import io.kotest.matchers.shouldBe
2525

2626
import org.ossreviewtoolkit.reporter.ORT_RESULT
2727
import org.ossreviewtoolkit.reporter.ReporterInput
28-
import org.ossreviewtoolkit.utils.test.getAssetAsString
28+
import org.ossreviewtoolkit.utils.test.getAssetFile
29+
import org.ossreviewtoolkit.utils.test.patchExpectedResult
2930

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

34-
val reportContent =
35-
HtmlTemplateReporter().generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
35+
val reporter = HtmlTemplateReporter()
36+
val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
3637

37-
reportContent.patchAsciiDocTemplateResult() shouldBe expectedText
38+
reportContent.patchAsciiDocTemplateResult() shouldBe patchExpectedResult(
39+
expectedResultFile,
40+
custom = mapOf("<REPLACE_ASCIIDOCTOR_VERSION>" to reporter.asciidoctor.asciidoctorVersion())
41+
)
3842
}
3943
})
4044

plugins/reporters/asciidoc/src/funTest/kotlin/ManPageTemplateReporterFunTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ import org.ossreviewtoolkit.utils.test.matchExpectedResult
3333
class ManPageTemplateReporterFunTest : StringSpec({
3434
"ManPage report is created from default template" {
3535
val expectedResultFile = getAssetFile("manpage-template-reporter-expected-result.1")
36+
val reporter = ManPageTemplateReporter()
3637

37-
val reportContent =
38-
ManPageTemplateReporter().generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
38+
val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()).single().readText()
3939

4040
reportContent should matchExpectedResult(
4141
expectedResultFile,
42-
custom = mapOf("<REPLACE_DATE>" to "${LocalDate.now()}")
42+
custom = mapOf(
43+
"<REPLACE_DATE>" to "${LocalDate.now()}",
44+
"<REPLACE_ASCIIDOCTOR_VERSION>" to reporter.asciidoctor.asciidoctorVersion()
45+
)
4346
)
4447
}
4548
})

plugins/reporters/asciidoc/src/main/kotlin/AsciiDocTemplateReporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ open class AsciiDocTemplateReporter(private val backend: String, override val ty
5959
ASCII_DOC_FILE_EXTENSION
6060
)
6161

62-
private val asciidoctor by lazy { Asciidoctor.Factory.create() }
62+
internal val asciidoctor by lazy { Asciidoctor.Factory.create() }
6363

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

0 commit comments

Comments
 (0)