mirror of
https://github.com/servo/servo.git
synced 2025-06-08 16:43:28 +00:00
Organize reftest list alphabetically and make the tidy script check it
Reftest list check is checked using Python's default string comparison. Also added a notice in the tidy script when there are no errors. Fixes #5092
This commit is contained in:
parent
1a73766db2
commit
54dfb659ec
2 changed files with 267 additions and 237 deletions
|
@ -11,10 +11,13 @@
|
|||
|
||||
import os
|
||||
import fnmatch
|
||||
import itertools
|
||||
from licenseck import licenses
|
||||
|
||||
directories_to_check = ["ports/gonk", "components"]
|
||||
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".py"]
|
||||
reftest_directories = ["tests/ref"]
|
||||
reftest_filetype = ".list"
|
||||
|
||||
ignored_files = [
|
||||
# Upstream
|
||||
|
@ -51,6 +54,10 @@ def should_check(file_name):
|
|||
return True
|
||||
|
||||
|
||||
def should_check_reftest(file_name):
|
||||
return file_name.endswith(reftest_filetype)
|
||||
|
||||
|
||||
def check_license(contents):
|
||||
valid_license = any(contents.startswith(license) for license in licenses)
|
||||
acknowledged_bad_license = "xfail-license" in contents[:100]
|
||||
|
@ -93,17 +100,45 @@ def collect_errors_for_files(files_to_check, checking_functions):
|
|||
yield (file_name, error[0], error[1])
|
||||
|
||||
|
||||
def check_reftest_order(files_to_check):
|
||||
for file_name in files_to_check:
|
||||
with open(file_name, "r") as fp:
|
||||
split_lines = fp.read().splitlines()
|
||||
lines = filter(lambda l: len(l) > 0 and l[0] != '#', split_lines)
|
||||
for idx, line in enumerate(lines[:-1]):
|
||||
next_line = lines[idx+1]
|
||||
current = get_reftest_names(line)
|
||||
next = get_reftest_names(next_line)
|
||||
if current is not None and next is not None and current > next:
|
||||
yield (file_name, split_lines.index(next_line) + 1, "line not in alphabetical order")
|
||||
|
||||
|
||||
def get_reftest_names(line):
|
||||
tokens = line.split()
|
||||
if (len(tokens) == 3):
|
||||
return tokens[1] + tokens[2]
|
||||
if (len(tokens) == 4):
|
||||
return tokens[2] + tokens[3]
|
||||
return None
|
||||
|
||||
|
||||
def scan():
|
||||
all_files = collect_file_names(directories_to_check)
|
||||
files_to_check = filter(should_check, all_files)
|
||||
|
||||
checking_functions = [check_license, check_length, check_whitespace]
|
||||
errors = collect_errors_for_files(files_to_check, checking_functions)
|
||||
errors = list(errors)
|
||||
|
||||
reftest_files = collect_file_names(reftest_directories)
|
||||
reftest_to_check = filter(should_check_reftest, reftest_files)
|
||||
r_errors = check_reftest_order(reftest_to_check)
|
||||
|
||||
errors = list(itertools.chain(errors, r_errors))
|
||||
|
||||
if errors:
|
||||
for error in errors:
|
||||
print("{}:{}: {}".format(*error))
|
||||
return 1
|
||||
else:
|
||||
print("tidy reported no errors.")
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue