Skip to content

Cleaning up tests in scala3doc #10170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 10, 2020
Merged

Cleaning up tests in scala3doc #10170

merged 5 commits into from
Nov 10, 2020

Conversation

Kordyjan
Copy link
Contributor

@Kordyjan Kordyjan commented Nov 4, 2020

The goals of this PR:

  • extracting one class that can be used as a configurable base for any kind of tests inspecting documentation model
  • migrating signature tests to the new base, tidying up their code in the process
  • enabling using more complex names in signatures as for now they weren't tested at all

Problems and questions:

  • Newly added tests revealed that scala3doc is skipping backticks in symbol names so:
    def `*name with backticks*`(param: Int): Int is documented asdef *name with backticks*(param: Int): Int. Is this the desired behavior?

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@abgruszecki
Copy link
Contributor

@Kordyjan we should print the backticks I think, but I'm not sure if there's an obvious way to do that. We may want to open a separate issue for that.

Copy link
Contributor

@romanowski romanowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

There is few nit-picks and I've asked for a few new features but this can be added in followup PR.

@pikinier20 could you take a look as well?

def +:(other: Int): A
def :+(other: Int): A
// scala3doc has problems with names in backticks
// def `multi word name`: Int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need a issue for it

cc @nicolasstucki

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are we missing here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print a name that needs backticks in backticks, I believe.

This makes sense to include in Tasty-Reflect, since the general concept is being able to print a name in a form that corresponds to how it was entered in source. I'm not certain what's the best way to do that, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to introduce a Name abstraction in the reflection API. A String loses too much information about the name. We cannot distinguish semantic names from simple names and we cannot know if they were backticked. That is on my TODO list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for now we can just fix that in scala3doc: lampepfl/scala3doc#235 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kordyjan I'd rather avoid the code duplication, but I suppose that the regex for Scala identifiers that don't need a backtick is unlikely to change anytime soon. Can you wrap the code for detecting whether an identifier needs a backtick in a function whose name starts with hack, so we can grep for it easily? We have a bunch of functions like that in the doctool already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we won't have that info. The scaladoc will need to figure it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abgruszecki: #10199 is ready.

)

private def tastyFiles =
def collectFiles(dir: File): List[String] = dir.listFiles.toList.flatMap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listFiles can return null if directory does not exisits so we should check that and print proper error message

*/
enum Assertion:
case AfterPluginSetup(fn: DokkaContext => Unit)
case DuringValidation(fn: (() => Unit) => Unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to make this signature more explanatory. Probably does not need to match 1-to-1 to its Kotlin version

case AfterDocumentablesTransformation(fn: DModule => Unit)
case AfterPagesGeneration(fn: RootPageNode => Unit)
case AfterPagesTransformation(fn: RootPageNode => Unit)
case AfterRendering(fn: (RootPageNode, DokkaContext) => Unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should turn RootPageNode => Unit and (RootPageNode, DokkaContext) => Unit into traits and provide helper methods, e.g. option to inspect all pages or output of rendering or location of rendered page

)

extension [T] (s: T):
private def kUnit = kotlin.Unit.INSTANCE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, probably we can unified the kotlin.Unit handling in whole codebase after this PR is merged.

.flatMap(signaturesFromSources(_, signatureKinds))
.toList
val expectedFromSources: Map[String, List[String]] = allSignaturesFromSources
.collect { case Expected(name, signature) => name -> signature }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allSignaturesFromSources.collect { case e: Expected => e}.groupMap(_.name)(_.signature)

findName(signature, signatureKinds).map(_ -> signature)
}.groupMap(_._1)(_._2)

val unexpected = unexpectedFromSources.flatMap(actualSignatures.getOrElse(_, Nil))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpectedFromSources.flatMap(actualSignatures.get) should work here

@romanowski romanowski merged commit 9a47067 into scala:master Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants