In the command-line client, forbid
[svn.git] / subversion / tests / cmdline / getopt_tests.py
blob182483c63fc0cd4c30b27915ac47a2a95491ede5
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"\* fs_(base|fs) :"),
64 # This is a list of lines to search and replace text on.
65 rep_lines_res = [
66 # In 'svn --version', this line varies, for example:
67 # "Subversion Client, version 0.10.2 (dev build)"
68 # "Subversion Client, version 0.10.2 (r1729)"
69 (re.compile(r'version \d+\.\d+\.\d+ \(.*\)'),
70 'version X.Y.Z '),
71 # The copyright end date keeps changing; fix forever.
72 (re.compile(r'Copyright \(C\) 2000-\d+ CollabNet\.'),
73 'Copyright (C) YYYY-YYYY CollabNet'),
74 # In 'svn --version --quiet', we print only the version
75 # number in a single line.
76 (re.compile(r'^\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?$'), 'X.Y.Z\n'),
77 # 'svn --help' has a line with the version number.
78 # It can vary, for example:
79 # "Subversion command-line client, version 1.1.0."
80 # "Subversion command-line client, version 1.1.0-dev."
81 (re.compile(r'Subversion command-line client, '
82 'version \d+\.\d+\.\d+(.|-[a-zA-Z0-9]+\.)$'),
83 'Subversion command-line client, version X.Y.Z.'),
86 def process_lines(lines):
87 "delete lines that should not be compared and search and replace the rest"
88 output = [ ]
89 for line in lines:
90 # Skip these lines from the output list.
91 delete_line = 0
92 for delete_re in del_lines_res:
93 if delete_re.match(line):
94 delete_line = 1
95 break
96 if delete_line:
97 continue
99 # Search and replace text on the rest.
100 for replace_re, replace_str in rep_lines_res:
101 line = replace_re.sub(replace_str, line)
103 output.append(line)
105 return output
107 def run_one_test(sbox, basename, *varargs):
108 "run svn with args and compare against the specified output files"
110 ### no need to use sbox.build() -- we don't need a repos or working copy
111 ### for these tests.
113 exp_stdout, exp_stderr = load_expected_output(basename)
115 # special case the 'svn' test so that no extra arguments are added
116 if basename != 'svn':
117 actual_stdout, actual_stderr = apply(svntest.main.run_svn, (1,) + varargs)
118 else:
119 actual_stdout, actual_stderr = apply(svntest.main.run_command,
120 (svntest.main.svn_binary, 1, 0)
121 + varargs)
123 # Delete and perform search and replaces on the lines from the
124 # actual and expected output that may differ between build
125 # environments.
126 exp_stdout = process_lines(exp_stdout)
127 exp_stderr = process_lines(exp_stderr)
128 actual_stdout = process_lines(actual_stdout)
129 actual_stderr = process_lines(actual_stderr)
131 if exp_stdout != actual_stdout:
132 print "Standard output does not match."
133 print "Expected standard output:"
134 print "====="
135 map(sys.stdout.write, exp_stdout)
136 print "====="
137 print "Actual standard output:"
138 print "====="
139 map(sys.stdout.write, actual_stdout)
140 print "====="
141 raise svntest.Failure
143 if exp_stderr != actual_stderr:
144 print "Standard error does not match."
145 print "Expected standard error:"
146 print "====="
147 map(sys.stdout.write, exp_stderr)
148 print "====="
149 print "Actual standard error:"
150 print "====="
151 map(sys.stdout.write, actual_stderr)
152 print "====="
153 raise svntest.Failure
155 def getopt_no_args(sbox):
156 "run svn with no arguments"
157 run_one_test(sbox, 'svn')
159 def getopt__version(sbox):
160 "run svn --version"
161 run_one_test(sbox, 'svn--version', '--version')
163 def getopt__version__quiet(sbox):
164 "run svn --version --quiet"
165 run_one_test(sbox, 'svn--version--quiet', '--version', '--quiet')
167 def getopt__help(sbox):
168 "run svn --help"
169 run_one_test(sbox, 'svn--help', '--help')
171 def getopt_help(sbox):
172 "run svn help"
173 run_one_test(sbox, 'svn_help', 'help')
175 def getopt_help_log_switch(sbox):
176 "run svn help log switch"
177 run_one_test(sbox, 'svn_help_log_switch', 'help', 'log', 'switch')
179 def getopt_help_bogus_cmd(sbox):
180 "run svn help bogus-cmd"
181 run_one_test(sbox, 'svn_help_bogus-cmd', 'help', 'bogus-cmd')
183 ########################################################################
184 # Run the tests
187 # list all tests here, starting with None:
188 test_list = [ None,
189 getopt_no_args,
190 getopt__version,
191 getopt__version__quiet,
192 getopt__help,
193 getopt_help,
194 getopt_help_bogus_cmd,
195 getopt_help_log_switch
198 if __name__ == '__main__':
199 svntest.main.run_tests(test_list)
200 # NOTREACHED
203 ### End of file.