diff --git a/composer.lock b/composer.lock index 5b0f0bb3e..d7d77ee8f 100644 --- a/composer.lock +++ b/composer.lock @@ -405,16 +405,16 @@ }, { "name": "hhvm/hhast", - "version": "v4.15.0", + "version": "v4.15.1", "source": { "type": "git", "url": "https://github.com/hhvm/hhast.git", - "reference": "6b127b01616bf61139b931200320c901815ecf83" + "reference": "82ac0e7f15ee67c4299335dbd02b62c12ae74f81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hhvm/hhast/zipball/6b127b01616bf61139b931200320c901815ecf83", - "reference": "6b127b01616bf61139b931200320c901815ecf83", + "url": "https://api.github.com/repos/hhvm/hhast/zipball/82ac0e7f15ee67c4299335dbd02b62c12ae74f81", + "reference": "82ac0e7f15ee67c4299335dbd02b62c12ae74f81", "shasum": "" }, "require": { @@ -449,7 +449,7 @@ "license": [ "MIT" ], - "time": "2019-07-22T16:33:23+00:00" + "time": "2019-08-01T21:11:43+00:00" }, { "name": "hhvm/hhvm-autoload", diff --git a/src/hh-apidoc-extensions/PageSections/Examples.php b/src/hh-apidoc-extensions/PageSections/Examples.php index 1ea4139cf..44f0c18fa 100644 --- a/src/hh-apidoc-extensions/PageSections/Examples.php +++ b/src/hh-apidoc-extensions/PageSections/Examples.php @@ -18,19 +18,20 @@ final class Examples extends PageSection { <<__Override>> public function getMarkdown(): ?string { - $path = LocalConfig::ROOT.'/api-examples/'; if ($this->parent !== null) { - $path .= 'class.'.$this->parent->getName().'/'; + $subdirectory = 'class.'.$this->parent->getName().'/'; } else { - $path .= 'function'; + $subdirectory = 'function.'; } - $path .= Str\replace( - $this->definition->getName(), - "\\", - '.', + $subdirectory .= $this->definition->getName(); + + $path = Str\format( + '%s/api-examples/%s', + LocalConfig::ROOT, + Str\replace($subdirectory, '\\', '.'), ); - $examples = Vec\concat(\glob($path.'/*.php'), \glob($path.'/*.php')) + $examples = Vec\concat(\glob($path.'/*.md'), \glob($path.'/*.php')) |> Vec\map($$, $file ==> \pathinfo($file, \PATHINFO_FILENAME)) |> keyset($$); diff --git a/tests/APIPagesTest.php b/tests/APIPagesTest.php index 528386e93..5a5239f11 100644 --- a/tests/APIPagesTest.php +++ b/tests/APIPagesTest.php @@ -6,11 +6,12 @@ APIDefinitionType, APINavData, APIProduct, + LocalConfig, NavDataNode, URLBuilder, }; -use namespace HH\Lib\Vec; +use namespace HH\Lib\{Str, Vec}; use function Facebook\FBExpect\expect; use type Facebook\HackTest\{DataProvider, TestGroup}; @@ -177,4 +178,28 @@ public function getDoNotDocument(): vec<(string, APIDefinitionType)> { \sprintf('"%s" should not be documented', $name), ); } + + public function getPagesWithExamples(): vec> { + $root = LocalConfig::ROOT.'/api-examples'; + $urls = keyset[]; + foreach (\glob($root.'/class.*/*') as $dir) { + if (!\is_dir($dir)) { + continue; + } + $urls[] = Str\replace($dir, $root.'/class.', 'class/'); + } + foreach (\glob($root.'/function.*') as $dir) { + $urls[] = Str\replace($dir, $root.'/function.', 'function/'); + } + return Vec\map($urls, $url ==> vec['/hack/reference/'.$url.'/']); + } + + <> + public async function testExamples(string $url): Awaitable { + list($response, $body) = await PageLoader::getPageAsync($url); + expect($response->getStatusCode()) + ->toBeSame(200, 'Examples provided for non-existent page %s.', $url); + expect(Str\contains($body, '')) + ->toBeTrue('Missing examples at %s.', $url); + } }