Skip some mergeinfo-related tests in merge_authz, switch, and update
[svn.git] / subversion / tests / cmdline / getopt_tests.py
blobd6b97dac260ee300aab1db3719fbce20d435c7cd
1 #!/usr/bin/env python
3 # getopt_tests.py: testing the svn command line processing
5 # Subversion is a tool for revision control.
6 # See http://subversion.tigris.org for more information.
8 # ====================================================================
9 # Copyright (c) 2000-2004 CollabNet. All rights reserved.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://subversion.tigris.org/license-1.html.
14 # If newer versions of this license are posted there, you may use a
15 # newer version instead, at your option.
17 ######################################################################
19 # General modules
20 import sys, re, os.path
22 # Our testing module
23 import svntest
26 ######################################################################
27 # Tests
29 #----------------------------------------------------------------------
31 # This directory contains all the expected output from svn.
32 getopt_output_dir = os.path.join(os.path.dirname(sys.argv[0]),
33 'getopt_tests_data')
35 # Naming convention for golden files: take the svn command line as a
36 # single string and apply the following sed transformations:
37 # echo svn option1 option2 ... | sed -e 's/ /_/g' -e 's/_--/--/g'
38 # Then append either _stdout or _stderr for the file descriptor to
39 # compare against.
41 def load_expected_output(basename):
42 "load the expected standard output and standard error"
44 stdout_filename = os.path.join(getopt_output_dir, basename + '_stdout')
45 stderr_filename = os.path.join(getopt_output_dir, basename + '_stderr')
47 exp_stdout = open(stdout_filename, 'r').readlines()
48 exp_stderr = open(stderr_filename, 'r').readlines()
50 return exp_stdout, exp_stderr
52 # This is a list of lines to delete.
53 del_lines_res = [
54 # In 'svn --version', the date line is variable, for example:
55 # "compiled Apr 5 2002, 10:08:45"
56 re.compile(r'\s+compiled\s+'),
58 # Also for 'svn --version':
59 re.compile(r"\* ra_(neon|local|svn|serf) :"),
60 re.compile(r" - handles '(https?|file|svn)' scheme"),
61 re.compile(r" - with Cyrus SASL authentication"),
62 re.compile(r"\* fs_(base|fs) :"),
65 # This is a list of lines to search and replace text on.
66 rep_lines_res = [
67 # In 'svn --version', this line varies, for example:
68 # "Subversion Client, version 0.10.2 (dev build)"
69 # "Subversion Client, version 0.10.2 (r1729)"
70 (re.compile(r'version \d+\.\d+\.\d+ \(.*\)'),
71 'version X.Y.Z '),
72 # The copyright end date keeps changing; fix forever.
73 (re.compile(r'Copyright \(C\) 2000-\d+ CollabNet\.'),
74 'Copyright (C) YYYY-YYYY CollabNet'),
75 # In 'svn --version --quiet', we print only the version
76 # number in a single line.
77 (re.compile(r'^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$'), 'X.Y.Z\n'),
78 # 'svn --help' has a line with the version number.
79 # It can vary, for example:
80 # "Subversion command-line client, version 1.1.0."
81 # "Subversion command-line client, version 1.1.0-dev."
82 (re.compile(r'Subversion command-line client, '
83 'version \d+\.\d+\.\d+(.|-[a-zA-Z0-9]+\.)$'),
84 'Subversion command-line client, version X.Y.Z.'),
87 def process_lines(lines):
88 "delete lines that should not be compared and search and replace the rest"
89 output = [ ]
90 for line in lines:
91 # Skip these lines from the output list.
92 delete_line = 0
93 for delete_re in del_lines_res:
94 if delete_re.match(line):
95 delete_line = 1
96 break
97 if delete_line:
98 continue
100 # Search and replace text on the rest.
101 for replace_re, replace_str in rep_lines_res:
102 line = replace_re.sub(replace_str, line)
104 output.append(line)
106 return output
108 def run_one_test(sbox, basename, *varargs):
109 "run svn with args and compare against the specified output files"
111 ### no need to use sbox.build() -- we don't need a repos or working copy
112 ### for these tests.
114 exp_stdout, exp_stderr = load_expected_output(basename)
116 # special case the 'svn' test so that no extra arguments are added
117 if basename != 'svn':
118 exit_code, actual_stdout, actual_stderr = apply(svntest.main.run_svn,
119 (1,) + varargs)
120 else:
121 exit_code, actual_stdout, actual_stderr = apply(svntest.main.run_command,
122 (svntest.main.svn_binary,
123 1, 0) + varargs)
125 # Delete and perform search and replaces on the lines from the
126 # actual and expected output that may differ between build
127 # environments.
128 exp_stdout = process_lines(exp_stdout)
129 exp_stderr = process_lines(exp_stderr)
130 actual_stdout = process_lines(actual_stdout)
131 actual_stderr = process_lines(actual_stderr)
133 if exp_stdout != actual_stdout:
134 print "Standard output does not match."
135 print "Expected standard output:"
136 print "====="
137 map(sys.stdout.write, exp_stdout)
138 print "====="
139 print "Actual standard output:"
140 print "====="
141 map(sys.stdout.write, actual_stdout)
142 print "====="
143 raise svntest.Failure
145 if exp_stderr != actual_stderr:
146 print "Standard error does not match."
147 print "Expected standard error:"
148 print "====="
149 map(sys.stdout.write, exp_stderr)
150 print "====="
151 print "Actual standard error:"
152 print "====="
153 map(sys.stdout.write, actual_stderr)
154 print "====="
155 raise svntest.Failure
157 def getopt_no_args(sbox):
158 "run svn with no arguments"
159 run_one_test(sbox, 'svn')
161 def getopt__version(sbox):
162 "run svn --version"
163 run_one_test(sbox, 'svn--version', '--version')
165 def getopt__version__quiet(sbox):
166 "run svn --version --quiet"
167 run_one_test(sbox, 'svn--version--quiet', '--version', '--quiet')
169 def getopt__help(sbox):
170 "run svn --help"
171 run_one_test(sbox, 'svn--help', '--help')
173 def getopt_help(sbox):
174 "run svn help"
175 run_one_test(sbox, 'svn_help', 'help')
177 def getopt_help_log_switch(sbox):
178 "run svn help log switch"
179 run_one_test(sbox, 'svn_help_log_switch', 'help', 'log', 'switch')
181 def getopt_help_bogus_cmd(sbox):
182 "run svn help bogus-cmd"
183 run_one_test(sbox, 'svn_help_bogus-cmd', 'help', 'bogus-cmd')
185 ########################################################################
186 # Run the tests
189 # list all tests here, starting with None:
190 test_list = [ None,
191 getopt_no_args,
192 getopt__version,
193 getopt__version__quiet,
194 getopt__help,
195 getopt_help,
196 getopt_help_bogus_cmd,
197 getopt_help_log_switch
200 if __name__ == '__main__':
201 svntest.main.run_tests(test_list)
202 # NOTREACHED
205 ### End of file.