Skip to content

Commit f2571ae

Browse files
Lucas LeblancLucas Leblanc
Lucas Leblanc
authored and
Lucas Leblanc
committed
Refactor: Re-add the path check of the sidebar and the improve the test by erasing the title only
The goal of this PR is to re-add the path validation of page in the sidebar and improve the testcase by erasing the first title, so it's easier to understand the problem in it.
1 parent 10180da commit f2571ae

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Diff for: scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ object Sidebar:
3434

3535
private def toSidebar(r: RawInput, content: String | java.io.File)(using CompilerContext): Sidebar = r match
3636
case RawInput(title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
37+
val pagePath = content match
38+
case f: java.io.File =>
39+
val pagePath = f.toPath()
40+
.getParent()
41+
.resolve(s"_docs/$page")
42+
if !Files.exists(pagePath) then
43+
report.error(s"Page $page does not exist.")
44+
case s: String => None
3745
Sidebar.Page(Option.when(title.nonEmpty)(title), page, hidden)
3846
case RawInput(title, page, index, subsection, dir, hidden) if page.isEmpty && (!subsection.isEmpty() || !index.isEmpty()) =>
3947
Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option.when(dir.nonEmpty)(dir))

Diff for: scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class SidebarParserTest:
4141
private val sidebarNoTitle =
4242
"""index: index.md
4343
|subsection:
44-
| - title: My title
4544
| page: my-page1.md
4645
| - page: my-page2.md
4746
| - page: my-page3/subsection
@@ -57,7 +56,7 @@ class SidebarParserTest:
5756
| subsection:
5857
| - page: my-page5/my-page5.md
5958
| - subsection:
60-
| page: my-page7/my-page7.md
59+
| - page: my-page7/my-page7.md
6160
| - index: my-page6/index.md
6261
| subsection:
6362
| - index: my-page6/my-page6/index.md
@@ -122,10 +121,9 @@ class SidebarParserTest:
122121
Console.withErr(new PrintStream(out)) {
123122
Sidebar.load(sidebarErrorNoPage)(using testContext)
124123
}
125-
println(out.toString())
126-
val error = out.toString().trim()
124+
val errorPage = out.toString().trim()
127125

128-
assert(error.contains(msgNoPage) && error.contains(schemaMessage))
126+
assert(errorPage.contains(msgNoPage) && errorPage.contains(schemaMessage))
129127

130128

131129
@Test
@@ -134,6 +132,6 @@ class SidebarParserTest:
134132
Console.withErr(new PrintStream(out)) {
135133
Sidebar.load(sidebarNoTitle)(using testContext)
136134
}
137-
val error = out.toString().trim()
135+
val errorTitle = out.toString().trim()
138136

139-
assert(error.contains(msgNoTitle) && error.contains(schemaMessage))
137+
assert(errorTitle.contains(msgNoTitle) && errorTitle.contains(schemaMessage))

0 commit comments

Comments
 (0)