aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-03-07 10:48:51 -0700
committerbors-servo <metajack+bors@gmail.com>2015-03-07 10:48:51 -0700
commit3b14df16c6d60fd5e379203d8035e933777e0221 (patch)
tree70f0e16784cc46fdf700a0de0e38de0562742e6b /python
parent4f3feed2bea957de0910a136d33dff4fb3c07a22 (diff)
parentf770dbabd7ad1cc53fe7c37d11f0d37e77a9a433 (diff)
downloadservo-3b14df16c6d60fd5e379203d8035e933777e0221.tar.gz
servo-3b14df16c6d60fd5e379203d8035e933777e0221.zip
auto merge of #5172 : servo/servo/alpha, r=SimonSapin
Rebase of #5123. (Fixes #5123.) Thanks @gille-leblanc! 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
Diffstat (limited to 'python')
-rw-r--r--python/tidy.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/python/tidy.py b/python/tidy.py
index fda394f1eed..c6bb4931e2d 100644
--- a/python/tidy.py
+++ b/python/tidy.py
@@ -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