Skip some mergeinfo-related tests in merge_authz, switch, and update
[svn.git] / subversion / tests / cmdline / cat_tests.py
blob47c63840757274b9351f223abcdab31ad176df21
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(read_only = True)
44 A_path = os.path.join(sbox.wc_dir, 'A')
46 svntest.actions.run_and_verify_svn2('No error where one is expected',
47 None, svntest.verify.AnyOutput,
48 0, 'cat', A_path)
50 def cat_remote_directory(sbox):
51 "cat a remote directory"
52 sbox.build(create_wc = False, read_only = True)
54 A_url = sbox.repo_url + '/A'
55 svntest.actions.run_and_verify_svn2('No error where one is expected',
56 None, svntest.verify.AnyOutput,
57 0, 'cat', A_url)
59 def cat_base(sbox):
60 "cat a file at revision BASE"
61 sbox.build(read_only = True)
63 wc_dir = sbox.wc_dir
65 mu_path = os.path.join(wc_dir, 'A', 'mu')
66 svntest.main.file_append(mu_path, 'Appended text')
68 exit_code, outlines, errlines = svntest.main.run_svn(0, 'cat', mu_path)
70 # Verify the expected output
71 expected_output = svntest.main.greek_state.desc['A/mu'].contents
72 if len(outlines) != 1 or outlines[0] != expected_output:
73 raise svntest.Failure('Cat failed: expected "%s", but received "%s"' % \
74 (expected_output, outlines[0]))
76 def cat_nonexistent_file(sbox):
77 "cat a nonexistent file"
78 sbox.build(read_only = True)
80 wc_dir = sbox.wc_dir
82 bogus_path = os.path.join(wc_dir, 'A', 'bogus')
83 svntest.actions.run_and_verify_svn2('No error where one is expected',
84 None, svntest.verify.AnyOutput,
85 0, 'cat', bogus_path)
87 def cat_skip_uncattable(sbox):
88 "cat should skip uncattable resources"
89 sbox.build(read_only = True)
91 wc_dir = sbox.wc_dir
92 dir_path = os.path.join(wc_dir, 'A', 'D')
93 new_file_path = os.path.join(dir_path, 'new')
94 open(new_file_path, 'w')
95 item_list = os.listdir(dir_path)
97 # First we test running 'svn cat' on individual objects, expecting
98 # warnings for unversioned files and for directories. Then we try
99 # running 'svn cat' on multiple targets at once, and make sure we
100 # get the warnings we expect.
102 # item_list has all the files and directories under 'dir_path'
103 for file in item_list:
104 if file == svntest.main.get_admin_name():
105 continue
106 item_to_cat = os.path.join(dir_path, file)
107 if item_to_cat == new_file_path:
108 expected_err = ["svn: warning: '" + item_to_cat + "'" + \
109 " is not under version control\n"]
110 svntest.actions.run_and_verify_svn2(None, None, expected_err, 0,
111 'cat', item_to_cat)
112 elif os.path.isdir(item_to_cat):
113 expected_err = ["svn: warning: '" + item_to_cat + "'" + \
114 " refers to a directory\n"]
115 svntest.actions.run_and_verify_svn2(None, None, expected_err, 0,
116 'cat', item_to_cat)
117 else:
118 svntest.actions.run_and_verify_svn(None,
119 ["This is the file '"+file+"'.\n"],
120 [], 'cat', item_to_cat)
122 G_path = os.path.join(dir_path, 'G')
123 rho_path = os.path.join(G_path, 'rho')
125 expected_out = ["This is the file 'rho'.\n"]
126 expected_err1 = ["svn: warning: '" + G_path + "'"
127 + " refers to a directory\n"]
128 svntest.actions.run_and_verify_svn2(None, expected_out, expected_err1, 0,
129 'cat', rho_path, G_path)
131 expected_err2 = ["svn: warning: '" + new_file_path + "'"
132 + " is not under version control\n"]
133 svntest.actions.run_and_verify_svn2(None, expected_out, expected_err2, 0,
134 'cat', rho_path, new_file_path)
136 svntest.actions.run_and_verify_svn2(None, expected_out,
137 expected_err1 + expected_err2, 0,
138 'cat', rho_path, G_path, new_file_path)
141 ########################################################################
142 # Run the tests
145 # list all tests here, starting with None:
146 test_list = [ None,
147 cat_local_directory,
148 cat_remote_directory,
149 cat_base,
150 cat_nonexistent_file,
151 cat_skip_uncattable,
154 if __name__ == '__main__':
155 svntest.main.run_tests(test_list)
156 # NOTREACHED
159 ### End of file.