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 ######################################################################
20 import sys
, re
, os
.path
26 ######################################################################
29 #----------------------------------------------------------------------
31 # This directory contains all the expected output from svn.
32 getopt_output_dir
= os
.path
.join(os
.path
.dirname(sys
.argv
[0]),
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
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.
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.
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+ \(.*\)'),
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"
90 # Skip these lines from the output list.
92 for delete_re
in del_lines_res
:
93 if delete_re
.match(line
):
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
)
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
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
)
119 actual_stdout
, actual_stderr
= apply(svntest
.main
.run_command
,
120 (svntest
.main
.svn_binary
, 1, 0)
123 # Delete and perform search and replaces on the lines from the
124 # actual and expected output that may differ between build
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:"
135 map(sys
.stdout
.write
, exp_stdout
)
137 print "Actual standard output:"
139 map(sys
.stdout
.write
, actual_stdout
)
141 raise svntest
.Failure
143 if exp_stderr
!= actual_stderr
:
144 print "Standard error does not match."
145 print "Expected standard error:"
147 map(sys
.stdout
.write
, exp_stderr
)
149 print "Actual standard error:"
151 map(sys
.stdout
.write
, actual_stderr
)
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
):
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
):
169 run_one_test(sbox
, 'svn--help', '--help')
171 def getopt_help(sbox
):
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 ########################################################################
187 # list all tests here, starting with None:
191 getopt__version__quiet
,
194 getopt_help_bogus_cmd
,
195 getopt_help_log_switch
198 if __name__
== '__main__':
199 svntest
.main
.run_tests(test_list
)