3 # cat_tests.py: testing cat cases.
5 # Subversion is a tool for revision control.
6 # See http://subversion.tigris.org for more information.
8 # ====================================================================
9 # Copyright (c) 2000-2007 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 ######################################################################
27 Skip
= svntest
.testcase
.Skip
28 XFail
= svntest
.testcase
.XFail
29 Item
= svntest
.wc
.StateItem
32 ######################################################################
35 # Each test must return on success or raise on failure.
38 #----------------------------------------------------------------------
40 def cat_local_directory(sbox
):
41 "cat a local directory"
44 A_path
= os
.path
.join(sbox
.wc_dir
, 'A')
46 svntest
.actions
.run_and_verify_svn('No error where one is expected',
47 None, svntest
.verify
.AnyOutput
,
50 def cat_remote_directory(sbox
):
51 "cat a remote directory"
52 sbox
.build(create_wc
= False)
54 A_url
= sbox
.repo_url
+ '/A'
56 svntest
.actions
.run_and_verify_svn('No error where one is expected',
57 None, svntest
.verify
.AnyOutput
,
61 "cat a file at revision BASE"
66 mu_path
= os
.path
.join(wc_dir
, 'A', 'mu')
67 svntest
.main
.file_append(mu_path
, 'Appended text')
69 outlines
, errlines
= svntest
.main
.run_svn(0, 'cat', mu_path
)
71 # Verify the expected output
72 expected_output
= svntest
.main
.greek_state
.desc
['A/mu'].contents
73 if len(outlines
) != 1 or outlines
[0] != expected_output
:
74 raise svntest
.Failure('Cat failed: expected "%s", but received "%s"' % \
75 (expected_output
, outlines
[0]))
77 def cat_nonexistent_file(sbox
):
78 "cat a nonexistent file"
83 bogus_path
= os
.path
.join(wc_dir
, 'A', 'bogus')
85 svntest
.actions
.run_and_verify_svn('No error where one is expected',
86 None, svntest
.verify
.AnyOutput
,
89 def cat_skip_uncattable(sbox
):
90 "cat should skip uncattable resources"
94 dir_path
= os
.path
.join(wc_dir
, 'A', 'D')
95 new_file_path
= os
.path
.join(dir_path
, 'new')
96 open(new_file_path
, 'w')
97 item_list
= os
.listdir(dir_path
)
99 # First we test running 'svn cat' on individual objects, expecting
100 # warnings for unversioned files and for directories. Then we try
101 # running 'svn cat' on multiple targets at once, and make sure we
102 # get the warnings we expect.
104 # item_list has all the files and directories under 'dir_path'
105 for file in item_list
:
106 if file == svntest
.main
.get_admin_name():
108 item_to_cat
= os
.path
.join(dir_path
, file)
109 if item_to_cat
== new_file_path
:
110 expected_err
= ["svn: warning: '" + item_to_cat
+ "'" + \
111 " is not under version control\n"]
112 svntest
.actions
.run_and_verify_svn(None, None, expected_err
,
114 elif os
.path
.isdir(item_to_cat
):
115 expected_err
= ["svn: warning: '" + item_to_cat
+ "'" + \
116 " refers to a directory\n"]
117 svntest
.actions
.run_and_verify_svn(None, None,
118 expected_err
, 'cat', item_to_cat
)
120 svntest
.actions
.run_and_verify_svn(None,
121 ["This is the file '"+file+"'.\n"],
122 [], 'cat', item_to_cat
)
124 G_path
= os
.path
.join(dir_path
, 'G')
125 rho_path
= os
.path
.join(G_path
, 'rho')
127 expected_out
= ["This is the file 'rho'.\n"]
128 expected_err1
= ["svn: warning: '" + G_path
+ "'"
129 + " refers to a directory\n"]
130 svntest
.actions
.run_and_verify_svn(None, expected_out
, expected_err1
,
131 'cat', rho_path
, G_path
)
133 expected_err2
= ["svn: warning: '" + new_file_path
+ "'"
134 + " is not under version control\n"]
135 svntest
.actions
.run_and_verify_svn(None, expected_out
, expected_err2
,
136 'cat', rho_path
, new_file_path
)
138 svntest
.actions
.run_and_verify_svn(None, expected_out
,
139 expected_err1
+ expected_err2
,
140 'cat', rho_path
, G_path
, new_file_path
)
143 ########################################################################
147 # list all tests here, starting with None:
150 cat_remote_directory
,
152 cat_nonexistent_file
,
156 if __name__
== '__main__':
157 svntest
.main
.run_tests(test_list
)