Skip to content

Commit e9719f6

Browse files
committed
Corrections:
- Do a new method of test (Use a 'contains' instead) - Improve the accuracy of the error message by putting variables.
1 parent cfa4461 commit e9719f6

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ object Sidebar:
4545
Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option.when(dir.nonEmpty)(dir))
4646
case RawInput(title, page, index, subsection, dir, hidden) =>
4747
if title.isEmpty() then
48-
val msg = "Error parsing YAML configuration file: Title is not provided."
48+
val msg = s"Error parsing YAML configuration file: 'title' is not provided."
4949
report.error(s"$msg\n$schemaMessage")
5050
else if title.nonEmpty && (page.isEmpty() || index.isEmpty()) then
51-
val msg = "Error parsing YAML configuration file: Index or page path to at least one page is missing."
51+
val msg = s"Error parsing YAML configuration file: 'index' or 'page' path is missing for title '$title'."
5252
report.error(s"$msg\n$schemaMessage")
5353
else
54-
val msg = "The parsing seems not to have been done correctly."
54+
val msg = s"The parsing seems not to have been done correctly."
5555
report.warning(s"$msg\n$schemaMessage")
5656
Sidebar.Page(None, page, hidden)
5757

scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ class SidebarParserTest:
3838
| - page: my-page6/my-page6/my-page6.md
3939
""".stripMargin
4040

41+
private val sidebarNoTitle =
42+
"""index: index.md
43+
|subsection:
44+
| page: my-page1.md
45+
| - page: my-page2.md
46+
| - page: my-page3/subsection
47+
| - title: Reference
48+
| subsection:
49+
| - page: my-page3.md
50+
| hidden: true
51+
| - index: my-page4/index.md
52+
| subsection:
53+
| - page: my-page4/my-page4.md
54+
| - title: My subsection
55+
| index: my-page5/index.md
56+
| subsection:
57+
| - page: my-page5/my-page5.md
58+
| - subsection:
59+
| - page: my-page7/my-page7.md
60+
| - index: my-page6/index.md
61+
| subsection:
62+
| - index: my-page6/my-page6/index.md
63+
| subsection:
64+
| - page: my-page6/my-page6/my-page6.md
65+
""".stripMargin
66+
4167
private val sidebarErrorNoPage =
4268
"""index: index.md
4369
|subsection:
@@ -64,13 +90,11 @@ class SidebarParserTest:
6490
| - page: my-page6/my-page6/my-page6.md
6591
""".stripMargin
6692

67-
private val msgNoTitle = "Error parsing YAML configuration file: Title is not provided."
68-
private val msgNoPage = "Error parsing YAML configuration file: Index or page path to at least one page is missing."
93+
private val msgNoTitle = "Error parsing YAML configuration file: 'title' is not provided."
94+
private val msgNoPage = "Error parsing YAML configuration file: 'index' or 'page' path is missing for title 'My title'."
6995

7096
private def schemaMessage: String = Sidebar.schemaMessage
7197

72-
private val noPageExpectedError = s"$msgNoPage\n$schemaMessage\nPage my-page2.md does not exist.\nPage my-page3/subsection does not exist.\nPage my-page3.md does not exist.\nPage my-page4/my-page4.md does not exist.\nPage my-page5/my-page5.md does not exist.\nPage my-page7/my-page7.md does not exist.\nPage my-page6/my-page6/my-page6.md does not exist."
73-
7498
@Test
7599
def loadSidebar(): Unit = assertEquals(
76100
Sidebar.Category(
@@ -92,10 +116,23 @@ class SidebarParserTest:
92116
)
93117

94118
@Test
95-
def loadSidebarError(): Unit =
119+
def loadSidebarNoPageError: Unit =
96120
val out = new ByteArrayOutputStream()
97121
Console.withErr(new PrintStream(out)) {
98122
Sidebar.load(sidebarErrorNoPage)(using testContext)
99123
}
124+
println(out.toString())
100125
val error = out.toString().trim()
101-
assertEquals(noPageExpectedError, error)
126+
127+
assert(error.contains(msgNoPage) && error.contains(schemaMessage))
128+
129+
130+
@Test
131+
def loadSidebarNoTitleError(): Unit =
132+
val out = new ByteArrayOutputStream()
133+
Console.withErr(new PrintStream(out)) {
134+
Sidebar.load(sidebarNoTitle)(using testContext)
135+
}
136+
val error = out.toString().trim()
137+
138+
assert(error.contains(msgNoTitle) && error.contains(schemaMessage))

0 commit comments

Comments
 (0)