Skip to content

Commit 1573236

Browse files
committed
Test can use mocked docContext
1 parent 8685409 commit 1573236

9 files changed

+34
-31
lines changed

scala3doc/src/dotty/dokka/DocContext.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ case class DocContext(args: Scala3doc.Args, compilerContext: Context)
4242
override def getPluginsConfiguration: JList[DokkaConfiguration.PluginConfiguration] =
4343
JList()
4444

45-
lazy val mkSourceSet: DokkaSourceSet =
45+
val mkSourceSet: DokkaSourceSet =
4646
new DokkaSourceSetImpl(
4747
/*displayName=*/ args.name,
4848
/*sourceSetID=*/ new DokkaSourceSetID(args.name, "main"),
@@ -68,3 +68,5 @@ case class DocContext(args: Scala3doc.Args, compilerContext: Context)
6868
/*suppressedFiles=*/ JSet(),
6969
/*suppressedFiles=*/ Platform.jvm
7070
).asInstanceOf[DokkaSourceSet] // Why I do need to cast here? Kotlin magic?
71+
72+
val sourceSet = mkSourceSet.asInstanceOf[SourceSetWrapper]

scala3doc/src/dotty/dokka/ScalaModuleCreator.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import dotty.tools.dotc.core.Contexts._
1717

1818
class ScalaModuleProvider(using ctx: DocContext) extends SourceToDocumentableTranslator:
1919
override def invoke(sourceSet: DokkaSourceSet, cxt: DokkaContext, unused: Continuation[? >: DModule]) =
20-
val parser = new MarkdownParser(_ => null)
21-
val result = DokkaTastyInspector(sourceSet, parser).result()
20+
val result = DokkaTastyInspector(new MarkdownParser(_ => null)).result()
2221

2322
def flattenMember(m: Member): Seq[(DRI, Member)] = (m.dri -> m) +: m.allMembers.flatMap(flattenMember)
2423

scala3doc/src/dotty/dokka/tasty/BasicSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait BasicSupport:
3636
extension (sym: Symbol):
3737
def documentation = sym.documentation match
3838
case Some(comment) =>
39-
Map(sourceSet -> parseComment(comment, sym.tree))
39+
Map(ctx.sourceSet -> parseComment(comment, sym.tree))
4040
case None =>
4141
Map.empty
4242

scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ trait ClassLikeSupport:
1717
self: TastyParser =>
1818
import qctx.reflect._
1919

20-
private val placeholderVisibility = JMap(sourceSet -> KotlinVisibility.Public.INSTANCE)
21-
private val placeholderModifier = JMap(sourceSet -> KotlinModifier.Empty.INSTANCE)
20+
private val placeholderVisibility = JMap(ctx.sourceSet -> KotlinVisibility.Public.INSTANCE)
21+
private val placeholderModifier = JMap(ctx.sourceSet -> KotlinModifier.Empty.INSTANCE)
2222

2323
private def kindForClasslike(sym: Symbol): Kind =
2424
if sym.flags.is(Flags.Object) then Kind.Object
@@ -90,7 +90,7 @@ trait ClassLikeSupport:
9090
classDef.symbol.documentation.asJava,
9191
null,
9292
placeholderModifier,
93-
inspector.sourceSet.toSet,
93+
ctx.sourceSet.toSet,
9494
/*isExpectActual =*/ false,
9595
fullExtra.asInstanceOf[PropertyContainer[DClass]]
9696
)
@@ -109,9 +109,9 @@ trait ClassLikeSupport:
109109
case dd: DefDef if !dd.symbol.isHiddenByVisibility && !dd.symbol.isSyntheticFunc && dd.symbol.isExtensionMethod =>
110110
dd.symbol.extendedSymbol.map { extSym =>
111111
val target = ExtensionTarget(
112-
extSym.symbol.normalizedName,
113-
extSym.tpt.dokkaType.asSignature,
114-
extSym.tpt.symbol.dri,
112+
extSym.symbol.normalizedName,
113+
extSym.tpt.dokkaType.asSignature,
114+
extSym.tpt.symbol.dri,
115115
extSym.symbol.pos.start
116116
)
117117
parseMethod(dd.symbol, kind = Kind.Extension(target))
@@ -306,7 +306,7 @@ trait ClassLikeSupport:
306306
/*generics =*/ genericTypes.map(parseTypeArgument).asJava,
307307
/*receiver =*/ null, // Not used
308308
/*modifier =*/ placeholderModifier,
309-
sourceSet.toSet,
309+
ctx.sourceSet.toSet,
310310
/*isExpectActual =*/ false,
311311
PropertyContainer.Companion.empty()
312312
plus MethodExtension(paramLists.map(_.size))
@@ -327,7 +327,7 @@ trait ClassLikeSupport:
327327
argument.symbol.documentation.asJava,
328328
null,
329329
argument.tpt.dokkaType,
330-
sourceSet.toSet,
330+
ctx.sourceSet.toSet,
331331
PropertyContainer.Companion.empty()
332332
.plus(ParameterExtension(isExtendedSymbol, isGrouped))
333333
.plus(MemberExtension.empty.copy(annotations = argument.symbol.getAnnotations()))
@@ -345,7 +345,7 @@ trait ClassLikeSupport:
345345
argument.symbol.documentation.asJava,
346346
null,
347347
JList(argument.rhs.dokkaType),
348-
sourceSet.toSet,
348+
ctx.sourceSet.toSet,
349349
PropertyContainer.Companion.empty()
350350
)
351351

@@ -374,7 +374,7 @@ trait ClassLikeSupport:
374374
/*setter =*/ null,
375375
/*getter =*/ null,
376376
/*modifier =*/ placeholderModifier,
377-
sourceSet.toSet,
377+
ctx.sourceSet.toSet,
378378
/*generics =*/ generics.asJava, // TODO
379379
/*isExpectActual =*/ false,
380380
PropertyContainer.Companion.empty() plus MemberExtension(
@@ -405,7 +405,7 @@ trait ClassLikeSupport:
405405
/*setter =*/ null,
406406
/*getter =*/ null,
407407
/*modifier =*/ placeholderModifier,
408-
sourceSet.toSet,
408+
ctx.sourceSet.toSet,
409409
/*generics =*/ JList(),
410410
/*isExpectActual =*/ false,
411411
PropertyContainer.Companion.empty().plus(MemberExtension(

scala3doc/src/dotty/dokka/tasty/PackageSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait PackageSupport:
2525
JList(),
2626
documentation.asJava,
2727
null,
28-
sourceSet.toSet,
28+
ctx.sourceSet.toSet,
2929
PropertyContainer.Companion.empty()
3030
)
3131
}
@@ -41,7 +41,7 @@ trait PackageSupport:
4141
JList(),
4242
pckObj.symbol.documentation.asJava,
4343
null,
44-
sourceSet.toSet,
44+
ctx.sourceSet.toSet,
4545
PropertyContainer.Companion.empty()
4646
.plus(clazz.get(CompositeMemberExtension))
4747
)

scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trait ScaladocSupport { self: TastyParser =>
3939
println(s"WARN: Defaulting to Markdown syntax.")
4040
CommentSyntax.default
4141
}
42-
case None => self.config.args.defaultSyntax
42+
case None => ctx.args.defaultSyntax
4343
}
4444

4545
val parser = commentSyntax match {

scala3doc/src/dotty/dokka/tasty/TastyParser.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ case class DokkaTastyInspector(parser: Parser)(using ctx: DocContext) extends Do
7171
JList(),
7272
f.getDocumentation,
7373
null,
74-
sourceSet.toSet,
74+
JSet(ctx.sourceSet),
7575
f.getExtra
7676
).withNewMembers(entries.filterNot(_.isInstanceOf[DPackage]).toList).asInstanceOf[DPackage]
7777
)
@@ -80,7 +80,7 @@ case class DokkaTastyInspector(parser: Parser)(using ctx: DocContext) extends Do
8080
}.toList
8181

8282
extension (self: DPackage) def mergeWith(other: DPackage): DPackage =
83-
def nodes(p: DPackage): JList[TagWrapper] = p.getDocumentation.get(sourceSet) match
83+
def nodes(p: DPackage): JList[TagWrapper] = p.getDocumentation.get(ctx.sourceSet) match
8484
case null => JList[TagWrapper]()
8585
case node => node.getChildren
8686

@@ -91,22 +91,20 @@ case class DokkaTastyInspector(parser: Parser)(using ctx: DocContext) extends Do
9191
(self.getProperties.asScala ++ other.getProperties.asScala).asJava,
9292
JList(), // WARNING Merging is done before collecting classlikes, if it changes it needs to be refactored
9393
JList(),
94-
sourceSet.toMap(DocumentationNode(nodes(self) ++ nodes(other))),
94+
ctx.sourceSet.toMap(DocumentationNode(nodes(self) ++ nodes(other))),
9595
null,
96-
sourceSet.toSet,
96+
ctx.sourceSet.toSet,
9797
PropertyContainer.Companion.empty()
9898
),
9999
self,
100100
other
101101
)
102102

103103
/** Parses a single Tasty compilation unit. */
104-
case class TastyParser(qctx: Quotes, inspector: DokkaTastyInspector)(using DocContext)
104+
case class TastyParser(qctx: Quotes, inspector: DokkaTastyInspector)(using val ctx: DocContext)
105105
extends ScaladocSupport with BasicSupport with TypesSupport with ClassLikeSupport with SyntheticsSupport with PackageSupport with NameNormalizer:
106106
import qctx.reflect._
107107

108-
def sourceSet = inspector.sourceSet
109-
110108
def processTree[T](tree: Tree)(op: => T): Option[T] = try Option(op) catch case e: Throwable => errorMsg(tree, tree.symbol.show, e)
111109
def processTreeOpt[T](tree: Tree)(op: => Option[T]): Option[T] = try op catch case e: Throwable => errorMsg(tree, tree.symbol.show, e)
112110
def processSymbol[T](sym: Symbol)(op: => T): Option[T] = try Option(op) catch case e: Throwable => errorMsg(sym, sym.show, e)

scala3doc/test/dotty/dokka/RaportingTest.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ class ReportingTest:
2020

2121
val dest = Files.createTempDirectory("test-doc")
2222
try
23-
val args = Args(
24-
name = "Test Project Name",
25-
output = dest.toFile,
26-
tastyFiles = tastyFiles("nested") // Random package
27-
)
28-
Scala3doc.run(newArgs(args))(using ctx)
23+
// We are using random package
24+
Scala3doc.run(newArgs(testArgs(tastyFiles("nested"), dest.toFile)))(using ctx)
2925
op(ctx.reportedDiagnostics)
3026

3127
finally IO.delete(dest.toFile)

scala3doc/test/dotty/dokka/testUtils.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ class TestReporter extends ConsoleReporter:
4848
warnings += dia
4949
super.doReport(dia)
5050

51+
def testArgs(files: Seq[File] = Nil, dest: File = new File("notUsed")) = Scala3doc.Args(
52+
name = "Test Project Name",
53+
output = dest,
54+
tastyFiles = files
55+
)
56+
5157
def testContext = (new ContextBase).initialCtx.fresh.setReporter(new TestReporter)
5258

59+
def testDocContext = DocContext(testArgs(), testContext)
60+
5361
def tastyFiles(name: String) =
5462
def listFilesSafe(dir: File) = Option(dir.listFiles).getOrElse {
5563
throw AssertionError(s"$dir not found. The test name is incorrect or scala3doc-testcases were not recompiled.")

0 commit comments

Comments
 (0)