aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorGilles Leblanc <gilles.leblanc@gmail.com>2015-03-02 19:58:13 -0500
committerSimon Sapin <simon.sapin@exyr.org>2015-03-07 17:51:17 +0100
commit54dfb659ec3f599193769fd542e70671435e491d (patch)
tree68ae28355b87d3142b8e97abfdadc236e61daa82 /python
parent1a73766db2442476190f3dcec321f452aa122055 (diff)
downloadservo-54dfb659ec3f599193769fd542e70671435e491d.tar.gz
servo-54dfb659ec3f599193769fd542e70671435e491d.zip
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
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