/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
19
"""Tests of the 'brz clean-tree' command."""
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy import ignores
25
from breezy.tests import TestCaseWithTransport
26
from breezy.tests.script import run_script
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
27
28
29
class TestBzrTools(TestCaseWithTransport):
30
31
    @staticmethod
32
    def touch(filename):
6973.7.5 by Jelmer Vernooij
s/file/open.
33
        with open(filename, 'wb') as my_file:
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
34
            my_file.write(b'')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
35
36
    def test_clean_tree(self):
37
        self.run_bzr('init')
38
        self.run_bzr('ignore *~')
39
        self.run_bzr('ignore *.pyc')
40
        self.touch('name')
41
        self.touch('name~')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
42
        self.assertPathExists('name~')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
43
        self.touch('name.pyc')
44
        self.run_bzr('clean-tree --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
45
        self.assertPathExists('name~')
46
        self.assertPathDoesNotExist('name')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
47
        self.touch('name')
48
        self.run_bzr('clean-tree --detritus --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
49
        self.assertPathExists('name')
50
        self.assertPathDoesNotExist('name~')
51
        self.assertPathExists('name.pyc')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
52
        self.run_bzr('clean-tree --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
53
        self.assertPathExists('name')
54
        self.assertPathDoesNotExist('name.pyc')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
55
        self.run_bzr('clean-tree --unknown --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
56
        self.assertPathDoesNotExist('name')
4020.1.2 by Jelmer Vernooij
Import blackbox test for clean-tree, run regular tests.
57
        self.touch('name')
58
        self.touch('name~')
59
        self.touch('name.pyc')
60
        self.run_bzr('clean-tree --unknown --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
61
        self.assertPathDoesNotExist('name')
62
        self.assertPathDoesNotExist('name~')
63
        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.
64
65
    def test_clean_tree_nested_bzrdir(self):
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
66
        # 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.
67
        # bug https://bugs.launchpad.net/bzr/+bug/572098
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
68
        # 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.
69
        wt1 = self.make_branch_and_tree('.')
70
        wt2 = self.make_branch_and_tree('foo')
71
        wt3 = self.make_branch_and_tree('bar')
72
        ignores.tree_ignores_add_patterns(wt1, ['./foo'])
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
73
        self.run_bzr(['clean-tree', '--unknown', '--force'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
74
        self.assertPathExists('foo')
75
        self.assertPathExists('bar')
5195.4.5 by Alexander Belchenko
improved tests based on review of vila and parthm
76
        self.run_bzr(['clean-tree', '--ignored', '--force'])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
77
        self.assertPathExists('foo')
78
        self.assertPathExists('bar')
5195.4.7 by Gary van der Merwe
Merge bzr.dev.
79
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
80
    def test_clean_tree_directory(self):
81
        """Test --directory option"""
82
        tree = self.make_branch_and_tree('a')
83
        self.build_tree(['a/added', 'a/unknown', 'a/ignored'])
84
        tree.add('added')
85
        self.run_bzr('clean-tree -d a --unknown --ignored --force')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
86
        self.assertPathDoesNotExist('a/unknown')
87
        self.assertPathDoesNotExist('a/ignored')
88
        self.assertPathExists('a/added')
6228.1.2 by Benoît Pierre
Add a clean_tree test to check interactive prompt behaviour.
89
90
    def test_clean_tree_interactive(self):
91
        wt = self.make_branch_and_tree('.')
92
        self.touch('bar')
93
        self.touch('foo')
94
        run_script(self, """
6622.1.29 by Jelmer Vernooij
Fix some more tests.
95
        $ brz clean-tree
6228.1.2 by Benoît Pierre
Add a clean_tree test to check interactive prompt behaviour.
96
        bar
97
        foo
98
        2>Are you sure you wish to delete these? ([y]es, [n]o): no
99
        <n
100
        Canceled
101
        """)
102
        self.assertPathExists('bar')
103
        self.assertPathExists('foo')
104
        run_script(self, """
6622.1.29 by Jelmer Vernooij
Fix some more tests.
105
        $ brz clean-tree
6228.1.2 by Benoît Pierre
Add a clean_tree test to check interactive prompt behaviour.
106
        bar
107
        foo
108
        2>Are you sure you wish to delete these? ([y]es, [n]o): yes
109
        <y
110
        2>deleting paths:
111
        2>  bar
112
        2>  foo
113
        """)
114
        self.assertPathDoesNotExist('bar')
115
        self.assertPathDoesNotExist('foo')