1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
1 |
# Copyright (C) 2005, 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 |
||
18 |
"""Tests of the 'bzr add' command."""
|
|
19 |
||
20 |
import os |
|
21 |
||
22 |
from bzrlib.tests.blackbox import ExternalBase |
|
23 |
||
24 |
||
25 |
class TestAdd(ExternalBase): |
|
26 |
||
27 |
def test_add_reports(self): |
|
28 |
"""add command prints the names of added files."""
|
|
29 |
self.runbzr('init') |
|
30 |
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS']) |
|
31 |
out = self.run_bzr_captured(['add'], retcode=0)[0] |
|
32 |
# the ordering is not defined at the moment
|
|
33 |
results = sorted(out.rstrip('\n').split('\n')) |
|
34 |
self.assertEquals(['If you wish to add some of these files, please'\ |
|
35 |
' add them by name.', |
|
36 |
'added dir', |
|
37 |
'added dir/sub.txt', |
|
38 |
'added top.txt', |
|
39 |
'ignored 1 file(s).'], |
|
40 |
results) |
|
41 |
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0] |
|
42 |
results = sorted(out.rstrip('\n').split('\n')) |
|
43 |
self.assertEquals(['If you wish to add some of these files, please'\ |
|
44 |
' add them by name.', |
|
45 |
'ignored CVS matching "CVS"'], |
|
46 |
results) |
|
47 |
||
48 |
def test_add_quiet_is(self): |
|
49 |
"""add -q does not print the names of added files."""
|
|
50 |
self.runbzr('init') |
|
51 |
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt']) |
|
52 |
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0] |
|
53 |
# the ordering is not defined at the moment
|
|
54 |
results = sorted(out.rstrip('\n').split('\n')) |
|
55 |
self.assertEquals([''], results) |
|
56 |
||
57 |
def test_add_in_unversioned(self): |
|
58 |
"""Try to add a file in an unversioned directory.
|
|
59 |
||
60 |
"bzr add" should add the parent(s) as necessary.
|
|
61 |
"""
|
|
62 |
self.runbzr('init') |
|
63 |
self.build_tree(['inertiatic/', 'inertiatic/esp']) |
|
64 |
self.assertEquals(self.capture('unknowns'), 'inertiatic\n') |
|
65 |
self.run_bzr('add', 'inertiatic/esp') |
|
66 |
self.assertEquals(self.capture('unknowns'), '') |
|
67 |
||
68 |
# Multiple unversioned parents
|
|
69 |
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt']) |
|
70 |
self.assertEquals(self.capture('unknowns'), 'veil\n') |
|
71 |
self.run_bzr('add', 'veil/cerpin/taxt') |
|
72 |
self.assertEquals(self.capture('unknowns'), '') |
|
73 |
||
74 |
# Check whacky paths work
|
|
75 |
self.build_tree(['cicatriz/', 'cicatriz/esp']) |
|
76 |
self.assertEquals(self.capture('unknowns'), 'cicatriz\n') |
|
77 |
self.run_bzr('add', 'inertiatic/../cicatriz/esp') |
|
78 |
self.assertEquals(self.capture('unknowns'), '') |
|
79 |
||
80 |
def test_add_in_versioned(self): |
|
81 |
"""Try to add a file in a versioned directory.
|
|
82 |
||
83 |
"bzr add" should do this happily.
|
|
84 |
"""
|
|
85 |
self.runbzr('init') |
|
86 |
self.build_tree(['inertiatic/', 'inertiatic/esp']) |
|
87 |
self.assertEquals(self.capture('unknowns'), 'inertiatic\n') |
|
88 |
self.run_bzr('add', '--no-recurse', 'inertiatic') |
|
89 |
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n') |
|
90 |
self.run_bzr('add', 'inertiatic/esp') |
|
91 |
self.assertEquals(self.capture('unknowns'), '') |
|
92 |
||
93 |
def test_subdir_add(self): |
|
94 |
"""Add in subdirectory should add only things from there down"""
|
|
95 |
from bzrlib.workingtree import WorkingTree |
|
96 |
||
97 |
eq = self.assertEqual |
|
98 |
ass = self.assert_ |
|
99 |
chdir = os.chdir |
|
100 |
||
101 |
t = self.make_branch_and_tree('.') |
|
102 |
b = t.branch |
|
103 |
self.build_tree(['src/', 'README']) |
|
104 |
||
105 |
eq(sorted(t.unknowns()), |
|
106 |
['README', 'src']) |
|
107 |
||
108 |
self.run_bzr('add', 'src') |
|
109 |
||
110 |
self.build_tree(['src/foo.c']) |
|
111 |
||
112 |
chdir('src') |
|
113 |
self.run_bzr('add') |
|
114 |
||
115 |
self.assertEquals(self.capture('unknowns'), 'README\n') |
|
116 |
eq(len(t.read_working_inventory()), 3) |
|
117 |
||
118 |
chdir('..') |
|
119 |
self.run_bzr('add') |
|
120 |
self.assertEquals(self.capture('unknowns'), '') |
|
121 |
self.run_bzr('check') |
|
1757.2.1
by Robert Collins
Add an explicit test that adding a missing file barfs. |
122 |
|
123 |
def test_add_missing(self): |
|
124 |
"""bzr add foo where foo is missing should error."""
|
|
125 |
self.make_branch_and_tree('.') |
|
126 |
self.run_bzr('add', 'missing-file', retcode=3) |