Skip to content

Commit cfa4461

Browse files
committed
Add a first test:
- Error when a title but no pages
1 parent 3ce49f8 commit cfa4461

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object Sidebar:
5555
report.warning(s"$msg\n$schemaMessage")
5656
Sidebar.Page(None, page, hidden)
5757

58-
private def schemaMessage: String =
58+
def schemaMessage: String =
5959
s"""Static site YAML configuration file should comply with the following description:
6060
|The root element of static site needs to be <subsection>
6161
|`title` and `directory` properties are ignored in root subsection.
@@ -73,8 +73,7 @@ object Sidebar:
7373
| hidden: <boolean> # optional - Default value is false.
7474
|
7575
|For more information visit:
76-
|https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
77-
|""".stripMargin
76+
|https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html""".stripMargin
7877

7978
def load(content: String | java.io.File)(using CompilerContext): Sidebar.Category =
8079
import scala.util.Try

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

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package site
33

44
import org.junit.Test
55
import org.junit.Assert._
6+
import dotty.tools.scaladoc.site.Sidebar
7+
import dotty.tools.scaladoc.site.Sidebar.RawInput
8+
import java.io.ByteArrayOutputStream
9+
import java.io.PrintStream
610

711
// TODO add negaitve and more details tests
812
class SidebarParserTest:
@@ -34,10 +38,10 @@ class SidebarParserTest:
3438
| - page: my-page6/my-page6/my-page6.md
3539
""".stripMargin
3640

37-
private val sidebarErrorNoTitle =
38-
"""index: index.md
41+
private val sidebarErrorNoPage =
42+
"""index: index.md
3943
|subsection:
40-
| page: my-page1.md
44+
| - title: My title
4145
| - page: my-page2.md
4246
| - page: my-page3/subsection
4347
| - title: Reference
@@ -60,28 +64,12 @@ class SidebarParserTest:
6064
| - page: my-page6/my-page6/my-page6.md
6165
""".stripMargin
6266

63-
private val msg = "Error parsing YAML configuration file: Title is not provided."
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."
6469

65-
private def schemaMessage: String =
66-
s"""Static site YAML configuration file should comply with the following description:
67-
|The root element of static site needs to be <subsection>
68-
|`title` and `directory` properties are ignored in root subsection.
69-
|
70-
|<subsection>:
71-
| title: <string> # optional - Default value is file name. Title can be also set using front-matter.
72-
| index: <string> # optional - If not provided, default empty index template is generated.
73-
| directory: <string> # optional - By default, directory name is title name in kebab case.
74-
| subsection: # optional - If not provided, pages are loaded from the index directory
75-
| - <subsection> | <page>
76-
| # either index or subsection needs to be present
77-
|<page>:
78-
| title: <string> # optional - Default value is file name. Title can be also set using front-matter.
79-
| page: <string>
80-
| hidden: <boolean> # optional - Default value is false.
81-
|
82-
|For more information visit:
83-
|https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
84-
|""".stripMargin
70+
private def schemaMessage: String = Sidebar.schemaMessage
71+
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."
8573

8674
@Test
8775
def loadSidebar(): Unit = assertEquals(
@@ -103,15 +91,11 @@ class SidebarParserTest:
10391
Sidebar.load(sidebar)(using testContext)
10492
)
10593

106-
@Test(expected = classOf[IllegalArgumentException])
94+
@Test
10795
def loadSidebarError(): Unit =
108-
assertEquals(
109-
Sidebar.Category(
110-
None,
111-
None,
112-
List(),
113-
None
114-
),
115-
Sidebar.load(sidebarErrorNoTitle)(using testContext)
116-
)
117-
throw new IllegalArgumentException(s"$msg\n$schemaMessage")
96+
val out = new ByteArrayOutputStream()
97+
Console.withErr(new PrintStream(out)) {
98+
Sidebar.load(sidebarErrorNoPage)(using testContext)
99+
}
100+
val error = out.toString().trim()
101+
assertEquals(noPageExpectedError, error)

0 commit comments

Comments
 (0)