~bzr-pqm/bzr/bzr.dev

1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
1
# Copyright (C) 2006 by Canonical Ltd
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
21
from bzrlib.tests import TestCaseWithTransport
22
23
24
class TestMove(TestCaseWithTransport):
25
26
    def test_mv_modes(self):
27
        """Test two modes of operation for mv"""
28
        tree = self.make_branch_and_tree('.')
29
        files = self.build_tree(['a', 'c', 'subdir/'])
30
        tree.add(['a', 'c', 'subdir'])
31
32
        self.run_bzr('mv', 'a', 'b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
33
        self.failUnlessExists('b')
34
        self.failIfExists('a')
35
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
36
        self.run_bzr('mv', 'b', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
37
        self.failUnlessExists('subdir/b')
38
        self.failIfExists('b')
39
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
40
        self.run_bzr('mv', 'subdir/b', 'a')
1846.1.2 by Wouter van Heyst
test mv more rigorously
41
        self.failUnlessExists('a')
42
        self.failIfExists('subdir/b')
43
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
44
        self.run_bzr('mv', 'a', 'c', 'subdir')
1846.1.2 by Wouter van Heyst
test mv more rigorously
45
        self.failUnlessExists('subdir/a')
46
        self.failUnlessExists('subdir/c')
47
        self.failIfExists('a')
48
        self.failIfExists('c')
49
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
50
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
1846.1.2 by Wouter van Heyst
test mv more rigorously
51
        self.failUnlessExists('subdir/newa')
52
        self.failIfExists('subdir/a')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
53
54
    def test_mv_unversioned(self):
55
        self.build_tree(['unversioned.txt'])
56
        self.run_bzr_error(
57
            ["^bzr: ERROR: can't rename: old name .* is not versioned$"],
58
            'mv', 'unversioned.txt', 'elsewhere')
59
60
    def test_mv_nonexisting(self):
61
        self.run_bzr_error(
62
            ["^bzr: ERROR: can't rename: old working file .* does not exist$"],
63
            'mv', 'doesnotexist', 'somewhereelse')
64
65
    def test_mv_unqualified(self):
66
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
67
        
68
    def test_mv_invalid(self):
69
        tree = self.make_branch_and_tree('.')
70
        self.build_tree(['test.txt', 'sub1/'])
71
        tree.add(['test.txt'])
72
73
        self.run_bzr_error(
74
            ["^bzr: ERROR: destination u'sub1' is not a versioned directory$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
75
            'mv', 'test.txt', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
76
        
77
        self.run_bzr_error(
78
            ["^bzr: ERROR: can't determine destination directory id for u'sub1'$"],
1846.1.2 by Wouter van Heyst
test mv more rigorously
79
            'mv', 'test.txt', 'sub1/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
80
        
81
    def test_mv_dirs(self):
82
        tree = self.make_branch_and_tree('.')
83
        self.build_tree(['hello.txt', 'sub1/'])
84
        tree.add(['hello.txt', 'sub1'])
85
1846.1.2 by Wouter van Heyst
test mv more rigorously
86
        self.run_bzr('mv', 'sub1', 'sub2')
87
        self.failUnlessExists('sub2')
88
        self.failIfExists('sub1')
89
        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.
90
        self.failUnlessExists("sub2/hello.txt")
91
        self.failIfExists("hello.txt")
92
93
        tree.read_working_inventory()
94
        tree.commit('commit with some things moved to subdirs')
95
96
        self.build_tree(['sub1/'])
97
        tree.add(['sub1'])
1846.1.2 by Wouter van Heyst
test mv more rigorously
98
        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.
99
        self.failIfExists('sub2/hello.txt')
100
        self.failUnlessExists('sub1/hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
101
        self.run_bzr('mv', 'sub2', 'sub1')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
102
        self.failIfExists('sub2')
103
        self.failUnlessExists('sub1/sub2')
104
1846.1.2 by Wouter van Heyst
test mv more rigorously
105
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
106
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
107
        tree = self.make_branch_and_tree('.')
108
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
109
        tree.commit('initial tree')
110
111
        os.chdir('sub1/sub2')
1846.1.2 by Wouter van Heyst
test mv more rigorously
112
        self.run_bzr('mv', '../hello.txt', '.')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
113
        self.failUnlessExists('./hello.txt')
114
        tree.read_working_inventory()
115
        tree.commit('move to parent directory')
116
117
        os.chdir('..')
118
1846.1.2 by Wouter van Heyst
test mv more rigorously
119
        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.
120
        self.failUnlessExists('hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
121
122
    def test_mv_smoke_aliases(self):
123
        # just test that aliases for mv exist, if their behaviour is changed in
124
        # the future, then extend the tests.
125
        self.build_tree(['a'])
126
        tree = self.make_branch_and_tree('.')
127
        tree.add(['a'])
128
129
        self.run_bzr('move', 'a', 'b')
130
        self.run_bzr('rename', 'b', 'a')