~bzr-pqm/bzr/bzr.dev

5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
1
# Copyright (C) 2005-2010 Canonical Ltd
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
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
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
16
#
17
4020.1.5 by Aaron Bentley
Fix some formatting issues.
18
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
19
"""Tests of the 'bzr clean-tree' command."""
20
4020.1.5 by Aaron Bentley
Fix some formatting issues.
21
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
22
import os
23
5195.4.1 by Alexander Belchenko
added test to illustrate bug https://bugs.launchpad.net/bzr/+bug/572098. Currently test failed as expected.
24
from bzrlib import ignores
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
25
from bzrlib.tests import TestCaseWithTransport
26
27
28
class TestBzrTools(TestCaseWithTransport):
29
30
    @staticmethod
31
    def touch(filename):
4020.1.4 by Aaron Bentley
Assign copyright, update tests.
32
        my_file = open(filename, 'wb')
33
        try:
34
            my_file.write('')
35
        finally:
36
            my_file.close()
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
37
38
    def test_clean_tree(self):
39
        self.run_bzr('init')
40
        self.run_bzr('ignore *~')
41
        self.run_bzr('ignore *.pyc')
42
        self.touch('name')
43
        self.touch('name~')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
44
        self.assertPathExists('name~')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
45
        self.touch('name.pyc')
46
        self.run_bzr('clean-tree --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
47
        self.assertPathExists('name~')
48
        self.assertPathDoesNotExist('name')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
49
        self.touch('name')
50
        self.run_bzr('clean-tree --detritus --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
51
        self.assertPathExists('name')
52
        self.assertPathDoesNotExist('name~')
53
        self.assertPathExists('name.pyc')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
54
        self.run_bzr('clean-tree --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
55
        self.assertPathExists('name')
56
        self.assertPathDoesNotExist('name.pyc')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
57
        self.run_bzr('clean-tree --unknown --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
58
        self.assertPathDoesNotExist('name')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
59
        self.touch('name')
60
        self.touch('name~')
61
        self.touch('name.pyc')
62
        self.run_bzr('clean-tree --unknown --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
63
        self.assertPathDoesNotExist('name')
64
        self.assertPathDoesNotExist('name~')
65
        self.assertPathDoesNotExist('name.pyc')
5195.4.1 by Alexander Belchenko
added test to illustrate bug https://bugs.launchpad.net/bzr/+bug/572098. Currently test failed as expected.
66
67
    def test_clean_tree_nested_bzrdir(self):
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
68
        # clean-tree should not blindly delete nested bzrdirs (branches)
5195.4.1 by Alexander Belchenko
added test to illustrate bug https://bugs.launchpad.net/bzr/+bug/572098. Currently test failed as expected.
69
        # bug https://bugs.launchpad.net/bzr/+bug/572098
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
70
        # so it will play well with scmproj/bzr-externals plugins.
5195.4.1 by Alexander Belchenko
added test to illustrate bug https://bugs.launchpad.net/bzr/+bug/572098. Currently test failed as expected.
71
        wt1 = self.make_branch_and_tree('.')
72
        wt2 = self.make_branch_and_tree('foo')
73
        wt3 = self.make_branch_and_tree('bar')
74
        ignores.tree_ignores_add_patterns(wt1, ['./foo'])
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
75
        self.run_bzr(['clean-tree', '--unknown', '--force'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
76
        self.assertPathExists('foo')
77
        self.assertPathExists('bar')
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
78
        self.run_bzr(['clean-tree', '--ignored', '--force'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
79
        self.assertPathExists('foo')
80
        self.assertPathExists('bar')
5195.4.7 by Gary van der Merwe
Merge bzr.dev.
81
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
82
    def test_clean_tree_directory(self):
83
        """Test --directory option"""
84
        tree = self.make_branch_and_tree('a')
85
        self.build_tree(['a/added', 'a/unknown', 'a/ignored'])
86
        tree.add('added')
87
        self.run_bzr('clean-tree -d a --unknown --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
88
        self.assertPathDoesNotExist('a/unknown')
89
        self.assertPathDoesNotExist('a/ignored')
90
        self.assertPathExists('a/added')