| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import importlib.util |
| 9 |
import os |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
from rsyncfns import SCRATCHDIR, SRCDIR, test_fail |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
SRC = Path(SRCDIR).resolve() |
| 18 |
|
| 19 |
spec = importlib.util.spec_from_file_location('runtests', SRC / 'runtests.py') |
| 20 |
runtests = importlib.util.module_from_spec(spec) |
| 21 |
spec.loader.exec_module(runtests) |
| 22 |
|
| 23 |
SUITE = str(SRC / 'testsuite') |
| 24 |
ERROR = f'exit:{runtests.Exit.ERROR}' |
| 25 |
|
| 26 |
|
| 27 |
def expand(text_spec, srcdir=None, suitedir=None): |
| 28 |
"""expand_skip_spec, but reporting a SystemExit as a string.""" |
| 29 |
try: |
| 30 |
return runtests.expand_skip_spec(text_spec, srcdir or str(SRC), |
| 31 |
suitedir or SUITE) |
| 32 |
except SystemExit as e: |
| 33 |
return f'exit:{e.code}' |
| 34 |
|
| 35 |
|
| 36 |
def write(name, body): |
| 37 |
p = SCRATCHDIR / name |
| 38 |
if isinstance(body, bytes): |
| 39 |
p.write_bytes(body) |
| 40 |
else: |
| 41 |
p.write_text(body) |
| 42 |
return '@' + str(p) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
FAKE = SCRATCHDIR / 'fakesuite' |
| 48 |
FAKE.mkdir(exist_ok=True) |
| 49 |
(FAKE / 'acls sparse_test.py').write_text('') |
| 50 |
(FAKE / 'foo,bar_test.py').write_text('') |
| 51 |
(FAKE / 'adir_test.py').mkdir(exist_ok=True) |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
for what, arg, suite in ( |
| 59 |
('missing file', '@testsuite/skiplist/does-not-exist.txt', None), |
| 60 |
('unknown test name', 'no-such-test-here', None), |
| 61 |
('unsorted list', write('unsorted.txt', 'sparse\nacls\n'), None), |
| 62 |
('duplicate entry', write('dup.txt', 'acls\nacls\n'), None), |
| 63 |
('stale name in a list', write('stale.txt', 'gone-away-test\n'), None), |
| 64 |
('empty file', write('empty.txt', ''), None), |
| 65 |
('comments only', write('comments.txt', '# nothing here\n\n'), None), |
| 66 |
('not valid text', write('binary.txt', b'acls\n\xff\xfe not utf-8\n'), None), |
| 67 |
('empty entry', 'acls,,sparse', None), |
| 68 |
('trailing comma', 'acls,', None), |
| 69 |
('leading comma', ',acls', None), |
| 70 |
('path in a name', '../testsuite/acls', None), |
| 71 |
('two names on a line', write('twonames.txt', 'acls sparse\n'), str(FAKE)), |
| 72 |
('comma in a name', write('comma.txt', 'foo,bar\n'), str(FAKE)), |
| 73 |
('a directory, not a test', 'adir', str(FAKE)), |
| 74 |
): |
| 75 |
got = expand(arg, suitedir=suite) |
| 76 |
if got != ERROR: |
| 77 |
test_fail(f'{what}: expected a hard error, got {got!r}') |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
one = write('one.txt', '# comment\n\nacls # trailing comment\nsparse\n') |
| 82 |
two = write('two.txt', 'devices\nsparse\n') |
| 83 |
|
| 84 |
for what, arg, want in ( |
| 85 |
('@FILE expansion', one, 'acls,sparse'), |
| 86 |
('composing two lists', f'{one},{two}', 'acls,devices,sparse'), |
| 87 |
('a bare name with @FILE', f'{one},crtimes', 'acls,crtimes,sparse'), |
| 88 |
('an empty spec is "no skips"', '', ''), |
| 89 |
): |
| 90 |
got = expand(arg) |
| 91 |
if got != want: |
| 92 |
test_fail(f'{what}: expected {want!r}, got {got!r}') |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
got = expand('@testsuite/skiplist/common.txt', str(SRC)) |
| 99 |
if got.startswith('exit:') or not got: |
| 100 |
test_fail(f'relative @FILE did not resolve against srcdir: {got!r}') |
| 101 |
|
| 102 |
cwd = os.getcwd() |
| 103 |
try: |
| 104 |
os.chdir(SRC.parent) |
| 105 |
got = expand('@testsuite/skiplist/common.txt', SRC.name) |
| 106 |
finally: |
| 107 |
os.chdir(cwd) |
| 108 |
if got.startswith('exit:') or not got: |
| 109 |
test_fail(f'@FILE did not resolve against a relative srcdir: {got!r}') |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
BACKPORT_LIST = 'backport.txt' |
| 119 |
|
| 120 |
lists = sorted(p for p in (SRC / 'testsuite' / 'skiplist').glob('*.txt') |
| 121 |
if p.name != BACKPORT_LIST) |
| 122 |
if len(lists) < 5: |
| 123 |
test_fail(f'expected the per-platform skip lists, found {lists}') |
| 124 |
for path in lists: |
| 125 |
got = expand('@' + str(path)) |
| 126 |
if got.startswith('exit:') or not got: |
| 127 |
test_fail(f'{path.name} is empty or does not parse: {got!r} ' |
| 128 |
'(run runtests.py to see the diagnostic)') |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
wf = sorted((SRC / '.github' / 'workflows').glob('*.yml')) |
| 134 |
refs, referenced = 0, set() |
| 135 |
for path in wf: |
| 136 |
for line in path.read_text().splitlines(): |
| 137 |
if 'RSYNC_EXPECT_SKIPPED=' not in line: |
| 138 |
continue |
| 139 |
arg = line.split('RSYNC_EXPECT_SKIPPED=', 1)[1].split()[0] |
| 140 |
got = expand(arg) |
| 141 |
if got.startswith('exit:') or not got: |
| 142 |
test_fail(f'{path.name}: unusable RSYNC_EXPECT_SKIPPED spec {arg!r}') |
| 143 |
refs += 1 |
| 144 |
for tok in arg.split(','): |
| 145 |
if tok.startswith('@'): |
| 146 |
referenced.add(Path(tok[1:]).name) |
| 147 |
if wf: |
| 148 |
if refs == 0: |
| 149 |
test_fail('no workflow references RSYNC_EXPECT_SKIPPED any more') |
| 150 |
orphans = sorted({p.name for p in lists} - referenced) |
| 151 |
if orphans: |
| 152 |
test_fail(f'skip lists no workflow references: {", ".join(orphans)}') |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
common = SRC / 'testsuite' / 'skiplist' / 'common.txt' |
| 157 |
if common.is_file(): |
| 158 |
full = expand('@' + str(common)) |
| 159 |
victim = full.split(',')[0] |
| 160 |
got = expand(f'@{common},-{victim}') |
| 161 |
if got == full or victim in got.split(','): |
| 162 |
test_fail(f'-{victim} did not remove it from the expanded list') |
| 163 |
if len(got.split(',')) != len(full.split(',')) - 1: |
| 164 |
test_fail(f'-{victim} removed more than the one name') |
| 165 |
|
| 166 |
if expand(f'-{victim},@{common}') != got: |
| 167 |
test_fail('a removal before the list it removes from behaved differently') |
| 168 |
|
| 169 |
|
| 170 |
for stale in (f'@{common},-no-such-test-here', f'@{common},-{victim},-{victim}'): |
| 171 |
if expand(stale) != ERROR: |
| 172 |
test_fail(f'a stale removal was accepted: {stale!r}') |
| 173 |
|
| 174 |
print(f'ok: {len(lists)} skip lists, {refs} workflow references') |