13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
"""Black-box tests for bzr aliases.
21
from bzrlib import config
22
21
from bzrlib.branch import Branch
23
from bzrlib.tests import TestCaseWithTransport
22
from bzrlib.tests import TestCaseInTempDir
24
23
from bzrlib.trace import mutter
27
class TestAliases(TestCaseWithTransport):
24
from bzrlib.config import (ensure_config_dir_exists, config_filename)
27
class TestAliases(TestCaseInTempDir):
29
29
def test_aliases(self):
31
def bzr(args, **kwargs):
32
return self.run_bzr(args, **kwargs)[0]
34
def bzr_catch_error(args, **kwargs):
35
return self.run_bzr(args, **kwargs)[1]
38
conf = config.GlobalConfig.from_string('''[ALIASES]
31
def bzr(*args, **kwargs):
32
return self.run_bzr(*args, **kwargs)[0]
34
def bzr_catch_error(*args, **kwargs):
35
return self.run_bzr(*args, **kwargs)[1]
38
if os.path.isfile(config_filename()):
39
# Something is wrong in environment,
40
# we risk overwriting users config
41
self.assert_(config_filename() + "exists, abort")
43
ensure_config_dir_exists()
49
open(config_filename(),'wb').write(CONFIG)
47
tree = self.make_branch_and_tree('.')
48
self.build_tree_contents([('a', str1)])
50
tree.commit(message='1')
52
self.assertEquals(bzr('c a'), str1)
54
self.build_tree_contents([('a', str2)])
55
tree.commit(message='2')
57
self.assertEquals(bzr('c a'), str2)
58
self.assertEquals(bzr('c1 a'), str1)
59
self.assertEquals(bzr('c1 --revision 2 a'), str2)
56
open('a', 'wb').write(str1)
59
bzr('commit', '-m', '1')
61
self.assertEquals(bzr('c', 'a'), str1)
63
open('a', 'wb').write(str2)
64
bzr('commit', '-m', '2')
66
self.assertEquals(bzr('c', 'a'), str2)
67
self.assertEquals(bzr('c1', 'a'), str1)
68
self.assertEquals(bzr('c1', '--revision', '2', 'a'), str2)
61
70
# If --no-aliases isn't working, we will not get retcode=3
62
bzr('--no-aliases c a', retcode=3)
71
bzr('--no-aliases', 'c', 'a', retcode=3)
64
73
# If --no-aliases breaks all of bzr, we also get retcode=3
65
74
# So we need to catch the output as well
66
self.assertEquals(bzr_catch_error('--no-aliases c a',
75
self.assertEquals(bzr_catch_error('--no-aliases', 'c', 'a',
68
77
'bzr: ERROR: unknown command "c"\n')
70
bzr('c -r1 -r2', retcode=3)
71
bzr('c1 -r1 -r2', retcode=3)
79
bzr('c', '-r1', '-r2', retcode=3)
80
bzr('c1', '-r1', '-r2', retcode=3)
72
81
bzr('c2', retcode=3)
73
bzr('c2 -r1', retcode=3)
82
bzr('c2', '-r1', retcode=3)