import sys, re, os.path
import svntest
getopt_output_dir = os.path.join(os.path.dirname(sys.argv[0]),
'getopt_tests_data')
def load_expected_output(basename):
"load the expected standard output and standard error"
stdout_filename = os.path.join(getopt_output_dir, basename + '_stdout')
stderr_filename = os.path.join(getopt_output_dir, basename + '_stderr')
exp_stdout = open(stdout_filename, 'r').readlines()
exp_stderr = open(stderr_filename, 'r').readlines()
return exp_stdout, exp_stderr
del_lines_res = [
re.compile(r'\s+compiled\s+'),
re.compile(r"\* ra_(neon|local|svn|serf) :"),
re.compile(r" - handles '(https?|file|svn)' scheme"),
re.compile(r" - with Cyrus SASL authentication"),
re.compile(r"\* fs_(base|fs) :"),
]
rep_lines_res = [
(re.compile(r'version \d+\.\d+\.\d+(-[^ ]*)? \(.*\)'),
'version X.Y.Z '),
(re.compile(r'Copyright \(C\) 20\d\d The Apache '
'Software Foundation\.'),
'Copyright (C) YYYY The Apache Software Foundation'),
(re.compile(r'^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$'), 'X.Y.Z\n'),
(re.compile(r'Subversion command-line client, '
'version \d+\.\d+\.\d+(.|-[a-zA-Z0-9]+\.)$'),
'Subversion command-line client, version X.Y.Z.'),
]
def process_lines(lines):
"delete lines that should not be compared and search and replace the rest"
output = [ ]
for line in lines:
delete_line = 0
for delete_re in del_lines_res:
if delete_re.match(line):
delete_line = 1
break
if delete_line:
continue
for replace_re, replace_str in rep_lines_res:
line = replace_re.sub(replace_str, line)
output.append(line)
return output
def run_one_test(sbox, basename, *varargs):
"run svn with args and compare against the specified output files"
exp_stdout, exp_stderr = load_expected_output(basename)
if basename != 'svn':
exit_code, actual_stdout, actual_stderr = svntest.main.run_svn(1, *varargs)
else:
exit_code, actual_stdout, actual_stderr = svntest.main.run_command(svntest.main.svn_binary,
1, 0, *varargs)
exp_stdout = process_lines(exp_stdout)
exp_stderr = process_lines(exp_stderr)
actual_stdout = process_lines(actual_stdout)
actual_stderr = process_lines(actual_stderr)
if exp_stdout != actual_stdout:
print("Standard output does not match.")
print("Expected standard output:")
print("=====")
for x in exp_stdout:
sys.stdout.write(x)
print("=====")
print("Actual standard output:")
print("=====")
for x in actual_stdout:
sys.stdout.write(x)
print("=====")
raise svntest.Failure
if exp_stderr != actual_stderr:
print("Standard error does not match.")
print("Expected standard error:")
print("=====")
for x in exp_stderr:
sys.stdout.write(x)
print("=====")
print("Actual standard error:")
print("=====")
for x in actual_stderr:
sys.stdout.write(x)
print("=====")
raise svntest.Failure
def getopt_no_args(sbox):
"run svn with no arguments"
run_one_test(sbox, 'svn')
def getopt__version(sbox):
"run svn --version"
run_one_test(sbox, 'svn--version', '--version')
def getopt__version__quiet(sbox):
"run svn --version --quiet"
run_one_test(sbox, 'svn--version--quiet', '--version', '--quiet')
def getopt__help(sbox):
"run svn --help"
run_one_test(sbox, 'svn--help', '--help')
def getopt_help(sbox):
"run svn help"
run_one_test(sbox, 'svn_help', 'help')
def getopt_help_log_switch(sbox):
"run svn help log switch"
run_one_test(sbox, 'svn_help_log_switch', 'help', 'log', 'switch')
def getopt_help_bogus_cmd(sbox):
"run svn help bogus-cmd"
run_one_test(sbox, 'svn_help_bogus-cmd', 'help', 'bogus-cmd')
test_list = [ None,
getopt_no_args,
getopt__version,
getopt__version__quiet,
getopt__help,
getopt_help,
getopt_help_bogus_cmd,
getopt_help_log_switch,
]
if __name__ == '__main__':
svntest.main.run_tests(test_list)