/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Test for 'bzr mv'"""
18
19
import os
20
2091.3.6 by Aaron Bentley
Add symlink test guards
21
from bzrlib import (
22
    osutils,
23
    workingtree,
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
24
    )
25
from bzrlib.tests import (
26
    TestCaseWithTransport,
27
    TestSkipped,
28
    )
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
29
30
31
class TestMove(TestCaseWithTransport):
32
33
    def test_mv_modes(self):
34
        """Test two modes of operation for mv"""
35
        tree = self.make_branch_and_tree('.')
36
        files = self.build_tree(['a', 'c', 'subdir/'])
37
        tree.add(['a', 'c', 'subdir'])
38
39
        self.run_bzr('mv', 'a', 'b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
40
        self.failUnlessExists('b')
41
        self.failIfExists('a')
42
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
43
        self.run_bzr('mv', 'b', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
44
        self.failUnlessExists('subdir/b')
45
        self.failIfExists('b')
46
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
47
        self.run_bzr('mv', 'subdir/b', 'a')
1846.1.2 by Wouter van Heyst
test mv more rigorously
48
        self.failUnlessExists('a')
49
        self.failIfExists('subdir/b')
50
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
51
        self.run_bzr('mv', 'a', 'c', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
52
        self.failUnlessExists('subdir/a')
53
        self.failUnlessExists('subdir/c')
54
        self.failIfExists('a')
55
        self.failIfExists('c')
56
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
57
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
1846.1.2 by Wouter van Heyst
test mv more rigorously
58
        self.failUnlessExists('subdir/newa')
59
        self.failIfExists('subdir/a')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
60
61
    def test_mv_unversioned(self):
62
        self.build_tree(['unversioned.txt'])
63
        self.run_bzr_error(
64
            ["^bzr: ERROR: can't rename: old name .* is not versioned$"],
65
            'mv', 'unversioned.txt', 'elsewhere')
66
67
    def test_mv_nonexisting(self):
68
        self.run_bzr_error(
69
            ["^bzr: ERROR: can't rename: old working file .* does not exist$"],
70
            'mv', 'doesnotexist', 'somewhereelse')
71
72
    def test_mv_unqualified(self):
73
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
74
        
75
    def test_mv_invalid(self):
76
        tree = self.make_branch_and_tree('.')
77
        self.build_tree(['test.txt', 'sub1/'])
78
        tree.add(['test.txt'])
79
80
        self.run_bzr_error(
81
            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
82
            'mv', 'test.txt', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
83
        
84
        self.run_bzr_error(
85
            ["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
86
            'mv', 'test.txt', 'sub1/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
87
        
88
    def test_mv_dirs(self):
89
        tree = self.make_branch_and_tree('.')
90
        self.build_tree(['hello.txt', 'sub1/'])
91
        tree.add(['hello.txt', 'sub1'])
92
1846.1.2 by Wouter van Heyst
test mv more rigorously
93
        self.run_bzr('mv', 'sub1', 'sub2')
94
        self.failUnlessExists('sub2')
95
        self.failIfExists('sub1')
96
        self.run_bzr('mv', 'hello.txt', 'sub2')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
97
        self.failUnlessExists("sub2/hello.txt")
98
        self.failIfExists("hello.txt")
99
100
        tree.read_working_inventory()
101
        tree.commit('commit with some things moved to subdirs')
102
103
        self.build_tree(['sub1/'])
104
        tree.add(['sub1'])
1846.1.2 by Wouter van Heyst
test mv more rigorously
105
        self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
106
        self.failIfExists('sub2/hello.txt')
107
        self.failUnlessExists('sub1/hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
108
        self.run_bzr('mv', 'sub2', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
109
        self.failIfExists('sub2')
110
        self.failUnlessExists('sub1/sub2')
111
1846.1.2 by Wouter van Heyst
test mv more rigorously
112
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
113
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
114
        tree = self.make_branch_and_tree('.')
115
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
116
        tree.commit('initial tree')
117
118
        os.chdir('sub1/sub2')
1846.1.2 by Wouter van Heyst
test mv more rigorously
119
        self.run_bzr('mv', '../hello.txt', '.')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
120
        self.failUnlessExists('./hello.txt')
121
        tree.read_working_inventory()
122
        tree.commit('move to parent directory')
123
124
        os.chdir('..')
125
1846.1.2 by Wouter van Heyst
test mv more rigorously
126
        self.run_bzr('mv', 'sub2/hello.txt', '.')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
127
        self.failUnlessExists('hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
128
129
    def test_mv_smoke_aliases(self):
130
        # just test that aliases for mv exist, if their behaviour is changed in
131
        # the future, then extend the tests.
132
        self.build_tree(['a'])
133
        tree = self.make_branch_and_tree('.')
134
        tree.add(['a'])
135
136
        self.run_bzr('move', 'a', 'b')
137
        self.run_bzr('rename', 'b', 'a')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
138
139
    def test_mv_through_symlinks(self):
2091.3.6 by Aaron Bentley
Add symlink test guards
140
        if not osutils.has_symlinks():
141
            raise TestSkipped('Symlinks are not supported on this platform')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
142
        tree = self.make_branch_and_tree('.')
143
        self.build_tree(['a/', 'a/b'])
144
        os.symlink('a', 'c')
145
        os.symlink('.', 'd')
146
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
147
        self.run_bzr('mv', 'c/b', 'b')
148
        tree = workingtree.WorkingTree.open('.')
149
        self.assertEqual('b-id', tree.path2id('b'))