Skip to content

Commit

Permalink
Adding parameter to tidy for skipping print text when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
askeing committed Apr 25, 2016
1 parent 97a45dc commit 33d8e21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions python/tidy/servo_tidy/tidy.py
Expand Up @@ -577,11 +577,12 @@ def check_spec(file_name, lines):
brace_count -= 1


def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions):
def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions, print_text=True):
(has_element, files_to_check) = is_iter_empty(files_to_check)
if not has_element:
raise StopIteration
print '\rChecking files for tidiness...'
if print_text:
print '\rChecking files for tidiness...'
for filename in files_to_check:
with open(filename, "r") as f:
contents = f.read()
Expand Down
20 changes: 10 additions & 10 deletions python/tidy/servo_tidy_tests/test_tidy.py
Expand Up @@ -24,7 +24,7 @@ def assertNoMoreErrors(self, errors):
errors.next()

def test_spaces_correctnes(self):
errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line])
errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('trailing whitespace', errors.next()[2])
self.assertEqual('no newline at EOF', errors.next()[2])
self.assertEqual('tab on line', errors.next()[2])
Expand All @@ -33,23 +33,23 @@ def test_spaces_correctnes(self):
self.assertNoMoreErrors(errors)

def test_long_line(self):
errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line])
errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('Line is longer than 120 characters', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_whatwg_link(self):
errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line])
errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line], print_text=False)
self.assertTrue('link to WHATWG may break in the future, use this format instead:' in errors.next()[2])
self.assertTrue('links to WHATWG single-page url, change to multi page:' in errors.next()[2])
self.assertNoMoreErrors(errors)

def test_licence(self):
errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license])
errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license], print_text=False)
self.assertEqual('incorrect license', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_rust(self):
errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust])
errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('use statement spans multiple lines', errors.next()[2])
self.assertEqual('missing space before }', errors.next()[2])
self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
Expand All @@ -75,22 +75,22 @@ def test_rust(self):

def test_spec_link(self):
tidy.spec_base_path = base_path
errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec])
errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec], print_text=False)
self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_webidl(self):
errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [])
errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [], print_text=False)
self.assertEqual('No specification link found.', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_toml(self):
errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [])
errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [], print_text=False)
self.assertEqual('found asterisk instead of minimum version number', errors.next()[2])
self.assertNoMoreErrors(errors)

def test_modeline(self):
errors = tidy.collect_errors_for_files(iterFile('modeline.txt'), [], [tidy.check_modeline])
errors = tidy.collect_errors_for_files(iterFile('modeline.txt'), [], [tidy.check_modeline], print_text=False)
self.assertEqual('vi modeline present', errors.next()[2])
self.assertEqual('vi modeline present', errors.next()[2])
self.assertEqual('vi modeline present', errors.next()[2])
Expand All @@ -99,7 +99,7 @@ def test_modeline(self):
self.assertNoMoreErrors(errors)

def test_lock(self):
errors = tidy.collect_errors_for_files(iterFile('duplicated_package.lock'), [tidy.check_lock], [])
errors = tidy.collect_errors_for_files(iterFile('duplicated_package.lock'), [tidy.check_lock], [], print_text=False)
msg = """duplicate versions for package "test"
\t\033[93mfound dependency on version 0.4.9\033[0m
\t\033[91mbut highest version is 0.5.1\033[0m
Expand Down

0 comments on commit 33d8e21

Please sign in to comment.