20
from breezy import commands, tests
20
from breezy import commands, osutils, tests
21
21
from breezy.tests import features
22
22
from breezy.plugins.bash_completion.bashcomp import *
45
45
stderr=subprocess.PIPE)
47
47
cword = len(words) + cword
48
input = '%s\n' % self.script
49
input += ('COMP_WORDS=( %s )\n' %
50
' '.join(["'"+w.replace("'", "'\\''")+"'" for w in words]))
51
input += 'COMP_CWORD=%d\n' % cword
52
input += '%s\n' % getattr(self, 'script_name', '_brz')
53
input += 'echo ${#COMPREPLY[*]}\n'
54
input += "IFS=$'\\n'\n"
55
input += 'echo "${COMPREPLY[*]}"\n'
48
encoding = osutils.get_user_encoding()
49
input = b'%s\n' % self.script.encode(encoding)
50
input += (b'COMP_WORDS=( %s )\n' %
51
b' '.join([b"'"+w.replace("'", "'\\''").encode(encoding)+b"'" for w in words]))
52
input += b'COMP_CWORD=%d\n' % cword
53
input += b'%s\n' % getattr(self, 'script_name', '_brz').encode(encoding)
54
input += b'echo ${#COMPREPLY[*]}\n'
55
input += b"IFS=$'\\n'\n"
56
input += b'echo "${COMPREPLY[*]}"\n'
56
57
(out, err) = proc.communicate(input)
58
59
raise AssertionError('Unexpected error message:\n%s' % err)
59
60
self.assertEqual(b'', err, 'No messages to standard error')
61
62
#print >>sys.stdout, '---\n%s\n---\n%s\n---\n' % (input, out)
62
lines = out.split('\n')
63
lines = out.split(b'\n')
63
64
nlines = int(lines[0])
65
self.assertEqual('', lines[-1], 'Newline at end')
66
self.assertEqual(b'', lines[-1], 'Newline at end')
67
if nlines == 0 and len(lines) == 1 and lines[0] == '':
68
if nlines == 0 and len(lines) == 1 and lines[0] == b'':
69
70
self.assertEqual(nlines, len(lines), 'No newlines in generated words')
70
self.completion_result = set(lines)
71
self.completion_result = {l.decode(encoding) for l in lines}
71
72
return self.completion_result
73
74
def assertCompletionEquals(self, *words):