~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
16
17
"""Test the executable bit under various working tree formats."""
18
19
import os
20
2911.5.4 by John Arbash Meinel
Switch around to properly look up the executable bit in the basis.
21
from bzrlib import (
22
    osutils,
23
    )
1852.6.6 by Robert Collins
Finish updating iter_entries change to make all tests pass.
24
from bzrlib.inventory import InventoryFile
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
25
from bzrlib.transform import TreeTransform
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
26
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
27
28
29
class TestExecutable(TestCaseWithWorkingTree):
30
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
31
    def setUp(self):
32
        super(TestExecutable, self).setUp()
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
33
        self.thisFailsStrictLockCheck()
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
34
35
        self.a_id = "a-20051208024829-849e76f7968d7a86"
36
        self.b_id = "b-20051208024829-849e76f7968d7a86"
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
37
        wt = self.make_branch_and_tree('b1')
38
        b = wt.branch
39
        tt = TreeTransform(wt)
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
40
        tt.new_file('a', tt.root, 'a test\n', self.a_id, True)
41
        tt.new_file('b', tt.root, 'b test\n', self.b_id, False)
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
42
        tt.apply()
43
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
44
        self.wt = wt
45
46
    def check_exist(self, tree):
47
        """Just check that both files have the right executable bits set"""
2255.2.35 by Robert Collins
Remove inappropriate use of inventory in tree executability tests. The inventory is not the authoritative source of executability.
48
        tree.lock_read()
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
49
        self.failUnless(tree.is_executable(self.a_id),
50
                        "'a' lost the execute bit")
51
        self.failIf(tree.is_executable(self.b_id),
52
                    "'b' gained an execute bit")
2255.2.35 by Robert Collins
Remove inappropriate use of inventory in tree executability tests. The inventory is not the authoritative source of executability.
53
        tree.unlock()
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
54
55
    def check_empty(self, tree, ignore_inv=False):
56
        """Check that the files are truly missing
57
        :param ignore_inv: If you just delete files from a working tree
58
                the inventory still shows them, so don't assert that
59
                the inventory is empty, just that the tree doesn't have them
60
        """
2255.2.36 by Robert Collins
Fix Dirstate unversioning of entries which are in a parent.
61
        tree.lock_read()
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
62
        if not ignore_inv:
1852.6.6 by Robert Collins
Finish updating iter_entries change to make all tests pass.
63
            self.assertEqual(
64
                [('', tree.inventory.root)],
65
                list(tree.inventory.iter_entries()))
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
66
        self.failIf(tree.has_id(self.a_id))
67
        self.failIf(tree.has_filename('a'))
68
        self.failIf(tree.has_id(self.b_id))
69
        self.failIf(tree.has_filename('b'))
2255.2.36 by Robert Collins
Fix Dirstate unversioning of entries which are in a parent.
70
        tree.unlock()
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
71
72
    def commit_and_branch(self):
73
        """Commit the current tree, and create a second tree"""
74
        self.wt.commit('adding a,b', rev_id='r1')
75
        # Now make sure that 'bzr branch' also preserves the
76
        # executable bit
77
        # TODO: Maybe this should be a blackbox test
78
        dir2 = self.wt.branch.bzrdir.clone('b2', revision_id='r1')
79
        wt2 = dir2.open_workingtree()
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
80
        self.assertEqual(['r1'], wt2.get_parent_ids())
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
81
        self.assertEqual('r1', wt2.branch.last_revision())
82
        return wt2
83
84
    def test_01_is_executable(self):
85
        """Make sure that the tree was created and has the executable bit set"""
86
        self.check_exist(self.wt)
87
88
    def test_02_stays_executable(self):
89
        """reopen the tree and ensure it stuck."""
90
        self.wt = self.wt.bzrdir.open_workingtree()
91
        self.check_exist(self.wt)
92
93
    def test_03_after_commit(self):
94
        """Commit the change, and check the history"""
95
        self.wt.commit('adding a,b', rev_id='r1')
96
97
        rev_tree = self.wt.branch.repository.revision_tree('r1')
98
        self.check_exist(rev_tree)
99
100
    def test_04_after_removed(self):
101
        """Make sure reverting removed files brings them back correctly"""
102
        self.wt.commit('adding a,b', rev_id='r1')
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
103
104
        # Make sure the entries are gone
105
        os.remove('b1/a')
106
        os.remove('b1/b')
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
107
        self.check_empty(self.wt, ignore_inv=True)
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
108
109
        # Make sure that revert is able to bring them back,
110
        # and sets 'a' back to being executable
111
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
112
        rev_tree = self.wt.branch.repository.revision_tree('r1')
113
114
        self.wt.revert(['a', 'b'], rev_tree, backups=False)
115
        self.check_exist(self.wt)
116
117
    def test_05_removed_and_committed(self):
118
        """Check that reverting to an earlier commit restores them"""
119
        self.wt.commit('adding a,b', rev_id='r1')
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
120
121
        # Now remove them again, and make sure that after a
122
        # commit, they are still marked correctly
123
        os.remove('b1/a')
124
        os.remove('b1/b')
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
125
        self.wt.commit('removed', rev_id='r2')
126
127
        self.check_empty(self.wt)
128
129
        rev_tree = self.wt.branch.repository.revision_tree('r1')
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
130
        # Now revert back to the previous commit
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
131
        self.wt.revert(old_tree=rev_tree, backups=False)
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
132
133
        self.check_exist(self.wt)
134
135
    def test_06_branch(self):
136
        """branch b1=>b2 should preserve the executable bits"""
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
137
        # TODO: Maybe this should be a blackbox test
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
138
        wt2 = self.commit_and_branch()
139
140
        self.check_exist(wt2)
141
142
    def test_07_pull(self):
143
        """Test that pull will handle bits correctly"""
144
        wt2 = self.commit_and_branch()
145
146
        os.remove('b1/a')
147
        os.remove('b1/b')
148
        self.wt.commit('removed', rev_id='r2')
149
150
        # now wt2 can pull and the files should be removed
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
151
152
        # Make sure pull will delete the files
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
153
        wt2.pull(self.wt.branch)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
154
        self.assertEquals(['r2'], wt2.get_parent_ids())
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
155
        self.assertEquals('r2', wt2.branch.last_revision())
156
        self.check_empty(wt2)
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
157
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
158
        # Now restore the files on the first branch and commit
1711.4.30 by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins)
159
        # so that the second branch can pull the changes
160
        # and make sure that the executable bit has been copied
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
161
        rev_tree = self.wt.branch.repository.revision_tree('r1')
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
162
        self.wt.revert(old_tree=rev_tree, backups=False)
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
163
        self.wt.commit('resurrected', rev_id='r3')
164
165
        self.check_exist(self.wt)
166
167
        wt2.pull(self.wt.branch)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
168
        self.assertEquals(['r3'], wt2.get_parent_ids())
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
169
        self.assertEquals('r3', wt2.branch.last_revision())
170
        self.check_exist(wt2)
171
172
    def test_08_no_op_revert(self):
173
        """Just do a simple revert without anything changed
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
174
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
175
        The bits shouldn't swap.
176
        """
177
        self.wt.commit('adding a,b', rev_id='r1')
178
        rev_tree = self.wt.branch.repository.revision_tree('r1')
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
179
        self.wt.revert(old_tree=rev_tree, backups=False)
1711.4.33 by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones.
180
        self.check_exist(self.wt)
181
2911.5.4 by John Arbash Meinel
Switch around to properly look up the executable bit in the basis.
182
    def test_commit_with_exec_from_basis(self):
183
        self.wt._is_executable_from_path_and_stat = \
184
            self.wt._is_executable_from_path_and_stat_from_basis
185
        rev_id1 = self.wt.commit('one')
186
        rev_tree1 = self.wt.branch.repository.revision_tree(rev_id1)
187
        a_executable = rev_tree1.inventory[self.a_id].executable
188
        b_executable = rev_tree1.inventory[self.b_id].executable
189
        self.assertIsNot(None, a_executable)
190
        self.assertTrue(a_executable)
191
        self.assertIsNot(None, b_executable)
192
        self.assertFalse(b_executable)
193
194
    def test_use_exec_from_basis(self):
195
        if osutils.supports_executable():
196
            self.assertEqual(self.wt._is_executable_from_path_and_stat_from_stat,
197
                             self.wt._is_executable_from_path_and_stat)
198
        else:
199
            self.assertEqual(self.wt._is_executable_from_path_and_stat_from_basis,
200
                             self.wt._is_executable_from_path_and_stat)