Auto merge of #44949 - QuietMisdreavus:rustdoctest-dirs, r=nikomatsakis

let htmldocck.py check for directories

Since i messed this up during https://github.com/rust-lang/rust/pull/44613, i wanted to codify this into the rustdoc tests to make sure that doesn't happen again.
This commit is contained in:
bors 2017-10-03 19:38:33 +00:00
commit 4502e2aa9c
2 changed files with 21 additions and 0 deletions

View File

@ -99,6 +99,8 @@ There are a number of supported commands:
* `@count PATH XPATH COUNT' checks for the occurrence of given XPath * `@count PATH XPATH COUNT' checks for the occurrence of given XPath
in the given file. The number of occurrences must match the given count. in the given file. The number of occurrences must match the given count.
* `@has-dir PATH` checks for the existence of the given directory.
All conditions can be negated with `!`. `@!has foo/type.NoSuch.html` All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
checks if the given file does not exist, for example. checks if the given file does not exist, for example.
@ -308,6 +310,12 @@ class CachedFiles(object):
self.trees[path] = tree self.trees[path] = tree
return self.trees[path] return self.trees[path]
def get_dir(self, path):
path = self.resolve_path(path)
abspath = os.path.join(self.root, path)
if not(os.path.exists(abspath) and os.path.isdir(abspath)):
raise FailedCheck('Directory does not exist {!r}'.format(path))
def check_string(data, pat, regexp): def check_string(data, pat, regexp):
if not pat: if not pat:
@ -407,6 +415,16 @@ def check_command(c, cache):
ret = expected == found ret = expected == found
else: else:
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd)) raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
elif c.cmd == 'has-dir': # has-dir test
if len(c.args) == 1: # @has-dir <path> = has-dir test
try:
cache.get_dir(c.args[0])
ret = True
except FailedCheck as err:
cerr = str(err)
ret = False
else:
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
elif c.cmd == 'valid-html': elif c.cmd == 'valid-html':
raise InvalidCheck('Unimplemented @valid-html') raise InvalidCheck('Unimplemented @valid-html')

View File

@ -34,16 +34,19 @@ pub use mod1::*;
// @has foo/struct.Mod2Public.html // @has foo/struct.Mod2Public.html
// @!has foo/struct.Mod2Private.html // @!has foo/struct.Mod2Private.html
// @has-dir foo/mod1
// @!has foo/mod1/index.html // @!has foo/mod1/index.html
// @has foo/mod1/struct.Mod1Public.html // @has foo/mod1/struct.Mod1Public.html
// @!has foo/mod1/struct.Mod1Private.html // @!has foo/mod1/struct.Mod1Private.html
// @!has foo/mod1/struct.Mod2Public.html // @!has foo/mod1/struct.Mod2Public.html
// @!has foo/mod1/struct.Mod2Private.html // @!has foo/mod1/struct.Mod2Private.html
// @has-dir foo/mod1/mod2
// @!has foo/mod1/mod2/index.html // @!has foo/mod1/mod2/index.html
// @has foo/mod1/mod2/struct.Mod2Public.html // @has foo/mod1/mod2/struct.Mod2Public.html
// @!has foo/mod1/mod2/struct.Mod2Private.html // @!has foo/mod1/mod2/struct.Mod2Private.html
// @!has-dir foo/mod2
// @!has foo/mod2/index.html // @!has foo/mod2/index.html
// @!has foo/mod2/struct.Mod2Public.html // @!has foo/mod2/struct.Mod2Public.html
// @!has foo/mod2/struct.Mod2Private.html // @!has foo/mod2/struct.Mod2Private.html