-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add automated test to check if scaladoc sourcelinks are correctly pointing to remote repository #11512
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
BarkingBad
merged 5 commits into
scala:master
from
BarkingBad:scala3doc/source-links-tests
May 11, 2021
Merged
Add automated test to check if scaladoc sourcelinks are correctly pointing to remote repository #11512
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c382e9
Add automated test to check if sourcelinks are correctly pointing to …
BarkingBad 2f77e5c
Add e2e tests for sourcelinks of standard library of scala3
BarkingBad d805188
Make test choose random 20 links
BarkingBad 4cb278e
Add unit tests for source links existance
BarkingBad 37ed4b7
Apply requested changes
BarkingBad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def toplevelDef = 123 | ||
|
||
class ToplevelClass | ||
class ToplevelClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,4 +140,3 @@ object SourceLinks: | |
) | ||
SourceLinks(sourceLinks) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
scaladoc/test-source-links/dotty/tools/scaladoc/source-links/RemoteLinksTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package dotty.tools.scaladoc | ||
package sourcelinks | ||
|
||
import scala.util.Random | ||
import scala.io.Source | ||
import scala.jdk.CollectionConverters._ | ||
import scala.util.matching.Regex | ||
import dotty.tools.scaladoc.test.BuildInfo | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import util.IO | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class RemoteLinksTest: | ||
|
||
class TimeoutException extends Exception | ||
|
||
val randomGenerator = new Random(125L) | ||
val mtslAll = membersToSourceLinks(using testDocContext()) | ||
|
||
@Test | ||
def scala213XSourceLink = | ||
assertTrue(mtslAll.find((k, _) => k == "AbstractMap").isDefined) // source link to Scala2.13.X stdlib class | ||
|
||
@Test | ||
def scala3SourceLink = | ||
assertTrue(mtslAll.find((k, _) => k == "PolyFunction").isDefined) // source link to Scala3 stdlib class | ||
|
||
@Test | ||
def runTest = | ||
assertTrue(mtslAll.nonEmpty) | ||
val mtsl = randomGenerator.shuffle(mtslAll).take(20) // take 20 random entries | ||
val pageToMtsl: Map[String, List[(String, String)]] = mtsl.groupMap(_._2.split("#L").head)(v => (v._1, v._2.split("#L").last)) | ||
pageToMtsl.foreach { case (link, members) => | ||
try | ||
val doc = getDocumentFromUrl(link) | ||
members.foreach { (member, line) => | ||
if !member.startsWith("given_") then // TODO: handle synthetic givens, for now we disable them from testing | ||
val loc = doc.select(s"#LC$line").text | ||
val memberToMatch = member.replace("`", "") | ||
assertTrue(s"Expected to find $memberToMatch at $link at line $line", loc.contains(memberToMatch)) | ||
} | ||
catch | ||
case e: java.lang.IllegalArgumentException => | ||
report.error(s"Could not open link for $link - invalid URL")(using testContext) | ||
case e: TimeoutException => | ||
report.error(s"Tried to open link $link 16 times but with no avail")(using testContext) | ||
case e: org.jsoup.HttpStatusException => e.getStatusCode match | ||
case 404 => throw AssertionError(s"Page $link does not exists") | ||
case n => report.warning(s"Could not open link for $link, return code $n")(using testContext) | ||
} | ||
assertNoErrors(testContext.reportedDiagnostics) | ||
|
||
private def getDocumentFromUrl(link: String, retries: Int = 16): Document = | ||
try | ||
if retries == 0 then throw TimeoutException() | ||
Jsoup.connect(link).get | ||
catch | ||
case e: org.jsoup.HttpStatusException => e.getStatusCode match | ||
case 429 => | ||
Thread.sleep(10) | ||
getDocumentFromUrl(link, retries - 1) | ||
case n => | ||
throw e | ||
|
||
private def membersToSourceLinks(using DocContext): List[(String, String)] = | ||
val output = Paths.get("scaladoc", "output", "scala3", "api").toAbsolutePath | ||
val mtsl = List.newBuilder[(String, String)] | ||
def processFile(path: Path): Unit = | ||
val document = Jsoup.parse(IO.read(path)) | ||
if document.select("span.kind").first.text == "package" then | ||
document.select(".documentableElement").forEach { dElem => | ||
if dElem.select("span.kind").first.text != "package" then | ||
dElem.select("dt").forEach { elem => | ||
val content = elem.text | ||
if content == "Source" then | ||
mtsl += dElem.select(".documentableName").first.text -> elem.nextSibling.childNode(0).attr("href") | ||
} | ||
} | ||
IO.foreachFileIn(output, processFile) | ||
mtsl.result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.