From 020aeddde0c9b93ef780f94e1e6ddd7117f2faa5 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 12 Jun 2023 14:05:49 +0200 Subject: [PATCH 1/3] Fix: Error Sidebar PR failed test [test_windows_full] --- .../test/dotty/tools/scaladoc/site/SidebarParserTest.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala index f30990d07cfa..408a8a5a9476 100644 --- a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala @@ -38,10 +38,9 @@ class SidebarParserTest: | - page: my-page6/my-page6/my-page6.md """.stripMargin - private val sidebarNoTitle = + private val sidebarErrorNoTitle = """index: index.md |subsection: - | - title: My title | page: my-page1.md | - page: my-page2.md | - page: my-page3/subsection @@ -122,7 +121,6 @@ class SidebarParserTest: Console.withErr(new PrintStream(out)) { Sidebar.load(sidebarErrorNoPage)(using testContext) } - println(out.toString()) val error = out.toString().trim() assert(error.contains(msgNoPage) && error.contains(schemaMessage)) @@ -132,7 +130,7 @@ class SidebarParserTest: def loadSidebarNoTitleError(): Unit = val out = new ByteArrayOutputStream() Console.withErr(new PrintStream(out)) { - Sidebar.load(sidebarNoTitle)(using testContext) + Sidebar.load(sidebarErrorNoTitle)(using testContext) } val error = out.toString().trim() From 68693855801419940f47c804a0f21b843f43bbab Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 13 Jun 2023 11:52:35 +0200 Subject: [PATCH 2/3] Fix: Test with previous version of the file --- .../scaladoc/site/SidebarParserTest.scala | 89 +------------------ 1 file changed, 2 insertions(+), 87 deletions(-) diff --git a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala index 408a8a5a9476..a97f39cd9128 100644 --- a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala @@ -1,16 +1,9 @@ package dotty.tools.scaladoc package site - import org.junit.Test import org.junit.Assert._ -import dotty.tools.scaladoc.site.Sidebar -import dotty.tools.scaladoc.site.Sidebar.RawInput -import java.io.ByteArrayOutputStream -import java.io.PrintStream - -// TODO add negative and more details tests +// TODO add negaitve and more details tests class SidebarParserTest: - private val sidebar = """index: index.md |subsection: @@ -38,63 +31,6 @@ class SidebarParserTest: | - page: my-page6/my-page6/my-page6.md """.stripMargin - private val sidebarErrorNoTitle = - """index: index.md - |subsection: - | page: my-page1.md - | - page: my-page2.md - | - page: my-page3/subsection - | - title: Reference - | subsection: - | - page: my-page3.md - | hidden: true - | - index: my-page4/index.md - | subsection: - | - page: my-page4/my-page4.md - | - title: My subsection - | index: my-page5/index.md - | subsection: - | - page: my-page5/my-page5.md - | - subsection: - | page: my-page7/my-page7.md - | - index: my-page6/index.md - | subsection: - | - index: my-page6/my-page6/index.md - | subsection: - | - page: my-page6/my-page6/my-page6.md - """.stripMargin - - private val sidebarErrorNoPage = - """index: index.md - |subsection: - | - title: My title - | - page: my-page2.md - | - page: my-page3/subsection - | - title: Reference - | subsection: - | - page: my-page3.md - | hidden: true - | - index: my-page4/index.md - | subsection: - | - page: my-page4/my-page4.md - | - title: My subsection - | index: my-page5/index.md - | subsection: - | - page: my-page5/my-page5.md - | - subsection: - | - page: my-page7/my-page7.md - | - index: my-page6/index.md - | subsection: - | - index: my-page6/my-page6/index.md - | subsection: - | - page: my-page6/my-page6/my-page6.md - """.stripMargin - - private val msgNoTitle = "`title` property is missing for some page." - private val msgNoPage = "Error parsing YAML configuration file: 'index' or 'page' path is missing for title 'My title'." - - private def schemaMessage: String = Sidebar.schemaMessage - @Test def loadSidebar(): Unit = assertEquals( Sidebar.Category( @@ -113,25 +49,4 @@ class SidebarParserTest: None ), Sidebar.load(sidebar)(using testContext) - ) - - @Test - def loadSidebarNoPageError: Unit = - val out = new ByteArrayOutputStream() - Console.withErr(new PrintStream(out)) { - Sidebar.load(sidebarErrorNoPage)(using testContext) - } - val error = out.toString().trim() - - assert(error.contains(msgNoPage) && error.contains(schemaMessage)) - - - @Test - def loadSidebarNoTitleError(): Unit = - val out = new ByteArrayOutputStream() - Console.withErr(new PrintStream(out)) { - Sidebar.load(sidebarErrorNoTitle)(using testContext) - } - val error = out.toString().trim() - - assert(error.contains(msgNoTitle) && error.contains(schemaMessage)) + ) \ No newline at end of file From 9c89c1d3f5f51c4c7419850189facb1b8c935ec0 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 13 Jun 2023 17:13:20 +0200 Subject: [PATCH 3/3] Fix: Erase the check path to correct the issue --- .../tools/scaladoc/site/SidebarParser.scala | 7 -- .../scaladoc/site/SidebarParserTest.scala | 91 ++++++++++++++++++- 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala b/scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala index 1916c32e53dc..7094d2a1f751 100644 --- a/scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala +++ b/scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala @@ -34,13 +34,6 @@ object Sidebar: private def toSidebar(r: RawInput, content: String | java.io.File)(using CompilerContext): Sidebar = r match case RawInput(title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() => - val sidebarPath = content match - case s: String => Paths.get(s) - case f: java.io.File => f.toPath() - val basePath = sidebarPath.getParent().resolve("_docs") - val pagePath = basePath.resolve(page) - if !Files.exists(pagePath) then - report.error(s"Page $page does not exist.") Sidebar.Page(Option.when(title.nonEmpty)(title), page, hidden) case RawInput(title, page, index, subsection, dir, hidden) if page.isEmpty && (!subsection.isEmpty() || !index.isEmpty()) => Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option.when(dir.nonEmpty)(dir)) diff --git a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala index a97f39cd9128..87cf07faa55f 100644 --- a/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala @@ -1,9 +1,16 @@ package dotty.tools.scaladoc package site + import org.junit.Test import org.junit.Assert._ -// TODO add negaitve and more details tests +import dotty.tools.scaladoc.site.Sidebar +import dotty.tools.scaladoc.site.Sidebar.RawInput +import java.io.ByteArrayOutputStream +import java.io.PrintStream + +// TODO add negative and more details tests class SidebarParserTest: + private val sidebar = """index: index.md |subsection: @@ -31,6 +38,64 @@ class SidebarParserTest: | - page: my-page6/my-page6/my-page6.md """.stripMargin + private val sidebarNoTitle = + """index: index.md + |subsection: + | - title: My title + | page: my-page1.md + | - page: my-page2.md + | - page: my-page3/subsection + | - title: Reference + | subsection: + | - page: my-page3.md + | hidden: true + | - index: my-page4/index.md + | subsection: + | - page: my-page4/my-page4.md + | - title: My subsection + | index: my-page5/index.md + | subsection: + | - page: my-page5/my-page5.md + | - subsection: + | page: my-page7/my-page7.md + | - index: my-page6/index.md + | subsection: + | - index: my-page6/my-page6/index.md + | subsection: + | - page: my-page6/my-page6/my-page6.md + """.stripMargin + + private val sidebarErrorNoPage = + """index: index.md + |subsection: + | - title: My title + | - page: my-page2.md + | - page: my-page3/subsection + | - title: Reference + | subsection: + | - page: my-page3.md + | hidden: true + | - index: my-page4/index.md + | subsection: + | - page: my-page4/my-page4.md + | - title: My subsection + | index: my-page5/index.md + | subsection: + | - page: my-page5/my-page5.md + | - subsection: + | - page: my-page7/my-page7.md + | - index: my-page6/index.md + | subsection: + | - index: my-page6/my-page6/index.md + | subsection: + | - page: my-page6/my-page6/my-page6.md + """.stripMargin + + private val msgNoTitle = "`title` property is missing for some page." + private val msgNoPage = "Error parsing YAML configuration file: 'index' or 'page' path is missing for title 'My title'." + + private def schemaMessage: String = Sidebar.schemaMessage + @Test def loadSidebar(): Unit = assertEquals( Sidebar.Category( @@ -49,4 +114,26 @@ class SidebarParserTest: None ), Sidebar.load(sidebar)(using testContext) - ) \ No newline at end of file + ) + + @Test + def loadSidebarNoPageError: Unit = + val out = new ByteArrayOutputStream() + Console.withErr(new PrintStream(out)) { + Sidebar.load(sidebarErrorNoPage)(using testContext) + } + println(out.toString()) + val error = out.toString().trim() + + assert(error.contains(msgNoPage) && error.contains(schemaMessage)) + + + @Test + def loadSidebarNoTitleError(): Unit = + val out = new ByteArrayOutputStream() + Console.withErr(new PrintStream(out)) { + Sidebar.load(sidebarNoTitle)(using testContext) + } + val error = out.toString().trim() + + assert(error.contains(msgNoTitle) && error.contains(schemaMessage)) \ No newline at end of file