Skip to content

Commit 4502e2a

Browse files
committed
Auto merge of #44949 - QuietMisdreavus:rustdoctest-dirs, r=nikomatsakis
let htmldocck.py check for directories Since i messed this up during #44613, i wanted to codify this into the rustdoc tests to make sure that doesn't happen again.
2 parents 835e3e5 + 5b59c4d commit 4502e2a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/etc/htmldocck.py

+18
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
* `@count PATH XPATH COUNT' checks for the occurrence of given XPath
100100
in the given file. The number of occurrences must match the given count.
101101
102+
* `@has-dir PATH` checks for the existence of the given directory.
103+
102104
All conditions can be negated with `!`. `@!has foo/type.NoSuch.html`
103105
checks if the given file does not exist, for example.
104106
@@ -308,6 +310,12 @@ def get_tree(self, path):
308310
self.trees[path] = tree
309311
return self.trees[path]
310312

313+
def get_dir(self, path):
314+
path = self.resolve_path(path)
315+
abspath = os.path.join(self.root, path)
316+
if not(os.path.exists(abspath) and os.path.isdir(abspath)):
317+
raise FailedCheck('Directory does not exist {!r}'.format(path))
318+
311319

312320
def check_string(data, pat, regexp):
313321
if not pat:
@@ -407,6 +415,16 @@ def check_command(c, cache):
407415
ret = expected == found
408416
else:
409417
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
418+
elif c.cmd == 'has-dir': # has-dir test
419+
if len(c.args) == 1: # @has-dir <path> = has-dir test
420+
try:
421+
cache.get_dir(c.args[0])
422+
ret = True
423+
except FailedCheck as err:
424+
cerr = str(err)
425+
ret = False
426+
else:
427+
raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
410428
elif c.cmd == 'valid-html':
411429
raise InvalidCheck('Unimplemented @valid-html')
412430

src/test/rustdoc/inline_local/glob-private.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ pub use mod1::*;
3434
// @has foo/struct.Mod2Public.html
3535
// @!has foo/struct.Mod2Private.html
3636

37+
// @has-dir foo/mod1
3738
// @!has foo/mod1/index.html
3839
// @has foo/mod1/struct.Mod1Public.html
3940
// @!has foo/mod1/struct.Mod1Private.html
4041
// @!has foo/mod1/struct.Mod2Public.html
4142
// @!has foo/mod1/struct.Mod2Private.html
4243

44+
// @has-dir foo/mod1/mod2
4345
// @!has foo/mod1/mod2/index.html
4446
// @has foo/mod1/mod2/struct.Mod2Public.html
4547
// @!has foo/mod1/mod2/struct.Mod2Private.html
4648

49+
// @!has-dir foo/mod2
4750
// @!has foo/mod2/index.html
4851
// @!has foo/mod2/struct.Mod2Public.html
4952
// @!has foo/mod2/struct.Mod2Private.html

0 commit comments

Comments
 (0)