Skip to content
Snippets Groups Projects
Commit 223a4cb5 authored by Torsten Schmits's avatar Torsten Schmits Committed by Marge Bot
Browse files

test driver: fix file collection for regex linters

When a testsuite linter is executed with the `tracked` strategy, the
driver runs `git ls-tree` to collect eligible files.

This appears to have ceased producing any paths – `ls-tree` restricts
its results to the current working directory, which is
`testsuite/tests/linters` in this case.

As a quick fix, this patch changes the working directory to match
expectations.
parent 502e6711
No related branches found
No related tags found
No related merge requests found
...@@ -12,16 +12,16 @@ uniques: ...@@ -12,16 +12,16 @@ uniques:
python3 checkUniques/check-uniques.py $(TOP)/.. python3 checkUniques/check-uniques.py $(TOP)/..
makefiles: makefiles:
(cd $(TOP)/tests/linters/ && python3 regex-linters/check-makefiles.py tracked) (cd $(TOP)/.. && python3 testsuite/tests/linters/regex-linters/check-makefiles.py tracked)
version-number: version-number:
regex-linters/check-version-number.sh ${TOP}/.. regex-linters/check-version-number.sh ${TOP}/..
cpp: cpp:
(cd $(TOP)/tests/linters/ && python3 regex-linters/check-cpp.py tracked) (cd $(TOP)/.. && python3 testsuite/tests/linters/regex-linters/check-cpp.py tracked)
rts-includes: rts-includes:
(cd $(TOP)/tests/linters/ && python3 regex-linters/check-rts-includes.py tracked) (cd $(TOP)/.. && python3 testsuite/tests/linters/regex-linters/check-rts-includes.py tracked)
changelogs: changelogs:
regex-linters/check-changelogs.sh $(TOP)/.. regex-linters/check-changelogs.sh $(TOP)/..
......
...@@ -29,12 +29,6 @@ for l in linters: ...@@ -29,12 +29,6 @@ for l in linters:
l.add_path_filter(lambda path: not path.name == 'config.guess') l.add_path_filter(lambda path: not path.name == 'config.guess')
# Don't lint files from external xxhash projects # Don't lint files from external xxhash projects
l.add_path_filter(lambda path: path != Path('rts', 'xxhash.h')), l.add_path_filter(lambda path: path != Path('rts', 'xxhash.h')),
# Don't lint font files
l.add_path_filter(lambda path: not path.parent == Path('docs','users_guide',
'rtd-theme', 'static', 'fonts'))
# Don't lint image files
l.add_path_filter(lambda path: not path.parent == Path('docs','users_guide',
'images'))
# Don't lint core spec # Don't lint core spec
l.add_path_filter(lambda path: not path.name == 'core-spec.pdf') l.add_path_filter(lambda path: not path.name == 'core-spec.pdf')
# Don't lint the linter itself # Don't lint the linter itself
......
...@@ -40,6 +40,8 @@ def get_changed_files(base_commit: str, head_commit: str, ...@@ -40,6 +40,8 @@ def get_changed_files(base_commit: str, head_commit: str,
def get_tracked_files(subdir: str = '.'): def get_tracked_files(subdir: str = '.'):
""" Get the files tracked by git in the given subdirectory. """ """ Get the files tracked by git in the given subdirectory. """
if not Path(subdir).exists():
raise Exception("Regex linter executed with nonexistent target directory '{}'".format(subdir))
cmd = ['git', 'ls-tree', '--name-only', '-r', 'HEAD', subdir] cmd = ['git', 'ls-tree', '--name-only', '-r', 'HEAD', subdir]
files = subprocess.check_output(cmd) files = subprocess.check_output(cmd)
return files.decode('UTF-8').split('\n') return files.decode('UTF-8').split('\n')
...@@ -77,9 +79,16 @@ class LineLinter(Linter): ...@@ -77,9 +79,16 @@ class LineLinter(Linter):
""" """
def lint(self, path: Path): def lint(self, path: Path):
if path.is_file(): if path.is_file():
with path.open('r') as f: try:
for line_no, line in enumerate(f): with path.open('r') as f:
self.lint_line(path, line_no+1, line) for line_no, line in enumerate(f):
self.lint_line(path, line_no+1, line)
# We don't want to explicitly exclude every single binary file in the test suite
except UnicodeDecodeError as e:
pass
except Exception as e:
print('Exception occurred while linting file: {}'.format(path))
raise e
def lint_line(self, path: Path, line_no: int, line: str): def lint_line(self, path: Path, line_no: int, line: str):
raise NotImplementedError raise NotImplementedError
...@@ -124,7 +133,7 @@ def run_linters(linters: Sequence[Linter], ...@@ -124,7 +133,7 @@ def run_linters(linters: Sequence[Linter],
linted_files = args.get_linted_files(args) linted_files = args.get_linted_files(args)
for path in linted_files: for path in linted_files:
if path.startswith('linters'): if path.startswith('testsuite/tests/linters'):
continue continue
for linter in linters: for linter in linters:
linter.do_lint(Path(path)) linter.do_lint(Path(path))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment