diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-18 04:42:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-18 04:42:05 +0100 |
| commit | be3d25bd7800b67bb7675a3d74445de305fcff3d (patch) | |
| tree | 888a6e5c07700dc3ddd23ae39309d3a79bc62ed0 /src | |
| parent | 6a5663ed822f81e1c3c9b18a28358b1aed22db13 (diff) | |
| parent | 9c6d8ef80c3525a10d2d51a7db2c93495857cfac (diff) | |
| download | rust-be3d25bd7800b67bb7675a3d74445de305fcff3d.tar.gz rust-be3d25bd7800b67bb7675a3d74445de305fcff3d.zip | |
Rollup merge of #92914 - camelid:snapshot-text, r=GuillaumeGomez
htmldocck: Add support for `/text()` in `@snapshot` This allows just testing the text, in cases where the HTML tags don't matter. See https://github.com/rust-lang/rust/pull/92908#discussion_r785191758 for an example of when this would be useful. r? `@GuillaumeGomez`
Diffstat (limited to 'src')
| -rw-r--r-- | src/etc/htmldocck.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index 48a341ffe08..6bb235b2c83 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -401,7 +401,7 @@ def get_tree_count(tree, path): return len(tree.findall(path)) -def check_snapshot(snapshot_name, tree): +def check_snapshot(snapshot_name, tree, normalize_to_text): assert rust_test_path.endswith('.rs') snapshot_path = '{}.{}.{}'.format(rust_test_path[:-3], snapshot_name, 'html') try: @@ -413,7 +413,10 @@ def check_snapshot(snapshot_name, tree): else: raise FailedCheck('No saved snapshot value') - actual_str = ET.tostring(tree).decode('utf-8') + if not normalize_to_text: + actual_str = ET.tostring(tree).decode('utf-8') + else: + actual_str = flatten(tree) if expected_str != actual_str: if bless: @@ -494,11 +497,16 @@ def check_command(c, cache): [snapshot_name, html_path, pattern] = c.args tree = cache.get_tree(html_path) xpath = normalize_xpath(pattern) + normalize_to_text = False + if xpath.endswith('/text()'): + xpath = xpath[:-7] + normalize_to_text = True + subtrees = tree.findall(xpath) if len(subtrees) == 1: [subtree] = subtrees try: - check_snapshot(snapshot_name, subtree) + check_snapshot(snapshot_name, subtree, normalize_to_text) ret = True except FailedCheck as err: cerr = str(err) |
