In the command-line client, forbid
[svn.git] / subversion / tests / cmdline / cat_tests.py
blobb36f390957b4875b40dde51c3da7c63d028189e8
1 #!/usr/bin/env python
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 ######################################################################
19 # General modules
20 import os
22 # Our testing module
23 import svntest
26 # (abbreviation)
27 Skip = svntest.testcase.Skip
28 XFail = svntest.testcase.XFail
29 Item = svntest.wc.StateItem
32 ######################################################################
33 # Tests
35 # Each test must return on success or raise on failure.
38 #----------------------------------------------------------------------
40 def cat_local_directory(sbox):
41 "cat a local directory"
42 sbox.build()
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,
48 'cat', A_path)
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,
58 'cat', A_url)
60 def cat_base(sbox):
61 "cat a file at revision BASE"
62 sbox.build()
64 wc_dir = sbox.wc_dir
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"
79 sbox.build()
81 wc_dir = sbox.wc_dir
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,
87 'cat', bogus_path)
89 def cat_skip_uncattable(sbox):
90 "cat should skip uncattable resources"
91 sbox.build()
93 wc_dir = sbox.wc_dir
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():
107 continue
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,
113 'cat', item_to_cat)
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)
119 else:
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 ########################################################################
144 # Run the tests
147 # list all tests here, starting with None:
148 test_list = [ None,
149 cat_local_directory,
150 cat_remote_directory,
151 cat_base,
152 cat_nonexistent_file,
153 cat_skip_uncattable,
156 if __name__ == '__main__':
157 svntest.main.run_tests(test_list)
158 # NOTREACHED
161 ### End of file.