Skip to content

let htmldocck.py check for directories #44949

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 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
* `@count PATH XPATH COUNT' checks for the occurrence of given XPath
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`
checks if the given file does not exist, for example.

Expand Down Expand Up @@ -308,6 +310,12 @@ def get_tree(self, path):
self.trees[path] = tree
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):
if not pat:
Expand Down Expand Up @@ -407,6 +415,16 @@ def check_command(c, cache):
ret = expected == found
else:
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':
raise InvalidCheck('Unimplemented @valid-html')

Expand Down
3 changes: 3 additions & 0 deletions src/test/rustdoc/inline_local/glob-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ pub use mod1::*;
// @has foo/struct.Mod2Public.html
// @!has foo/struct.Mod2Private.html

// @has-dir foo/mod1
// @!has foo/mod1/index.html
// @has foo/mod1/struct.Mod1Public.html
// @!has foo/mod1/struct.Mod1Private.html
// @!has foo/mod1/struct.Mod2Public.html
// @!has foo/mod1/struct.Mod2Private.html

// @has-dir foo/mod1/mod2
// @!has foo/mod1/mod2/index.html
// @has foo/mod1/mod2/struct.Mod2Public.html
// @!has foo/mod1/mod2/struct.Mod2Private.html

// @!has-dir foo/mod2
// @!has foo/mod2/index.html
// @!has foo/mod2/struct.Mod2Public.html
// @!has foo/mod2/struct.Mod2Private.html