1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # svnversion_tests.py: testing the 'svnversion' tool. |
---|
4 | # |
---|
5 | # Subversion is a tool for revision control. |
---|
6 | # See http://subversion.tigris.org for more information. |
---|
7 | # |
---|
8 | # ==================================================================== |
---|
9 | # Copyright (c) 2003 CollabNet. All rights reserved. |
---|
10 | # |
---|
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. |
---|
16 | # |
---|
17 | ###################################################################### |
---|
18 | |
---|
19 | # General modules |
---|
20 | import os.path |
---|
21 | import warnings |
---|
22 | |
---|
23 | # Our testing module |
---|
24 | import svntest |
---|
25 | from svntest import wc |
---|
26 | |
---|
27 | # (abbreviation) |
---|
28 | Skip = svntest.testcase.Skip |
---|
29 | XFail = svntest.testcase.XFail |
---|
30 | Item = svntest.wc.StateItem |
---|
31 | |
---|
32 | #---------------------------------------------------------------------- |
---|
33 | |
---|
34 | def svnversion_test(sbox): |
---|
35 | "test 'svnversion' on wc and other dirs" |
---|
36 | sbox.build() |
---|
37 | wc_dir = sbox.wc_dir |
---|
38 | repo_url = sbox.repo_url |
---|
39 | |
---|
40 | # Unmodified |
---|
41 | svntest.actions.run_and_verify_svnversion("Unmodified working copy", |
---|
42 | wc_dir, repo_url, |
---|
43 | [ "1\n" ], []) |
---|
44 | |
---|
45 | # Unmodified, whole wc switched |
---|
46 | svntest.actions.run_and_verify_svnversion("Unmodified switched working copy", |
---|
47 | wc_dir, "some/other/url", |
---|
48 | [ "1S\n" ], []) |
---|
49 | |
---|
50 | mu_path = os.path.join(wc_dir, 'A', 'mu') |
---|
51 | svntest.main.file_append(mu_path, 'appended mu text') |
---|
52 | |
---|
53 | # Text modified |
---|
54 | svntest.actions.run_and_verify_svnversion("Modified text", wc_dir, repo_url, |
---|
55 | [ "1M\n" ], []) |
---|
56 | |
---|
57 | expected_output = wc.State(wc_dir, {'A/mu' : Item(verb='Sending')}) |
---|
58 | expected_status = svntest.actions.get_virginal_state(wc_dir, 1) |
---|
59 | expected_status.tweak('A/mu', wc_rev=2) |
---|
60 | if svntest.actions.run_and_verify_commit(wc_dir, |
---|
61 | expected_output, expected_status, |
---|
62 | None, wc_dir): |
---|
63 | raise svntest.Failure |
---|
64 | |
---|
65 | # Unmodified, mixed |
---|
66 | svntest.actions.run_and_verify_svnversion("Unmodified mixed working copy", |
---|
67 | wc_dir, repo_url, |
---|
68 | [ "1:2\n" ], []) |
---|
69 | |
---|
70 | svntest.actions.run_and_verify_svn(None, None, [], |
---|
71 | 'propset', 'blue', 'azul', |
---|
72 | os.path.join(wc_dir, 'A', 'mu')) |
---|
73 | |
---|
74 | # Prop modified, mixed |
---|
75 | svntest.actions.run_and_verify_svnversion("Property modified mixed wc", |
---|
76 | wc_dir, repo_url, |
---|
77 | [ "1:2M\n" ], []) |
---|
78 | |
---|
79 | iota_path = os.path.join(wc_dir, 'iota') |
---|
80 | gamma_url = sbox.repo_url + '/A/D/gamma' |
---|
81 | expected_output = wc.State(wc_dir, {'iota' : Item(status='U ')}) |
---|
82 | expected_status.tweak('A/mu', status=' M') |
---|
83 | expected_status.tweak('iota', switched='S', wc_rev=2) |
---|
84 | expected_disk = svntest.main.greek_state.copy() |
---|
85 | expected_disk.tweak('A/mu', |
---|
86 | contents=expected_disk.desc['A/mu'].contents |
---|
87 | + 'appended mu text') |
---|
88 | expected_disk.tweak('iota', |
---|
89 | contents=expected_disk.desc['A/D/gamma'].contents) |
---|
90 | if svntest.actions.run_and_verify_switch(wc_dir, iota_path, gamma_url, |
---|
91 | expected_output, |
---|
92 | expected_disk, |
---|
93 | expected_status): |
---|
94 | raise svntest.Failure |
---|
95 | |
---|
96 | # Prop modified, mixed, part wc switched |
---|
97 | svntest.actions.run_and_verify_svnversion("Prop-mod mixed partly switched", |
---|
98 | wc_dir, repo_url, |
---|
99 | [ "1:2MS\n" ], []) |
---|
100 | |
---|
101 | # Plain (exported) directory that is a direct subdir of a versioned dir |
---|
102 | Q_path = os.path.join(wc_dir, 'Q') |
---|
103 | os.mkdir(Q_path) |
---|
104 | svntest.actions.run_and_verify_svnversion("Exported subdirectory", |
---|
105 | Q_path, repo_url, |
---|
106 | [ "exported\n" ], []) |
---|
107 | |
---|
108 | # Plain (exported) directory that is not a direct subdir of a versioned dir |
---|
109 | R_path = os.path.join(Q_path, 'Q') |
---|
110 | os.mkdir(R_path) |
---|
111 | svntest.actions.run_and_verify_svnversion("Exported directory", |
---|
112 | R_path, repo_url, |
---|
113 | [ "exported\n" ], []) |
---|
114 | |
---|
115 | # No directory generates an error |
---|
116 | svntest.actions.run_and_verify_svnversion("None existent directory", |
---|
117 | os.path.join(wc_dir, 'Q', 'X'), |
---|
118 | repo_url, |
---|
119 | None, svntest.verify.AnyOutput) |
---|
120 | |
---|
121 | # Perform a sparse checkout of under the existing WC, and confirm that |
---|
122 | # svnversion detects it as a "partial" WC. |
---|
123 | A_path = os.path.join(wc_dir, "A") |
---|
124 | A_A_path = os.path.join(A_path, "SPARSE_A") |
---|
125 | expected_output = wc.State(A_path, { |
---|
126 | "SPARSE_A" : Item(), |
---|
127 | "SPARSE_A/mu" : Item(status='A '), |
---|
128 | }) |
---|
129 | expected_disk = wc.State("", { |
---|
130 | "mu" : Item(expected_disk.desc['A/mu'].contents), |
---|
131 | }) |
---|
132 | svntest.actions.run_and_verify_checkout(repo_url + "/A", A_A_path, |
---|
133 | expected_output, expected_disk, |
---|
134 | None, None, None, None, |
---|
135 | "--depth=files") |
---|
136 | |
---|
137 | # Partial (sparse) checkout |
---|
138 | svntest.actions.run_and_verify_svnversion("Sparse checkout", A_A_path, |
---|
139 | repo_url, [ "2SP\n" ], []) |
---|
140 | |
---|
141 | |
---|
142 | #---------------------------------------------------------------------- |
---|
143 | |
---|
144 | def ignore_externals(sbox): |
---|
145 | "test 'svnversion' with svn:externals" |
---|
146 | sbox.build() |
---|
147 | wc_dir = sbox.wc_dir |
---|
148 | repo_url = sbox.repo_url |
---|
149 | |
---|
150 | # Set up an external item |
---|
151 | C_path = os.path.join(wc_dir, "A", "C") |
---|
152 | externals_desc = "ext -r 1 " + repo_url + "/A/D/G" + "\n" |
---|
153 | tmp_f = os.tempnam(wc_dir, 'tmp') |
---|
154 | svntest.main.file_append(tmp_f, externals_desc) |
---|
155 | svntest.actions.run_and_verify_svn(None, None, [], |
---|
156 | 'pset', |
---|
157 | '-F', tmp_f, 'svn:externals', C_path) |
---|
158 | os.remove(tmp_f) |
---|
159 | expected_output = svntest.wc.State(wc_dir, { |
---|
160 | 'A/C' : Item(verb='Sending'), |
---|
161 | }) |
---|
162 | expected_status = svntest.actions.get_virginal_state(wc_dir, 1) |
---|
163 | expected_status.tweak('A/C', wc_rev=2) |
---|
164 | svntest.actions.run_and_verify_commit(wc_dir, |
---|
165 | expected_output, |
---|
166 | expected_status, |
---|
167 | None, wc_dir) |
---|
168 | |
---|
169 | # Update to get it on disk |
---|
170 | svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir) |
---|
171 | ext_path = os.path.join(C_path, 'ext') |
---|
172 | exit_code, out, err = svntest.actions.run_and_verify_svn( |
---|
173 | None, svntest.verify.AnyOutput, [], 'info', ext_path) |
---|
174 | |
---|
175 | for line in out: |
---|
176 | if line.find('Revision: 1') != -1: |
---|
177 | break |
---|
178 | else: |
---|
179 | raise svntest.Failure |
---|
180 | |
---|
181 | svntest.actions.run_and_verify_svnversion("working copy with svn:externals", |
---|
182 | wc_dir, repo_url, |
---|
183 | [ "2\n" ], []) |
---|
184 | |
---|
185 | ######################################################################## |
---|
186 | # Run the tests |
---|
187 | |
---|
188 | |
---|
189 | # list all tests here, starting with None: |
---|
190 | test_list = [ None, |
---|
191 | svnversion_test, |
---|
192 | ignore_externals, |
---|
193 | ] |
---|
194 | |
---|
195 | if __name__ == '__main__': |
---|
196 | warnings.filterwarnings('ignore', 'tempnam', RuntimeWarning) |
---|
197 | svntest.main.run_tests(test_list) |
---|
198 | # NOTREACHED |
---|
199 | |
---|
200 | |
---|
201 | ### End of file. |
---|