Skip to content
Open
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
23 changes: 23 additions & 0 deletions tests/test_progress_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,29 @@ def test_paths_outside_the_repository_lose_their_file_name(self):
self.assertEqual(pd.scrub("in " + os.path.join(pd.HOME, "work", f"{SENTINEL}.fssm")), "in <path>")
self.assertEqual(pd.scrub(f"C:{sep}work{sep}{SENTINEL}_a.fssm, C:{sep}{SENTINEL}_b.fssm"), "<path> <path>")

def test_drive_paths_with_spaces_lose_their_whole_name(self):
for line, want in (
(rf"FAIL: cannot read D:\My work\shaders\{SENTINEL}.fssm", "FAIL: cannot read <path>"),
(rf"D:\My work\a b c\{SENTINEL}.fssm line 3", "<path> line 3"),
(rf"D:\My work\{SENTINEL}_a.fssm, D:\Other work\{SENTINEL}_b.fssm", "<path> <path>"),
(f"FAIL: cannot read D:/My work/shaders/{SENTINEL}.fssm", "FAIL: cannot read <path>"),
(rf"cannot read D:/My work\fixtures\{SENTINEL}.txt", "cannot read <path>"),
(rf"cannot read D:\My work/stubs/{SENTINEL}.spv", "cannot read <path>"),
(rf"D:\My own work/sub dir\a b/{SENTINEL}.fssm line 3", "<path> line 3"),
(rf"D:\My work/{SENTINEL}_a.fssm, D:/Other work\{SENTINEL}_b.fssm", "<path> <path>"),
(rf"Permission denied: 'D:\\My work\\{SENTINEL} one.fssm'", "Permission denied: '<path>'"),
(rf'File "D:\My work\{SENTINEL} one.py", line 3', 'File "<path>", line 3'),
(r"D:\work\a.txt is not a folder", "<path> is not a folder"),
(r"D:\work\a.txt, then tests/test_x.py failed", "<path> then tests/test_x.py failed"),
(r"D:\work\a.txt and tests/test_x.py failed", "<path> and tests/test_x.py failed"),
(r"D:\work\a.txt is 3/4 done", "<path> is 3/4 done"),
):
with self.subTest(line=line):
self.assertEqual(pd.scrub(line), want)
if os.name == "nt":
sibling = os.path.join(ROOT + " work", f"{SENTINEL} one.fssm")
self.assertEqual(pd.scrub(f"cannot read '{sibling}' now"), "cannot read '<path>' now")

def test_paths_inside_the_repository_become_relative(self):
line = "Error: " + os.path.join(ROOT, "tools", "text_tables.py") + " line 3"
self.assertEqual(pd.scrub(line), "Error: tools/text_tables.py line 3")
Expand Down
12 changes: 10 additions & 2 deletions tools/progress_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,17 @@ def shown(m):
checkout = rf"(?<![\w.:/~]){re.escape(ROOT)}"
# Consume a same-prefix sibling too, so shown() can redact its entire path.
checkout_path = rf"{checkout}[^\s'\"]*"
drive_path = r"(?i:\b[a-z]:[\\/][^\s'\"]*)"
# A quoted drive path ends at its quote. An unquoted one goes on over spaces while a later part still has its
# separator, so `D:\My work\name` is one path and the prose after a path stays. The other separator continues it
# too (`D:/My work\name`), but only after a part with no dot or punctuation: the prose after a file has slashes.
drive = r"\b[a-z]:"
quoted_path = rf"(?i:(?<='){drive}[\\/][^']*(?=')|(?<=\"){drive}[\\/][^\"]*(?=\"))"
more = r"(?:(?: +(?![a-z]:[\\/])[^\s'\"\\/]+)*? +(?![a-z]:[\\/])[^\s'\"\\/]+{sep}[^\s'\"]*)*"
folder = r"(?:[^\s'\"]*[\\/])?[^\s'\"\\/.,;:]*"
mixed = rf"(?:{folder}(?: +[^\s'\"\\/.,;:]+)*? +[^\s'\"\\/:]+[\\/])*"
drive_path = "(?i:" + "|".join(rf"{drive}{sep}{mixed}[^\s'\"]*" + more.format(sep=sep) for sep in (r"\\", "/")) + ")"
posix_path = r"(?<![\w.:/~])/[^\s/'\"][^\s'\"]*"
line = re.sub(rf"{checkout_path}|{drive_path}|{posix_path}", shown, line)
line = re.sub(rf"{quoted_path}|{checkout_path}|{drive_path}|{posix_path}", shown, line)
if HOME and len(HOME) > 3:
line = line.replace(HOME, "~")
line = re.sub(r"~[\\/][^\s'\"]*", "<path>", line)
Expand Down
Loading