From 64a32a910bca5ea6490a66a5c1660fe675c8dcad Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 11:50:28 +0400 Subject: [PATCH 01/19] Add window_cached decorator for ctrlp segment --- powerline/segments/plugin/ctrlp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerline/segments/plugin/ctrlp.py b/powerline/segments/plugin/ctrlp.py index e5893d7d..3c6af70d 100644 --- a/powerline/segments/plugin/ctrlp.py +++ b/powerline/segments/plugin/ctrlp.py @@ -6,8 +6,10 @@ except ImportError: vim = object() # NOQA from powerline.bindings.vim import getbufvar +from powerline.segments.vim import window_cached +@window_cached def ctrlp(pl, side): ''' From e8b2054868a9ef80183c217e71f933c56c8cf617 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 11:51:41 +0400 Subject: [PATCH 02/19] Make nerdtree segment use bufvar_exists --- powerline/bindings/vim/__init__.py | 12 ++++++++++++ powerline/segments/plugin/nerdtree.py | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/powerline/bindings/vim/__init__.py b/powerline/bindings/vim/__init__.py index 6705222d..ef8643ff 100644 --- a/powerline/bindings/vim/__init__.py +++ b/powerline/bindings/vim/__init__.py @@ -66,6 +66,18 @@ else: else: raise KeyError(varname) +if hasattr(vim, 'vars') and vim.vvars['version'] > 703: + def bufvar_exists(buffer, varname): + buffer = buffer or vim.current.buffer + return varname in buffer.vars +else: + def bufvar_exists(buffer, varname): # NOQA + if not buffer or buffer.number == vim.current.buffer.number: + return vim.eval('exists("b:{0}")'.format(varname)) + else: + return vim.eval('has_key(getbufvar({0}, ""), {1})' + .format(buffer.number, varname)) + if hasattr(vim, 'options'): def vim_getbufoption(info, option): return info['buffer'].options[option] diff --git a/powerline/segments/plugin/nerdtree.py b/powerline/segments/plugin/nerdtree.py index 39eb5aec..a8e6ad85 100644 --- a/powerline/segments/plugin/nerdtree.py +++ b/powerline/segments/plugin/nerdtree.py @@ -5,7 +5,7 @@ try: except ImportError: vim = object() # NOQA -from powerline.bindings.vim import getbufvar +from powerline.bindings.vim import bufvar_exists from powerline.segments.vim import window_cached @@ -15,9 +15,8 @@ def nerdtree(pl): Highlight groups used: ``nerdtree.path`` or ``file_name``. ''' - ntr = getbufvar('%', 'NERDTreeRoot') - if not ntr: - return + if not bufvar_exists(None, 'NERDTreeRoot'): + return None path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()') return [{ 'contents': path_str, From 73d7b0db08288d0576a59721f450f2bf34e336a5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 11:51:58 +0400 Subject: [PATCH 03/19] Add functional tests for plugin themes --- tests/test_configuration.py | 10 +++++++++- tests/vim.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 93857ec4..672c31b7 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -23,11 +23,15 @@ class TestConfig(TestCase): (('bufoptions',), {'buftype': 'help'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}), + (('bufname', 'NERD_tree_1'), {}), + (('bufname', '__Gundo__'), {}), + (('bufname', '__Gundo_Preview__'), {}), + (('bufname', 'ControlP'), {}), ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: local_themes_raw = json.load(f)['ext']['vim']['local_themes'] # Don't run tests on external/plugin segments - local_themes = dict((k, v) for (k, v) in local_themes_raw.items() if not '.' in k) + local_themes = dict((k, v) for (k, v) in local_themes_raw.items()) self.assertEqual(len(buffers), len(local_themes)) outputs = {} i = 0 @@ -58,6 +62,10 @@ class TestConfig(TestCase): i += 1 if mode in exclude: continue + if mode == 'nc' and args == ('bufname', 'ControlP'): + # ControlP window is not supposed to not + # be in the focus + continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: diff --git a/tests/vim.py b/tests/vim.py index 91a94886..bcc549b6 100644 --- a/tests/vim.py +++ b/tests/vim.py @@ -171,9 +171,13 @@ def eval(expr): return options[expr[1:]] elif expr.startswith('PowerlineRegisterCachePurgerEvent'): _buf_purge_events.add(expr[expr.find('"') + 1:expr.rfind('"') - 1]) - return "0" + return '0' elif expr.startswith('exists('): return '0' + elif expr == 'getbufvar("%", "NERDTreeRoot").path.str()': + import os + assert os.path.basename(buffers[_buffer()].name).startswith('NERD_tree_') + return '/usr/include' raise NotImplementedError @@ -205,6 +209,7 @@ def _emul_mode(*args): @_vim @_str_func def _emul_getbufvar(bufnr, varname): + import re if varname[0] == '&': if bufnr == '%': bufnr = buffers[_buffer()].number @@ -217,6 +222,12 @@ def _emul_getbufvar(bufnr, varname): return options[varname[1:]] except KeyError: return '' + elif re.match('^[a-zA-Z_]+$', varname): + if bufnr == '%': + bufnr = buffers[_buffer()].number + if bufnr not in buffers: + return '' + return buffers[bufnr].vars[varname] raise NotImplementedError @@ -625,10 +636,14 @@ class _WithBufName(object): self.new = new def __enter__(self): + import os buffer = buffers[_buffer()] self.buffer = buffer self.old = buffer.name buffer.name = self.new + if buffer.name and os.path.basename(buffer.name) == 'ControlP': + buffer.vars['powerline_ctrlp_type'] = 'main' + buffer.vars['powerline_ctrlp_args'] = ['focus', 'byfname', '0', 'prev', 'item', 'next', 'marked'] def __exit__(self, *args): self.buffer.name = self.old From bd4173eb1fdff221c338930d0b53fa55e9a8726c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 12:43:13 +0400 Subject: [PATCH 04/19] Add jobnum segment to default_leftonly theme --- powerline/config_files/themes/shell/default_leftonly.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powerline/config_files/themes/shell/default_leftonly.json b/powerline/config_files/themes/shell/default_leftonly.json index 16af9755..5060e1ea 100644 --- a/powerline/config_files/themes/shell/default_leftonly.json +++ b/powerline/config_files/themes/shell/default_leftonly.json @@ -34,6 +34,10 @@ "dir_limit_depth": 3 } }, + { + "module": "powerline.segments.shell", + "name": "jobnum" + }, { "name": "last_status", "module": "powerline.segments.shell" From fb00a9586b37d23d7f9525c66e22040c5a6a92d7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 12:50:50 +0400 Subject: [PATCH 05/19] Fix copy-paste typo in shell.py --- powerline/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerline/shell.py b/powerline/shell.py index b887d323..aa04dc3d 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -62,6 +62,6 @@ def finish_args(args): if args.config: args.config = mergeargs((parsedotval(v) for v in args.config)) if args.theme_option: - args.theme_option = mergeargs((parsedotval(v) for v in args.config)) + args.theme_option = mergeargs((parsedotval(v) for v in args.theme_option)) else: args.theme_option = {} From f20792bb380154236daa0114912a98cd2b204ac8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 13:16:25 +0400 Subject: [PATCH 06/19] Add bash functional tests --- tests/test.sh | 6 +++++ tests/test_shells.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 tests/test_shells.sh diff --git a/tests/test.sh b/tests/test.sh index e5b137ff..47b3a00e 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -4,10 +4,12 @@ FAILED=0 export PYTHONPATH="${PYTHONPATH}:`realpath .`" for file in tests/test_*.py ; do if ! ${PYTHON} $file --verbose --catch ; then + echo "Failed test(s) from $file" FAILED=1 fi done if ! ${PYTHON} scripts/powerline-lint -p powerline/config_files ; then + echo "Failed powerline-lint" FAILED=1 fi for script in tests/*.vim ; do @@ -18,4 +20,8 @@ for script in tests/*.vim ; do FAILED=1 fi done +if ! sh tests/test_shells.sh ; then + echo "Failed shells" + FAILED=1 +fi exit $FAILED diff --git a/tests/test_shells.sh b/tests/test_shells.sh new file mode 100755 index 00000000..5da7ffac --- /dev/null +++ b/tests/test_shells.sh @@ -0,0 +1,56 @@ +#!/bin/sh +FAILED=0 +if [ "$(echo '\e')" != '\e' ] ; then + safe_echo() { + echo -E "$@" + } +else + safe_echo() { + echo "$@" + } +fi +mkdir tests/shell +git init tests/shell/bash +git --git-dir=tests/shell/bash/.git checkout -b BRANCH +INPUT=' +POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +VIRTUAL_ENV= +COLUMNS=80 +source powerline/bindings/bash/powerline.sh ; cd tests/shell/bash +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +false +kill `cat pid` ; sleep 1s +false +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +exit +' +OUTPUT="`safe_echo "$INPUT" | LANG=C bash -i 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" +OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/bash/pid)/PID/g -e 's/\x1b/\\\\e/g'`" +EXPECTED_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mcd .git +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mbash \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m.git \e[0;38;5;240;49;22m \e[0mcd .. +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;74;22m \e[0;38;5;231;48;5;74mⓔ  some-virtual-environment \e[0;38;5;74;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV= +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mbash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +[1] PID +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;49;22m \e[0mfalse +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mkill `cat pid` ; sleep 1s +[1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mfalse +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +\e[0;38;5;220;48;5;166m  zyx-desktop \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mexit +exit' +if [ "b$EXPECTED_OUTPUT" != "b$OUTPUT" ] ; then + safe_echo "$EXPECTED_OUTPUT" > tests/shell/expected + safe_echo "$OUTPUT" > tests/shell/actual + diff -u tests/shell/expected tests/shell/actual + rm tests/shell/expected tests/shell/actual + FAILED=1 +fi +rm -r tests/shell +exit $FAILED From 301dbf2bd3eb80acef7850cea02f4218d403a711 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 13:31:57 +0400 Subject: [PATCH 07/19] Add a few empty lines, rename bash directory to 3rd --- tests/test_shells.sh | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/test_shells.sh b/tests/test_shells.sh index 5da7ffac..9b6b09e3 100755 --- a/tests/test_shells.sh +++ b/tests/test_shells.sh @@ -1,5 +1,6 @@ #!/bin/sh FAILED=0 + if [ "$(echo '\e')" != '\e' ] ; then safe_echo() { echo -E "$@" @@ -9,14 +10,16 @@ else echo "$@" } fi + mkdir tests/shell -git init tests/shell/bash -git --git-dir=tests/shell/bash/.git checkout -b BRANCH +git init tests/shell/3rd +git --git-dir=tests/shell/3rd/.git checkout -b BRANCH + INPUT=' POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" VIRTUAL_ENV= COLUMNS=80 -source powerline/bindings/bash/powerline.sh ; cd tests/shell/bash +source powerline/bindings/bash/powerline.sh ; cd tests/shell/3rd POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" cd .git cd .. @@ -29,22 +32,25 @@ false POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" exit ' + OUTPUT="`safe_echo "$INPUT" | LANG=C bash -i 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" -OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/bash/pid)/PID/g -e 's/\x1b/\\\\e/g'`" -EXPECTED_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mcd .git -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mbash \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m.git \e[0;38;5;240;49;22m \e[0mcd .. -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;74;22m \e[0;38;5;231;48;5;74mⓔ  some-virtual-environment \e[0;38;5;74;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV= -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mbash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g'`" + +EXPECTED_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mcd .git +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240m3rd \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m.git \e[0;38;5;240;49;22m \e[0mcd .. +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;74;22m \e[0;38;5;231;48;5;74mⓔ  some-virtual-environment \e[0;38;5;74;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV= +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mbash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & [1] PID -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;49;22m \e[0mfalse -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mkill `cat pid` ; sleep 1s +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;49;22m \e[0mfalse +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mkill `cat pid` ; sleep 1s [1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mfalse -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -\e[0;38;5;220;48;5;166m  zyx-desktop \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1mbash \e[0;38;5;240;49;22m \e[0mexit +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mfalse +\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +\e[0;38;5;220;48;5;166m  zyx-desktop \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mexit exit' + if [ "b$EXPECTED_OUTPUT" != "b$OUTPUT" ] ; then safe_echo "$EXPECTED_OUTPUT" > tests/shell/expected safe_echo "$OUTPUT" > tests/shell/actual @@ -52,5 +58,7 @@ if [ "b$EXPECTED_OUTPUT" != "b$OUTPUT" ] ; then rm tests/shell/expected tests/shell/actual FAILED=1 fi + rm -r tests/shell + exit $FAILED From ed99b09e8630f6bee14a6073f3436e812eccf6f9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 13:36:02 +0400 Subject: [PATCH 08/19] Use get_output function --- tests/test_shells.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test_shells.sh b/tests/test_shells.sh index 9b6b09e3..9a237ce8 100755 --- a/tests/test_shells.sh +++ b/tests/test_shells.sh @@ -11,6 +11,12 @@ else } fi +get_output() { + OUTPUT="`safe_echo "$INPUT" | LANG=C $@ 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" + OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g'`" + safe_echo "$OUTPUT" +} + mkdir tests/shell git init tests/shell/3rd git --git-dir=tests/shell/3rd/.git checkout -b BRANCH @@ -33,10 +39,9 @@ POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname. exit ' -OUTPUT="`safe_echo "$INPUT" | LANG=C bash -i 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" -OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g'`" +BASH_OUTPUT="`get_output bash -i`" -EXPECTED_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +EXPECTED_BASH_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mcd .git \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240m3rd \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m.git \e[0;38;5;240;49;22m \e[0mcd .. \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" @@ -50,15 +55,12 @@ EXPECTED_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" \e[0;38;5;220;48;5;166m  zyx-desktop \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mexit exit' - -if [ "b$EXPECTED_OUTPUT" != "b$OUTPUT" ] ; then - safe_echo "$EXPECTED_OUTPUT" > tests/shell/expected - safe_echo "$OUTPUT" > tests/shell/actual +if [ "b$EXPECTED_BASH_OUTPUT" != "b$BASH_OUTPUT" ] ; then + safe_echo "$EXPECTED_BASH_OUTPUT" > tests/shell/expected + safe_echo "$BASH_OUTPUT" > tests/shell/actual diff -u tests/shell/expected tests/shell/actual rm tests/shell/expected tests/shell/actual FAILED=1 fi - rm -r tests/shell - exit $FAILED From bb9034adcf084b099a99c6ea4dae0815cea5c038 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 11 Jan 2014 13:52:07 +0400 Subject: [PATCH 09/19] Replace zyx-desktop with HOSTNAME --- tests/test_shells.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_shells.sh b/tests/test_shells.sh index 9a237ce8..771ebca6 100755 --- a/tests/test_shells.sh +++ b/tests/test_shells.sh @@ -13,7 +13,7 @@ fi get_output() { OUTPUT="`safe_echo "$INPUT" | LANG=C $@ 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" - OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g'`" + OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g' | python -c 'import socket, sys; hostname=socket.gethostname(); exec ("""for line in sys.stdin:\n sys.stdout.write(line.replace(hostname, "HOSTNAME"))""")'`" safe_echo "$OUTPUT" } @@ -39,7 +39,7 @@ POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname. exit ' -BASH_OUTPUT="`get_output bash -i`" +BASH_OUTPUT="`get_output bash --noprofile -i`" EXPECTED_BASH_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mcd .git @@ -53,7 +53,7 @@ EXPECTED_BASH_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m [1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mfalse \e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -\e[0;38;5;220;48;5;166m  zyx-desktop \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mexit +\e[0;38;5;220;48;5;166m  HOSTNAME \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mexit exit' if [ "b$EXPECTED_BASH_OUTPUT" != "b$BASH_OUTPUT" ] ; then safe_echo "$EXPECTED_BASH_OUTPUT" > tests/shell/expected From 55957ec3cb4a6a4b15e9fe7dc482d2c38029d440 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Jan 2014 23:45:17 +0400 Subject: [PATCH 10/19] Move shell testing to tests/test_shells/test.sh --- tests/test.sh | 2 +- tests/{test_shells.sh => test_shells/test.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{test_shells.sh => test_shells/test.sh} (100%) diff --git a/tests/test.sh b/tests/test.sh index 47b3a00e..8d03f548 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -20,7 +20,7 @@ for script in tests/*.vim ; do FAILED=1 fi done -if ! sh tests/test_shells.sh ; then +if ! sh tests/test_shells/test.sh ; then echo "Failed shells" FAILED=1 fi diff --git a/tests/test_shells.sh b/tests/test_shells/test.sh similarity index 100% rename from tests/test_shells.sh rename to tests/test_shells/test.sh From 6996896b22f336ec2ed3125e9b95163e45cbc55e Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 00:53:38 +0400 Subject: [PATCH 11/19] Made it use screen for testing --- tests/test_shells/bash.ok | 14 +++++++++ tests/test_shells/input.sh | 14 +++++++++ tests/test_shells/screenrc | 3 ++ tests/test_shells/test.sh | 64 +++++++++++++------------------------- 4 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 tests/test_shells/bash.ok create mode 100644 tests/test_shells/input.sh create mode 100644 tests/test_shells/screenrc diff --git a/tests/test_shells/bash.ok b/tests/test_shells/bash.ok new file mode 100644 index 00000000..0576d112 --- /dev/null +++ b/tests/test_shells/bash.ok @@ -0,0 +1,14 @@ + zyx  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" + zyx   BRANCH  ⋯  tests  shell  3rd  cd .git + zyx   BRANCH  ⋯  shell  3rd  .git  cd .. + zyx   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" + zyx  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= + zyx   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +[1] PID + zyx   BRANCH  ⋯  tests  shell  3rd  1  false + zyx   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" + zyx   BRANCH  ⋯  tests  shell  3rd  false + zyx   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +  HOSTNAME  zyx   BRANCH  ⋯  tests  shell  3rd  exit +exit diff --git a/tests/test_shells/input.sh b/tests/test_shells/input.sh new file mode 100644 index 00000000..44e4de9a --- /dev/null +++ b/tests/test_shells/input.sh @@ -0,0 +1,14 @@ +POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +VIRTUAL_ENV= +source powerline/bindings/bash/powerline.sh ; cd tests/shell/3rd +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +false +kill `cat pid` ; sleep 1s +false +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +exit diff --git a/tests/test_shells/screenrc b/tests/test_shells/screenrc new file mode 100644 index 00000000..ad5a1466 --- /dev/null +++ b/tests/test_shells/screenrc @@ -0,0 +1,3 @@ +width 1024 +height 1 +logfile "tests/shell/screen.log" diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 771ebca6..b08f6de7 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -11,55 +11,33 @@ else } fi -get_output() { - OUTPUT="`safe_echo "$INPUT" | LANG=C $@ 2>&1 | sed 's/ \+\x08\+//g' | tail -n +6`" - OUTPUT="`safe_echo "$OUTPUT" | sed -e s/$(cat tests/shell/3rd/pid)/PID/g -e 's/\x1b/\\\\e/g' | python -c 'import socket, sys; hostname=socket.gethostname(); exec ("""for line in sys.stdin:\n sys.stdout.write(line.replace(hostname, "HOSTNAME"))""")'`" - safe_echo "$OUTPUT" +run_test() { + SESNAME="powerline-shell-test-$$" + screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" env LANG=C "$@" + screen -S "$SESNAME" -X readreg a tests/test_shells/input.sh + sleep 5s + screen -S "$SESNAME" -p 0 -X width 300 1 + screen -S "$SESNAME" -p 0 -X logfile tests/shell/screen.log + screen -S "$SESNAME" -p 0 -X paste a + while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do + sleep 1s + done + sed -i -e "1,3 d" \ + -e s/$(cat tests/shell/3rd/pid)/PID/g \ + -e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \ + tests/shell/screen.log + if ! diff -u tests/test_shells/${1}.ok tests/shell/screen.log ; then + return 1 + fi + return 0 } mkdir tests/shell git init tests/shell/3rd git --git-dir=tests/shell/3rd/.git checkout -b BRANCH -INPUT=' -POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" -VIRTUAL_ENV= -COLUMNS=80 -source powerline/bindings/bash/powerline.sh ; cd tests/shell/3rd -POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" -cd .git -cd .. -VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -VIRTUAL_ENV= -bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & -false -kill `cat pid` ; sleep 1s -false -POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -exit -' - -BASH_OUTPUT="`get_output bash --noprofile -i`" - -EXPECTED_BASH_OUTPUT='\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mcd .git -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240m3rd \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m.git \e[0;38;5;240;49;22m \e[0mcd .. -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;74;22m \e[0;38;5;231;48;5;74mⓔ  some-virtual-environment \e[0;38;5;74;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mVIRTUAL_ENV= -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mbash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & -[1] PID -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;49;22m \e[0mfalse -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;166;22m \e[0;38;5;220;48;5;166m1 \e[0;38;5;166;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mkill `cat pid` ; sleep 1s -[1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mfalse -\e[0;38;5;231;48;5;31;1m zyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;48;5;52;22m \e[0;38;5;231;48;5;52m1 \e[0;38;5;52;49;22m \e[0mPOWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -\e[0;38;5;220;48;5;166m  HOSTNAME \e[0;38;5;166;48;5;31;22m \e[0;38;5;231;48;5;31;1mzyx \e[0;38;5;31;48;5;236;22m \e[0;38;5;250;48;5;236m BRANCH \e[0;38;5;236;48;5;240;22m \e[0;38;5;250;48;5;240m⋯ \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mtests \e[0;38;5;245;48;5;240;22m \e[0;38;5;250;48;5;240mshell \e[0;38;5;245;48;5;240;22m \e[0;38;5;252;48;5;240;1m3rd \e[0;38;5;240;49;22m \e[0mexit -exit' -if [ "b$EXPECTED_BASH_OUTPUT" != "b$BASH_OUTPUT" ] ; then - safe_echo "$EXPECTED_BASH_OUTPUT" > tests/shell/expected - safe_echo "$BASH_OUTPUT" > tests/shell/actual - diff -u tests/shell/expected tests/shell/actual - rm tests/shell/expected tests/shell/actual +if ! run_test bash --norc --noprofile -i ; then + echo "Failed bash" FAILED=1 fi rm -r tests/shell From 6c275062703d160991a15328fac318f318d5b465 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 01:07:13 +0400 Subject: [PATCH 12/19] Move tests/test_shells/input.sh to tests/test_shells/input.bash --- tests/test_shells/{input.sh => input.bash} | 0 tests/test_shells/test.sh | 10 +++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) rename tests/test_shells/{input.sh => input.bash} (100%) diff --git a/tests/test_shells/input.sh b/tests/test_shells/input.bash similarity index 100% rename from tests/test_shells/input.sh rename to tests/test_shells/input.bash diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index b08f6de7..52a87a86 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -12,9 +12,11 @@ else fi run_test() { + SH="$1" SESNAME="powerline-shell-test-$$" - screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" env LANG=C "$@" - screen -S "$SESNAME" -X readreg a tests/test_shells/input.sh + screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \ + env LANG=C BINDFILE="$BINDFILE" "$@" + screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH sleep 5s screen -S "$SESNAME" -p 0 -X width 300 1 screen -S "$SESNAME" -p 0 -X logfile tests/shell/screen.log @@ -26,7 +28,7 @@ run_test() { -e s/$(cat tests/shell/3rd/pid)/PID/g \ -e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \ tests/shell/screen.log - if ! diff -u tests/test_shells/${1}.ok tests/shell/screen.log ; then + if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log ; then return 1 fi return 0 @@ -40,5 +42,7 @@ if ! run_test bash --norc --noprofile -i ; then echo "Failed bash" FAILED=1 fi +rm tests/shell/screen.log + rm -r tests/shell exit $FAILED From d9c62d4796c73d8f7bd88c58c24f93b01e6adfd3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 19:47:58 +0400 Subject: [PATCH 13/19] Add zsh functional tests --- tests/install.sh | 1 + tests/test_shells/input.zsh | 14 ++++++++++++++ tests/test_shells/test.sh | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/test_shells/input.zsh diff --git a/tests/install.sh b/tests/install.sh index 138da22a..4172395b 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -9,4 +9,5 @@ if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then pip install unittest2 argparse fi fi +apt-get install zsh true diff --git a/tests/test_shells/input.zsh b/tests/test_shells/input.zsh new file mode 100644 index 00000000..f3506642 --- /dev/null +++ b/tests/test_shells/input.zsh @@ -0,0 +1,14 @@ +unsetopt promptsp transientrprompt +POWERLINE_COMMAND=( $PWD/scripts/powerline -p $PWD/powerline/config_files ) ; VIRTUAL_ENV= +source powerline/bindings/zsh/powerline.zsh ; cd tests/shell/3rd +POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +false +kill `cat pid` ; sleep 1s +false +POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) +exit diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 52a87a86..75ef1752 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -15,7 +15,7 @@ run_test() { SH="$1" SESNAME="powerline-shell-test-$$" screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \ - env LANG=C BINDFILE="$BINDFILE" "$@" + env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "$@" screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH sleep 5s screen -S "$SESNAME" -p 0 -X width 300 1 @@ -44,5 +44,11 @@ if ! run_test bash --norc --noprofile -i ; then fi rm tests/shell/screen.log +if ! run_test zsh -f -i ; then + echo "Failed zsh" + FAILED=1 +fi +rm tests/shell/screen.log + rm -r tests/shell exit $FAILED From b55c5da33683e582eb2a49fee1f08884d3aed168 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 19:48:12 +0400 Subject: [PATCH 14/19] Also install screen --- tests/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/install.sh b/tests/install.sh index 4172395b..0a084d2a 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -9,5 +9,5 @@ if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then pip install unittest2 argparse fi fi -apt-get install zsh +apt-get install zsh screen true From d1793fac61ea2ded98b76a10da563f1a53950b06 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 21:48:09 +0400 Subject: [PATCH 15/19] Run apt-get with sudo and -qq like suggested in travis documentation Documentation though suggests using before_install. Not sure why. --- tests/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/install.sh b/tests/install.sh index 0a084d2a..24ad4a22 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -9,5 +9,5 @@ if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then pip install unittest2 argparse fi fi -apt-get install zsh screen +sudo apt-get install -qq zsh screen true From b16943292b5f7e1af838eb990722194c3998b605 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 22:04:44 +0400 Subject: [PATCH 16/19] Add missing zsh.ok --- tests/test_shells/zsh.ok | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_shells/zsh.ok diff --git a/tests/test_shells/zsh.ok b/tests/test_shells/zsh.ok new file mode 100644 index 00000000..bc3c9e75 --- /dev/null +++ b/tests/test_shells/zsh.ok @@ -0,0 +1,13 @@ +  zyx  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) +  zyx   BRANCH  ⋯  tests  shell  3rd  cd .git +  zyx   BRANCH  ⋯  shell  3rd  .git  cd .. +  zyx   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  zyx  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  zyx   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +[1] PID +  zyx   BRANCH  ⋯  tests  shell  3rd  false +  zyx   BRANCH  ⋯  tests  shell  3rd  1  kill `cat pid` ; sleep 1s +[1] + terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +  zyx   BRANCH  ⋯  tests  shell  3rd  false +  zyx   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) +   HOSTNAME  zyx   BRANCH  ⋯  tests  shell  3rd  exit From 03245f192b93b714e162fe8328235ac64bc01d00 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 22:11:52 +0400 Subject: [PATCH 17/19] Also replace $USER with USER --- tests/test_shells/bash.ok | 22 +++++++++++----------- tests/test_shells/test.sh | 1 + tests/test_shells/zsh.ok | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/test_shells/bash.ok b/tests/test_shells/bash.ok index 0576d112..b644e615 100644 --- a/tests/test_shells/bash.ok +++ b/tests/test_shells/bash.ok @@ -1,14 +1,14 @@ - zyx  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" - zyx   BRANCH  ⋯  tests  shell  3rd  cd .git - zyx   BRANCH  ⋯  shell  3rd  .git  cd .. - zyx   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" - zyx  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= - zyx   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & + USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" + USER   BRANCH  ⋯  tests  shell  3rd  cd .git + USER   BRANCH  ⋯  shell  3rd  .git  cd .. + USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" + USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= + USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & [1] PID - zyx   BRANCH  ⋯  tests  shell  3rd  1  false - zyx   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s + USER   BRANCH  ⋯  tests  shell  3rd  1  false + USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s [1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" - zyx   BRANCH  ⋯  tests  shell  3rd  false - zyx   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -  HOSTNAME  zyx   BRANCH  ⋯  tests  shell  3rd  exit + USER   BRANCH  ⋯  tests  shell  3rd  false + USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  exit exit diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 75ef1752..ca83d864 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -27,6 +27,7 @@ run_test() { sed -i -e "1,3 d" \ -e s/$(cat tests/shell/3rd/pid)/PID/g \ -e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \ + -e "s/$(python -c 'import os, re; print (re.escape(os.environ["USER"]))')/USER/g" \ tests/shell/screen.log if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log ; then return 1 diff --git a/tests/test_shells/zsh.ok b/tests/test_shells/zsh.ok index bc3c9e75..a986ed4d 100644 --- a/tests/test_shells/zsh.ok +++ b/tests/test_shells/zsh.ok @@ -1,13 +1,13 @@ -  zyx  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) -  zyx   BRANCH  ⋯  tests  shell  3rd  cd .git -  zyx   BRANCH  ⋯  shell  3rd  .git  cd .. -  zyx   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  zyx  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  zyx   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +  USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) +  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & [1] PID -  zyx   BRANCH  ⋯  tests  shell  3rd  false -  zyx   BRANCH  ⋯  tests  shell  3rd  1  kill `cat pid` ; sleep 1s +  USER   BRANCH  ⋯  tests  shell  3rd  false +  USER   BRANCH  ⋯  tests  shell  3rd  1  kill `cat pid` ; sleep 1s [1] + terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" -  zyx   BRANCH  ⋯  tests  shell  3rd  false -  zyx   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) -   HOSTNAME  zyx   BRANCH  ⋯  tests  shell  3rd  exit +  USER   BRANCH  ⋯  tests  shell  3rd  false +  USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  exit From 0f0a5e92d35b609fa5630ffd4eb51f67bc01053d Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Jan 2014 22:37:33 +0400 Subject: [PATCH 18/19] Replace sed with python script sed escaping is wrong: e.g. re.escape() will escape `+`, but with BRE escaped plus is quantifier --- tests/test_shells/postproc.py | 32 ++++++++++++++++++++++++++++++++ tests/test_shells/test.sh | 8 ++------ tests/test_shells/zsh.ok | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100755 tests/test_shells/postproc.py diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py new file mode 100755 index 00000000..8cd037d0 --- /dev/null +++ b/tests/test_shells/postproc.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from __future__ import unicode_literals + +import os +import socket +import sys +import codecs + + +fname = sys.argv[1] +new_fname = fname + '.new' +pid_fname = 'tests/shell/3rd/pid' + +with open(pid_fname, 'r') as P: + pid = P.read().strip() +hostname = socket.gethostname() +user = os.environ['USER'] + +with codecs.open(fname, 'r', encoding='utf-8') as R: + with codecs.open(new_fname, 'w', encoding='utf-8') as W: + found_cd = False + for line in R: + if not found_cd: + found_cd = ('cd tests/shell/3rd' in line) + continue + line = line.replace(pid, 'PID') + line = line.replace(hostname, 'HOSTNAME') + line = line.replace(user, 'USER') + W.write(line) + +os.rename(new_fname, fname) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index ca83d864..1459da5e 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -24,12 +24,8 @@ run_test() { while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do sleep 1s done - sed -i -e "1,3 d" \ - -e s/$(cat tests/shell/3rd/pid)/PID/g \ - -e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \ - -e "s/$(python -c 'import os, re; print (re.escape(os.environ["USER"]))')/USER/g" \ - tests/shell/screen.log - if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log ; then + ./tests/test_shells/postproc.py tests/shell/screen.log + if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log | cat -v ; then return 1 fi return 0 diff --git a/tests/test_shells/zsh.ok b/tests/test_shells/zsh.ok index a986ed4d..74d885cf 100644 --- a/tests/test_shells/zsh.ok +++ b/tests/test_shells/zsh.ok @@ -1,3 +1,4 @@ +  USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly )  USER   BRANCH  ⋯  tests  shell  3rd  cd .git  USER   BRANCH  ⋯  shell  3rd  .git  cd .. From 2e713269aee0cf5e3f8d3f2ba2753235bd50ff09 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 14 Jan 2014 00:18:34 +0400 Subject: [PATCH 19/19] Always show hostname (travis is ssh), fix jobnum in zsh --- powerline/bindings/zsh/powerline.zsh | 33 +++++++++++++++------------- tests/test_shells/bash.ok | 20 ++++++++--------- tests/test_shells/input.bash | 4 ++-- tests/test_shells/input.zsh | 7 +++--- tests/test_shells/test.sh | 4 +++- tests/test_shells/zsh.ok | 20 ++++++++--------- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/powerline/bindings/zsh/powerline.zsh b/powerline/bindings/zsh/powerline.zsh index 494160e0..917f5a8b 100644 --- a/powerline/bindings/zsh/powerline.zsh +++ b/powerline/bindings/zsh/powerline.zsh @@ -24,13 +24,28 @@ _powerline_tmux_set_columns() { _powerline_tmux_setenv COLUMNS "$COLUMNS" } -_powerline_install_precmd() { +_powerline_precmd() { + # If you are wondering why I am not using the same code as I use for bash + # ($(jobs|wc -l)): consider the following test: + # echo abc | less + # + # . This way jobs will print + # [1] + done echo abc | + # suspended less -M + # ([ is in first column). You see: any line counting thingie will return + # wrong number of jobs. You need to filter the lines first. Or not use + # jobs built-in at all. + _POWERLINE_JOBNUM=${(%):-%j} +} + +_powerline_setup_prompt() { emulate -L zsh for f in "${precmd_functions[@]}"; do if [[ "$f" = "_powerline_precmd" ]]; then return fi done + precmd_functions+=( _powerline_precmd ) chpwd_functions+=( _powerline_tmux_set_pwd ) if zmodload zsh/zpython &>/dev/null ; then zpython 'from powerline.bindings.zsh import setup as powerline_setup' @@ -38,19 +53,7 @@ _powerline_install_precmd() { zpython 'del powerline_setup' else local add_args='--last_exit_code=$? --last_pipe_status="$pipestatus"' - # If you are wondering why I am not using the same code as I use for - # bash ($(jobs|wc -l)): consider the following test: - # echo abc | less - # - # . This way jobs will print - # [1] + done echo abc | - # suspended less -M - # ([ is in first column). You see: any line counting thingie will return - # wrong number of jobs. You need to filter the lines first. Or not use - # jobs built-in at all. - # - # This and above variants also do not use subshell. - add_args+=' --jobnum=${(%):-%j}' + add_args+=' --jobnum=$_POWERLINE_JOBNUM' PS1='$($POWERLINE_COMMAND shell left -r zsh_prompt '$add_args')' RPS1='$($POWERLINE_COMMAND shell right -r zsh_prompt '$add_args')' fi @@ -62,4 +65,4 @@ _powerline_tmux_set_pwd setopt promptpercent setopt promptsubst -_powerline_install_precmd +_powerline_setup_prompt diff --git a/tests/test_shells/bash.ok b/tests/test_shells/bash.ok index b644e615..123b9fd6 100644 --- a/tests/test_shells/bash.ok +++ b/tests/test_shells/bash.ok @@ -1,14 +1,12 @@ - USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" - USER   BRANCH  ⋯  tests  shell  3rd  cd .git - USER   BRANCH  ⋯  shell  3rd  .git  cd .. - USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" - USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= - USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & [1] PID - USER   BRANCH  ⋯  tests  shell  3rd  1  false - USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s [1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" - USER   BRANCH  ⋯  tests  shell  3rd  false - USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  exit +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  exit exit diff --git a/tests/test_shells/input.bash b/tests/test_shells/input.bash index 44e4de9a..9b97dac0 100644 --- a/tests/test_shells/input.bash +++ b/tests/test_shells/input.bash @@ -1,7 +1,8 @@ POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" VIRTUAL_ENV= source powerline/bindings/bash/powerline.sh ; cd tests/shell/3rd -POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" cd .git cd .. VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" @@ -10,5 +11,4 @@ bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & false kill `cat pid` ; sleep 1s false -POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" exit diff --git a/tests/test_shells/input.zsh b/tests/test_shells/input.zsh index f3506642..a19bdff4 100644 --- a/tests/test_shells/input.zsh +++ b/tests/test_shells/input.zsh @@ -1,7 +1,9 @@ unsetopt promptsp transientrprompt -POWERLINE_COMMAND=( $PWD/scripts/powerline -p $PWD/powerline/config_files ) ; VIRTUAL_ENV= -source powerline/bindings/zsh/powerline.zsh ; cd tests/shell/3rd +POWERLINE_COMMAND=( $PWD/scripts/powerline -p $PWD/powerline/config_files ) +POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) +VIRTUAL_ENV= +source powerline/bindings/zsh/powerline.zsh ; cd tests/shell/3rd cd .git cd .. VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" @@ -10,5 +12,4 @@ bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & false kill `cat pid` ; sleep 1s false -POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) exit diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 1459da5e..e5febb8f 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -17,7 +17,7 @@ run_test() { screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \ env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "$@" screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH - sleep 5s + sleep 0.3s screen -S "$SESNAME" -p 0 -X width 300 1 screen -S "$SESNAME" -p 0 -X logfile tests/shell/screen.log screen -S "$SESNAME" -p 0 -X paste a @@ -39,12 +39,14 @@ if ! run_test bash --norc --noprofile -i ; then echo "Failed bash" FAILED=1 fi +cp tests/shell/screen.log tests/bash.log rm tests/shell/screen.log if ! run_test zsh -f -i ; then echo "Failed zsh" FAILED=1 fi +cp tests/shell/screen.log tests/zsh.log rm tests/shell/screen.log rm -r tests/shell diff --git a/tests/test_shells/zsh.ok b/tests/test_shells/zsh.ok index 74d885cf..2f7256b4 100644 --- a/tests/test_shells/zsh.ok +++ b/tests/test_shells/zsh.ok @@ -1,14 +1,12 @@ -  USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly ) -  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +   HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +   HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & [1] PID -  USER   BRANCH  ⋯  tests  shell  3rd  false -  USER   BRANCH  ⋯  tests  shell  3rd  1  kill `cat pid` ; sleep 1s +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s [1] + terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" -  USER   BRANCH  ⋯  tests  shell  3rd  false -  USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND=( $POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false ) -   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  exit +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  false +   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  exit