Skip to content

Commit f5fd510

Browse files
committed
Fix top level index. Add integration tests for indexes.
1 parent eb8773e commit f5fd510

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

scaladoc/src/dotty/tools/scaladoc/renderers/Locations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait Locations(using ctx: DocContext):
3535
val path = dri match
3636
case `docsRootDRI` => List("docs", "index")
3737
case `apiPageDRI` =>
38-
if ctx.args.apiSubdirectory || ctx.staticSiteContext.fold(false)(_.hasIndexFile)
38+
if ctx.staticSiteContext.fold(false)(_.hasIndexFile)
3939
then List("api", "index")
4040
else List("index")
4141
case dri if dri.isStaticFile =>

scaladoc/test/dotty/tools/scaladoc/BaseHtmlTest.scala

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ class BaseHtmlTest:
2323
withGeneratedDoc(Seq("site"), docsRoot = Some(base.toAbsolutePath.toString))(op)
2424

2525
def withGeneratedDoc(
26-
pcks: Seq[String],
27-
docsRoot: Option[String] = None)(
28-
op: ProjectContext ?=> Unit,
26+
pcks: Seq[String],
27+
docsRoot: Option[String] = None,
28+
customArgs: Option[Scaladoc.Args] = None,
29+
)(
30+
op: ProjectContext ?=> Unit,
2931
): Unit =
30-
val dest = Files.createTempDirectory("test-doc")
32+
val dest = customArgs.map(_.output).getOrElse(Files.createTempDirectory("test-doc").toFile)
3133
try
32-
val args = Scaladoc.Args(
33-
name = projectName,
34-
tastyFiles = pcks.flatMap(tastyFiles(_)),
35-
output = dest.toFile,
36-
docsRoot = docsRoot,
37-
projectVersion = Some(projectVersion)
38-
)
34+
val args = customArgs.getOrElse(Scaladoc.Args(
35+
name = projectName,
36+
tastyFiles = pcks.flatMap(tastyFiles(_)),
37+
output = dest,
38+
docsRoot = docsRoot,
39+
projectVersion = Some(projectVersion)
40+
))
3941
Scaladoc.run(args)(using testContext)
40-
op(using ProjectContext(dest))
42+
op(using ProjectContext(args.output.toPath))
4143

42-
finally IO.delete(dest.toFile)
44+
finally IO.delete(dest)
4345

4446
class DocumentContext(d: Document, path: Path):
4547
import collection.JavaConverters._
@@ -49,7 +51,7 @@ class BaseHtmlTest:
4951
def assertTextsIn(selector: String, expected: String*) =
5052
assertFalse(niceMsg(s"Selector not found for '$selector'"), d.select(selector).isEmpty)
5153
val found = d.select(selector).eachText.asScala
52-
assertEquals(niceMsg(s"Context does not match for '$selector'"), expected.toList, found.toList)
54+
assertEquals(niceMsg(s"Content does not match for '$selector'"), expected.toList, found.toList)
5355

5456
def assertAttr(selector: String, attr: String, expected: String*) =
5557
assertFalse(niceMsg(s"Selector '$selector' not found"), d.select(selector).isEmpty)
@@ -60,6 +62,9 @@ class BaseHtmlTest:
6062
val msg = niceMsg(s"Selector '$selector' exisits in document")
6163
assertTrue(msg, d.select(selector).isEmpty)
6264

65+
def fileExists =
66+
assertTrue(path.toFile.exists)
67+
6368
def withHtmlFile(pathStr: String)(op: DocumentContext => Unit)(using ProjectContext) =
6469
val path = summon[ProjectContext].path.resolve(pathStr)
6570
assertTrue(s"File at $path does not exisits!", Files.exists(path))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dotty.tools.scaladoc
2+
package site
3+
4+
import org.junit.Test
5+
import java.nio.file.Files
6+
7+
class IndexPagesTest extends BaseHtmlTest:
8+
9+
10+
private val baseArgs = Scaladoc.Args(
11+
name = projectName,
12+
tastyFiles = Seq("site").flatMap(tastyFiles(_)),
13+
output = Files.createTempDirectory("test-doc").toFile,
14+
projectVersion = Some(projectVersion)
15+
)
16+
17+
@Test
18+
def staticSiteAndApiSubdirectory = gridTest(baseArgs.copy(docsRoot = Some(testDocPath.resolve("noIndexes").toAbsolutePath.toString), apiSubdirectory = true))
19+
20+
@Test
21+
def staticSiteAndNOApiSubdirectoryAndReadyToGoIndex = gridTest(baseArgs.copy(docsRoot = Some(testDocPath.resolve("basic").toAbsolutePath.toString), apiSubdirectory = false))
22+
23+
@Test
24+
def staticSiteAndApiSubdirectoryAndReadyToGoIndex = gridTest(baseArgs.copy(docsRoot = Some(testDocPath.resolve("basic").toAbsolutePath.toString), apiSubdirectory = true))
25+
26+
@Test
27+
def staticSiteAndNOApiSubdirectory = gridTest(baseArgs.copy(docsRoot = Some(testDocPath.resolve("noIndexes").toAbsolutePath.toString), apiSubdirectory = false))
28+
29+
@Test
30+
def NOstaticSiteAndApSubdirectory = gridTest(baseArgs.copy(docsRoot = None, apiSubdirectory = true))
31+
32+
@Test
33+
def NOstaticSiteAndNOApiSubdirectory = gridTest(baseArgs.copy(docsRoot = None, apiSubdirectory = false))
34+
35+
private def gridTest(args: Scaladoc.Args) = withGeneratedDoc(Seq.empty, None, customArgs = Some(args)) {
36+
println(args.output)
37+
withHtmlFile("index.html") { content =>
38+
content.fileExists
39+
}
40+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NavigationTest extends BaseHtmlTest:
2222

2323

2424
@Test
25-
def testBasicNavigation() = withGeneratedSite(testDocPath.resolve("basic")){
25+
def testBasicNavigation() = withGeneratedSite(testDocPath.resolve("basic")) {
2626
val topLevelNav = NavMenuTestEntry(projectName, "index.html", Seq(
2727
NavMenuTestEntry("A directory", "dir/index.html", Seq(
2828
NavMenuTestEntry("Nested in a directory", "dir/nested.html", Nil)

0 commit comments

Comments
 (0)