/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_workingtree/test_eol_conversion.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
 
30
30
# Sample files
31
 
_sample_text         = b"""hello\nworld\r\n"""
32
 
_sample_text_on_win  = b"""hello\r\nworld\r\n"""
 
31
_sample_text = b"""hello\nworld\r\n"""
 
32
_sample_text_on_win = b"""hello\r\nworld\r\n"""
33
33
_sample_text_on_unix = b"""hello\nworld\n"""
34
 
_sample_binary       = b"""hello\nworld\r\n\x00"""
35
 
_sample_clean_lf     = _sample_text_on_unix
36
 
_sample_clean_crlf   = _sample_text_on_win
 
34
_sample_binary = b"""hello\nworld\r\n\x00"""
 
35
_sample_clean_lf = _sample_text_on_unix
 
36
_sample_clean_crlf = _sample_text_on_win
37
37
 
38
38
 
39
39
# Lists of formats for each storage policy
40
40
_LF_IN_REPO = ['native', 'lf', 'crlf']
41
 
_CRLF_IN_REPO = [ '%s-with-crlf-in-repo' % (f,) for f in _LF_IN_REPO]
 
41
_CRLF_IN_REPO = ['%s-with-crlf-in-repo' % (f,) for f in _LF_IN_REPO]
42
42
 
43
43
 
44
44
class TestEolConversion(TestCaseWithWorkingTree):
49
49
        f = getattr(fmt, 'supports_content_filtering')
50
50
        if f is None:
51
51
            raise TestSkipped("format %s doesn't declare whether it "
52
 
                "supports content filtering, assuming not" % fmt)
 
52
                              "supports content filtering, assuming not" % fmt)
53
53
        if not f():
54
54
            raise TestSkipped("format %s doesn't support content filtering"
55
 
                % fmt)
 
55
                              % fmt)
56
56
        super(TestEolConversion, self).setUp()
57
57
 
58
58
    def patch_rules_searcher(self, eol):
82
82
        return t, basis
83
83
 
84
84
    def assertNewContentForSetting(self, wt, eol, expected_unix,
85
 
        expected_win, roundtrip):
 
85
                                   expected_win, roundtrip):
86
86
        """Clone a working tree and check the convenience content.
87
 
        
 
87
 
88
88
        If roundtrip is True, status and commit should see no changes.
89
89
        """
90
90
        if expected_win is None:
104
104
            self.assertEqual(b'', status_io.getvalue())
105
105
 
106
106
    def assertContent(self, wt, basis, expected_raw, expected_unix,
107
 
        expected_win, roundtrip_to=None):
 
107
                      expected_win, roundtrip_to=None):
108
108
        """Check the committed content and content in cloned trees.
109
 
        
 
109
 
110
110
        :param roundtrip_to: the set of formats (excluding exact) we
111
111
          can round-trip to or None for all
112
112
        """
115
115
 
116
116
        # No setting and exact should always roundtrip
117
117
        self.assertNewContentForSetting(wt, None,
118
 
            expected_raw, expected_raw, roundtrip=True)
 
118
                                        expected_raw, expected_raw, roundtrip=True)
119
119
        self.assertNewContentForSetting(wt, 'exact',
120
 
            expected_raw, expected_raw, roundtrip=True)
 
120
                                        expected_raw, expected_raw, roundtrip=True)
121
121
 
122
122
        # Roundtripping is otherwise dependent on whether the original
123
123
        # text is clean - mixed line endings will prevent it. It also
125
125
        if roundtrip_to is None:
126
126
            roundtrip_to = _LF_IN_REPO + _CRLF_IN_REPO
127
127
        self.assertNewContentForSetting(wt, 'native',
128
 
            expected_unix, expected_win, 'native' in roundtrip_to)
 
128
                                        expected_unix, expected_win, 'native' in roundtrip_to)
129
129
        self.assertNewContentForSetting(wt, 'lf',
130
 
            expected_unix, expected_unix, 'lf' in roundtrip_to)
 
130
                                        expected_unix, expected_unix, 'lf' in roundtrip_to)
131
131
        self.assertNewContentForSetting(wt, 'crlf',
132
 
            expected_win, expected_win, 'crlf' in roundtrip_to)
 
132
                                        expected_win, expected_win, 'crlf' in roundtrip_to)
133
133
        self.assertNewContentForSetting(wt, 'native-with-crlf-in-repo',
134
 
            expected_unix, expected_win,
135
 
            'native-with-crlf-in-repo' in roundtrip_to)
 
134
                                        expected_unix, expected_win,
 
135
                                        'native-with-crlf-in-repo' in roundtrip_to)
136
136
        self.assertNewContentForSetting(wt, 'lf-with-crlf-in-repo',
137
 
            expected_unix, expected_unix,
138
 
            'lf-with-crlf-in-repo' in roundtrip_to)
 
137
                                        expected_unix, expected_unix,
 
138
                                        'lf-with-crlf-in-repo' in roundtrip_to)
139
139
        self.assertNewContentForSetting(wt, 'crlf-with-crlf-in-repo',
140
 
            expected_win, expected_win,
141
 
            'crlf-with-crlf-in-repo' in roundtrip_to)
 
140
                                        expected_win, expected_win,
 
141
                                        'crlf-with-crlf-in-repo' in roundtrip_to)
142
142
 
143
143
    # Test binary files. These always roundtrip.
144
144
 
145
145
    def test_eol_no_rules_binary(self):
146
146
        wt, basis = self.prepare_tree(_sample_binary)
147
147
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
148
 
            _sample_binary)
 
148
                           _sample_binary)
149
149
 
150
150
    def test_eol_exact_binary(self):
151
151
        wt, basis = self.prepare_tree(_sample_binary, eol='exact')
152
152
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
153
 
            _sample_binary)
 
153
                           _sample_binary)
154
154
 
155
155
    def test_eol_native_binary(self):
156
156
        wt, basis = self.prepare_tree(_sample_binary, eol='native')
157
157
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
158
 
            _sample_binary)
 
158
                           _sample_binary)
159
159
 
160
160
    def test_eol_lf_binary(self):
161
161
        wt, basis = self.prepare_tree(_sample_binary, eol='lf')
162
162
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
163
 
            _sample_binary)
 
163
                           _sample_binary)
164
164
 
165
165
    def test_eol_crlf_binary(self):
166
166
        wt, basis = self.prepare_tree(_sample_binary, eol='crlf')
167
167
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
168
 
            _sample_binary)
 
168
                           _sample_binary)
169
169
 
170
170
    def test_eol_native_with_crlf_in_repo_binary(self):
171
171
        wt, basis = self.prepare_tree(_sample_binary,
172
 
            eol='native-with-crlf-in-repo')
 
172
                                      eol='native-with-crlf-in-repo')
173
173
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
174
 
            _sample_binary)
 
174
                           _sample_binary)
175
175
 
176
176
    def test_eol_lf_with_crlf_in_repo_binary(self):
177
177
        wt, basis = self.prepare_tree(_sample_binary,
178
 
            eol='lf-with-crlf-in-repo')
 
178
                                      eol='lf-with-crlf-in-repo')
179
179
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
180
 
            _sample_binary)
 
180
                           _sample_binary)
181
181
 
182
182
    def test_eol_crlf_with_crlf_in_repo_binary(self):
183
183
        wt, basis = self.prepare_tree(_sample_binary,
184
 
            eol='crlf-with-crlf-in-repo')
 
184
                                      eol='crlf-with-crlf-in-repo')
185
185
        self.assertContent(wt, basis, _sample_binary, _sample_binary,
186
 
            _sample_binary)
 
186
                           _sample_binary)
187
187
 
188
188
    # Test text with mixed line endings ("dirty text").
189
189
    # This doesn't roundtrip so status always thinks something has changed.
191
191
    def test_eol_no_rules_dirty(self):
192
192
        wt, basis = self.prepare_tree(_sample_text)
193
193
        self.assertContent(wt, basis, _sample_text,
194
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
194
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
195
195
 
196
196
    def test_eol_exact_dirty(self):
197
197
        wt, basis = self.prepare_tree(_sample_text, eol='exact')
198
198
        self.assertContent(wt, basis, _sample_text,
199
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
199
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
200
200
 
201
201
    def test_eol_native_dirty(self):
202
202
        wt, basis = self.prepare_tree(_sample_text, eol='native')
203
203
        self.assertContent(wt, basis, _sample_text_on_unix,
204
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
204
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
205
205
 
206
206
    def test_eol_lf_dirty(self):
207
207
        wt, basis = self.prepare_tree(_sample_text, eol='lf')
208
208
        self.assertContent(wt, basis, _sample_text_on_unix,
209
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
209
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
210
210
 
211
211
    def test_eol_crlf_dirty(self):
212
212
        wt, basis = self.prepare_tree(_sample_text, eol='crlf')
213
213
        self.assertContent(wt, basis, _sample_text_on_unix,
214
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
214
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
215
215
 
216
216
    def test_eol_native_with_crlf_in_repo_dirty(self):
217
217
        wt, basis = self.prepare_tree(_sample_text,
218
 
            eol='native-with-crlf-in-repo')
 
218
                                      eol='native-with-crlf-in-repo')
219
219
        self.assertContent(wt, basis, _sample_text_on_win,
220
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
220
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
221
221
 
222
222
    def test_eol_lf_with_crlf_in_repo_dirty(self):
223
223
        wt, basis = self.prepare_tree(_sample_text,
224
 
            eol='lf-with-crlf-in-repo')
 
224
                                      eol='lf-with-crlf-in-repo')
225
225
        self.assertContent(wt, basis, _sample_text_on_win,
226
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
226
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
227
227
 
228
228
    def test_eol_crlf_with_crlf_in_repo_dirty(self):
229
229
        wt, basis = self.prepare_tree(_sample_text,
230
 
            eol='crlf-with-crlf-in-repo')
 
230
                                      eol='crlf-with-crlf-in-repo')
231
231
        self.assertContent(wt, basis, _sample_text_on_win,
232
 
            _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
 
232
                           _sample_text_on_unix, _sample_text_on_win, roundtrip_to=[])
233
233
 
234
234
    # Test text with clean line endings, either always lf or always crlf.
235
235
    # This selectively roundtrips (based on what's stored in the repo).
237
237
    def test_eol_no_rules_clean_lf(self):
238
238
        wt, basis = self.prepare_tree(_sample_clean_lf)
239
239
        self.assertContent(wt, basis, _sample_clean_lf,
240
 
            _sample_text_on_unix, _sample_text_on_win,
241
 
            roundtrip_to=_LF_IN_REPO)
 
240
                           _sample_text_on_unix, _sample_text_on_win,
 
241
                           roundtrip_to=_LF_IN_REPO)
242
242
 
243
243
    def test_eol_no_rules_clean_crlf(self):
244
244
        wt, basis = self.prepare_tree(_sample_clean_crlf)
245
245
        self.assertContent(wt, basis, _sample_clean_crlf,
246
 
            _sample_text_on_unix, _sample_text_on_win,
247
 
            roundtrip_to=_CRLF_IN_REPO)
 
246
                           _sample_text_on_unix, _sample_text_on_win,
 
247
                           roundtrip_to=_CRLF_IN_REPO)
248
248
 
249
249
    def test_eol_exact_clean_lf(self):
250
250
        wt, basis = self.prepare_tree(_sample_clean_lf, eol='exact')
251
251
        self.assertContent(wt, basis, _sample_clean_lf,
252
 
            _sample_text_on_unix, _sample_text_on_win,
253
 
            roundtrip_to=_LF_IN_REPO)
 
252
                           _sample_text_on_unix, _sample_text_on_win,
 
253
                           roundtrip_to=_LF_IN_REPO)
254
254
 
255
255
    def test_eol_exact_clean_crlf(self):
256
256
        wt, basis = self.prepare_tree(_sample_clean_crlf, eol='exact')
257
257
        self.assertContent(wt, basis, _sample_clean_crlf,
258
 
            _sample_text_on_unix, _sample_text_on_win,
259
 
            roundtrip_to=_CRLF_IN_REPO)
 
258
                           _sample_text_on_unix, _sample_text_on_win,
 
259
                           roundtrip_to=_CRLF_IN_REPO)
260
260
 
261
261
    def test_eol_native_clean_lf(self):
262
262
        wt, basis = self.prepare_tree(_sample_clean_lf, eol='native')
263
263
        self.assertContent(wt, basis, _sample_text_on_unix,
264
 
            _sample_text_on_unix, _sample_text_on_win,
265
 
            roundtrip_to=_LF_IN_REPO)
 
264
                           _sample_text_on_unix, _sample_text_on_win,
 
265
                           roundtrip_to=_LF_IN_REPO)
266
266
 
267
267
    def test_eol_native_clean_crlf(self):
268
268
        wt, basis = self.prepare_tree(_sample_clean_crlf, eol='native')
269
269
        self.assertContent(wt, basis, _sample_text_on_unix,
270
 
            _sample_text_on_unix, _sample_text_on_win,
271
 
            roundtrip_to=_LF_IN_REPO)
 
270
                           _sample_text_on_unix, _sample_text_on_win,
 
271
                           roundtrip_to=_LF_IN_REPO)
272
272
 
273
273
    def test_eol_lf_clean_lf(self):
274
274
        wt, basis = self.prepare_tree(_sample_clean_lf, eol='lf')
275
275
        self.assertContent(wt, basis, _sample_text_on_unix,
276
 
            _sample_text_on_unix, _sample_text_on_win,
277
 
            roundtrip_to=_LF_IN_REPO)
 
276
                           _sample_text_on_unix, _sample_text_on_win,
 
277
                           roundtrip_to=_LF_IN_REPO)
278
278
 
279
279
    def test_eol_lf_clean_crlf(self):
280
280
        wt, basis = self.prepare_tree(_sample_clean_crlf, eol='lf')
281
281
        self.assertContent(wt, basis, _sample_text_on_unix,
282
 
            _sample_text_on_unix, _sample_text_on_win,
283
 
            roundtrip_to=_LF_IN_REPO)
 
282
                           _sample_text_on_unix, _sample_text_on_win,
 
283
                           roundtrip_to=_LF_IN_REPO)
284
284
 
285
285
    def test_eol_crlf_clean_lf(self):
286
286
        wt, basis = self.prepare_tree(_sample_clean_lf, eol='crlf')
287
287
        self.assertContent(wt, basis, _sample_text_on_unix,
288
 
            _sample_text_on_unix, _sample_text_on_win,
289
 
            roundtrip_to=_LF_IN_REPO)
 
288
                           _sample_text_on_unix, _sample_text_on_win,
 
289
                           roundtrip_to=_LF_IN_REPO)
290
290
 
291
291
    def test_eol_crlf_clean_crlf(self):
292
292
        wt, basis = self.prepare_tree(_sample_clean_crlf, eol='crlf')
293
293
        self.assertContent(wt, basis, _sample_text_on_unix,
294
 
            _sample_text_on_unix, _sample_text_on_win,
295
 
            roundtrip_to=_LF_IN_REPO)
 
294
                           _sample_text_on_unix, _sample_text_on_win,
 
295
                           roundtrip_to=_LF_IN_REPO)
296
296
 
297
297
    def test_eol_native_with_crlf_in_repo_clean_lf(self):
298
298
        wt, basis = self.prepare_tree(_sample_clean_lf,
299
 
            eol='native-with-crlf-in-repo')
 
299
                                      eol='native-with-crlf-in-repo')
300
300
        self.assertContent(wt, basis, _sample_text_on_win,
301
 
            _sample_text_on_unix, _sample_text_on_win,
302
 
            roundtrip_to=_CRLF_IN_REPO)
 
301
                           _sample_text_on_unix, _sample_text_on_win,
 
302
                           roundtrip_to=_CRLF_IN_REPO)
303
303
 
304
304
    def test_eol_native_with_crlf_in_repo_clean_crlf(self):
305
305
        wt, basis = self.prepare_tree(_sample_clean_crlf,
306
 
            eol='native-with-crlf-in-repo')
 
306
                                      eol='native-with-crlf-in-repo')
307
307
        self.assertContent(wt, basis, _sample_text_on_win,
308
 
            _sample_text_on_unix, _sample_text_on_win,
309
 
            roundtrip_to=_CRLF_IN_REPO)
 
308
                           _sample_text_on_unix, _sample_text_on_win,
 
309
                           roundtrip_to=_CRLF_IN_REPO)
310
310
 
311
311
    def test_eol_lf_with_crlf_in_repo_clean_lf(self):
312
312
        wt, basis = self.prepare_tree(_sample_clean_lf,
313
 
            eol='lf-with-crlf-in-repo')
 
313
                                      eol='lf-with-crlf-in-repo')
314
314
        self.assertContent(wt, basis, _sample_text_on_win,
315
 
            _sample_text_on_unix, _sample_text_on_win,
316
 
            roundtrip_to=_CRLF_IN_REPO)
 
315
                           _sample_text_on_unix, _sample_text_on_win,
 
316
                           roundtrip_to=_CRLF_IN_REPO)
317
317
 
318
318
    def test_eol_lf_with_crlf_in_repo_clean_crlf(self):
319
319
        wt, basis = self.prepare_tree(_sample_clean_crlf,
320
 
            eol='lf-with-crlf-in-repo')
 
320
                                      eol='lf-with-crlf-in-repo')
321
321
        self.assertContent(wt, basis, _sample_text_on_win,
322
 
            _sample_text_on_unix, _sample_text_on_win,
323
 
            roundtrip_to=_CRLF_IN_REPO)
 
322
                           _sample_text_on_unix, _sample_text_on_win,
 
323
                           roundtrip_to=_CRLF_IN_REPO)
324
324
 
325
325
    def test_eol_crlf_with_crlf_in_repo_clean_lf(self):
326
326
        wt, basis = self.prepare_tree(_sample_clean_lf,
327
 
            eol='crlf-with-crlf-in-repo')
 
327
                                      eol='crlf-with-crlf-in-repo')
328
328
        self.assertContent(wt, basis, _sample_text_on_win,
329
 
            _sample_text_on_unix, _sample_text_on_win,
330
 
            roundtrip_to=_CRLF_IN_REPO)
 
329
                           _sample_text_on_unix, _sample_text_on_win,
 
330
                           roundtrip_to=_CRLF_IN_REPO)
331
331
 
332
332
    def test_eol_crlf_with_crlf_in_repo_clean_crlf(self):
333
333
        wt, basis = self.prepare_tree(_sample_clean_crlf,
334
 
            eol='crlf-with-crlf-in-repo')
 
334
                                      eol='crlf-with-crlf-in-repo')
335
335
        self.assertContent(wt, basis, _sample_text_on_win,
336
 
            _sample_text_on_unix, _sample_text_on_win,
337
 
            roundtrip_to=_CRLF_IN_REPO)
 
336
                           _sample_text_on_unix, _sample_text_on_win,
 
337
                           roundtrip_to=_CRLF_IN_REPO)