forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_spelling_pedantic_test.py
executable file
·105 lines (76 loc) · 3.46 KB
/
check_spelling_pedantic_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#! /usr/bin/env python3
# Tests check_spelling_pedantic.py. Normally run from check_spelling_pedantic.sh.
from __future__ import print_function
from run_command import run_command
import argparse
import logging
import os
import sys
curr_dir = os.path.dirname(os.path.realpath(__file__))
tools = os.path.dirname(curr_dir)
src = os.path.join(tools, 'testdata', 'spelling')
check_spelling = sys.executable + " " + os.path.join(curr_dir, 'check_spelling_pedantic.py')
# Runs the 'check_spelling_pedanic' operation, on the specified file,
# printing the comamnd run and the status code as well as the stdout,
# and returning all of that to the caller.
def run_check_format(operation, filename):
command = check_spelling + " --test-ignore-exts " + operation + " " + filename
status, stdout, stderr = run_command(command)
return (command, status, stdout + stderr)
def get_input_file(filename):
return os.path.join(src, filename)
def emit_stdout_as_error(stdout):
logging.error("\n".join(stdout))
def expect_error(filename, status, stdout, expected_substrings):
if status == 0:
logging.error(
"%s: Expected %d errors, but succeeded" % (filename, len(expected_substrings)))
return 1
errors = 0
for expected_substring in expected_substrings:
found = False
for line in stdout:
if expected_substring in line:
found = True
break
if not found:
logging.error("%s: Could not find '%s' in:\n" % (filename, expected_substring))
emit_stdout_as_error(stdout)
errors += 1
return errors
def check_file_expecting_errors(filename, expected_substrings):
command, status, stdout = run_check_format("check", get_input_file(filename))
return expect_error(filename, status, stdout, expected_substrings)
def check_file_path_expecting_ok(filename):
command, status, stdout = run_check_format("check", filename)
if status != 0:
logging.error("Expected %s to have no errors; status=%d, output:\n" % (filename, status))
emit_stdout_as_error(stdout)
return status
def check_file_expecting_ok(filename):
return check_file_path_expecting_ok(get_input_file(filename))
def run_checks():
errors = 0
errors += check_file_expecting_ok("valid")
errors += check_file_expecting_ok("skip_file")
errors += check_file_expecting_ok("exclusions")
errors += check_file_expecting_ok("third_party/something/file.cc")
errors += check_file_expecting_ok("./third_party/something/file.cc")
errors += check_file_expecting_errors(
"typos", ["spacific", "reelistic", "Awwful", "combeenations", "woork"])
errors += check_file_expecting_errors(
"skip_blocks", ["speelinga", "speelingb", "speelingc", "speelingd", "speelinge"])
errors += check_file_expecting_errors("on_off", ["speelinga", "speelingb"])
errors += check_file_expecting_errors("rst_code_block", ["speelinga", "speelingb"])
errors += check_file_expecting_errors("word_splitting", ["Speeled", "Korrectly"])
return errors
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='tester for check_format.py.')
parser.add_argument('--log', choices=['INFO', 'WARN', 'ERROR'], default='INFO')
args = parser.parse_args()
logging.basicConfig(format='%(message)s', level=args.log)
errors = run_checks()
if errors != 0:
logging.error("%d FAILURES" % errors)
exit(1)
logging.warning("PASS")