~bzr-pqm/bzr/bzr.dev

1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
1
"""Black-box tests for bzr aliases.
2
"""
3
4
import os
5
6
from bzrlib.branch import Branch
7
from bzrlib.tests import TestCaseInTempDir
8
from bzrlib.trace import mutter
1551.2.48 by abentley
Used ensure_config_dir exists instead of makedirs
9
from bzrlib.config import (ensure_config_dir_exists, config_filename)
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
10
1553.6.9 by Erik Bågfors
PEP8-ify
11
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
12
class TestAliases(TestCaseInTempDir):
13
14
    def test_aliases(self):
15
16
        def bzr(*args, **kwargs):
17
            return self.run_bzr(*args, **kwargs)[0]
18
1553.6.16 by Erik Bågfors
better test for --no-aliases
19
        def bzr_catch_error(*args, **kwargs):
20
            return self.run_bzr(*args, **kwargs)[1]
21
22
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
23
        if os.path.isfile(config_filename()):
1553.6.9 by Erik Bågfors
PEP8-ify
24
            # Something is wrong in environment, 
25
            # we risk overwriting users config 
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
26
            self.assert_(config_filename() + "exists, abort")
1551.2.42 by abentley
Fixed config directory creation in test_aliases
27
        
1551.2.48 by abentley
Used ensure_config_dir exists instead of makedirs
28
        ensure_config_dir_exists()
1553.6.7 by Erik Bågfors
test for option overrides
29
        CONFIG=("[ALIASES]\n"
30
                "c=cat\n"
31
                "c1=cat -r 1\n"
32
                "c2=cat -r 1 -r2\n")
33
34
        open(config_filename(),'wb').write(CONFIG)
35
36
37
        str1 = 'foo\n'
38
        str2 = 'bar\n'
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
39
40
        bzr('init')
1553.6.7 by Erik Bågfors
test for option overrides
41
        open('a', 'wb').write(str1)
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
42
        bzr('add', 'a')
43
44
        bzr('commit', '-m', '1')
45
1553.6.7 by Erik Bågfors
test for option overrides
46
        self.assertEquals(bzr('c', 'a'), str1)
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
47
1553.6.7 by Erik Bågfors
test for option overrides
48
        open('a', 'wb').write(str2)
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
49
        bzr('commit', '-m', '2')
50
1553.6.7 by Erik Bågfors
test for option overrides
51
        self.assertEquals(bzr('c', 'a'), str2)
52
        self.assertEquals(bzr('c1', 'a'), str1)
53
        self.assertEquals(bzr('c1', '--revision', '2', 'a'), str2)
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
54
1553.6.16 by Erik Bågfors
better test for --no-aliases
55
        # If --no-aliases isn't working, we will not get retcode=3
1553.6.6 by Erik Bågfors
blackbox tests for aliases,--no-aliases and aliases with options
56
        bzr('--no-aliases', 'c', 'a', retcode=3)
57
1553.6.16 by Erik Bågfors
better test for --no-aliases
58
        # If --no-aliases breaks all of bzr, we also get retcode=3
59
        # So we need to catch the output as well
1740.5.6 by Martin Pool
Clean up many exception classes.
60
        self.assertEquals(bzr_catch_error('--no-aliases', 'c', 'a',
61
                                          retcode=None),
62
                          'bzr: ERROR: unknown command "c"\n')
1553.6.16 by Erik Bågfors
better test for --no-aliases
63
1553.6.7 by Erik Bågfors
test for option overrides
64
        bzr('c', '-r1', '-r2', retcode=3)
65
        bzr('c1', '-r1', '-r2', retcode=3)
66
        bzr('c2', retcode=3)
67
        bzr('c2', '-r1', retcode=3)