From 9513a834e2adfc96046eefea6386a30e2e077ea5 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sun, 27 Aug 2017 13:09:14 -0400 Subject: [PATCH 1/3] WIP: making tests more reliable nvim --> vim Ideally we would have a simple mock formatter and not install any extra dependencies --- test/README.md | 3 ++- test/install.sh | 24 ------------------------ test/test.py | 29 +++++++++++++++++++---------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/test/README.md b/test/README.md index 7d95db76..dea0149f 100644 --- a/test/README.md +++ b/test/README.md @@ -7,7 +7,8 @@ Running tests ./install.sh -python3 -m virtualenv venv +python3 -m venv venv +source ./venv/bin/activate pip install -r requirements.txt pytest -v test.py diff --git a/test/install.sh b/test/install.sh index 9e4083eb..6ac8025f 100755 --- a/test/install.sh +++ b/test/install.sh @@ -1,13 +1,5 @@ #!/usr/bin/env bash -if [[ $OSTYPE == darwin* ]]; then - OS='mac' -elif [[ $OSTYPE == linux-gnu* ]]; then - OS='linux' -else - OS='unknown' -fi - # Formatters npm install -g csscomb@3.1.7 npm install -g prettydiff@99.0.1 @@ -21,22 +13,6 @@ if ! hash vint 2>/dev/null; then pip install vim-vint fi -# Make sure neovim is installed -if ! hash nvim 2>/dev/null; then - echo "installing neovim" - if [[ $OS == 'linux' ]]; then - echo "installing nvim on linux" - sudo add-apt-repository -y ppa:neovim-ppa/unstable - sudo apt-get update - sudo apt-get install -y neovim - elif [[ $OS == 'mac' ]]; then - echo "install nvim on mac" - brew install neovim - fi -else - echo "neovim already installed" -fi - # Vader if [ ! -d "$HOME/.vim/plugged/vader.vim" ]; then git clone https://github.com/junegunn/vader.vim.git ~/.vim/plugged/vader.vim diff --git a/test/test.py b/test/test.py index f5c42eeb..af600e0a 100644 --- a/test/test.py +++ b/test/test.py @@ -2,11 +2,12 @@ import subprocess -from os import listdir +import os from shutil import copyfile + def run_vim_cmd(cmd, filename=''): - cmd = f'nvim -u vimrc -c "set verbose=1 | {cmd} | wq " --headless {filename}' + cmd = f'vim -u vimrc -c "set verbose=1 | {cmd} | wq " {filename}' return run_cmd(cmd) @@ -23,10 +24,18 @@ def test_formatters(): ''' run formatters on entire buffer ''' - for filename in listdir('before'): + + files = os.listdir('before') + + ignored = set(['.mypy_cache']) + + filtered_files = (f for f in files if f not in ignored) + + for filename in filtered_files: + assert filename != '.mypy_cache' output_file = '/tmp/neoformat_' + filename formatter = filename.split('.')[0] - cmd = f'nvim -u vimrc -c "set verbose=1 | Neoformat {formatter} | w! {output_file} | q! " --headless ./before/{filename}' + cmd = f'vim -u vimrc -c "set verbose=1 | Neoformat {formatter} | w! {output_file} | q! " ./before/{filename}' run_cmd(cmd) before = readlines(output_file) after = readlines('./after/' + filename) @@ -45,7 +54,7 @@ def test_visual_selection_multi_filetype(): (filetype, start_line, end_line) = test print(start_line) vim_cmd = f'{start_line},{end_line}Neoformat! {filetype}' - cmd = f'nvim -u vimrc -c "set verbose=1 | {vim_cmd} | wq " --headless {output_file}' + cmd = f'vim -u vimrc -c "set verbose=1 | {vim_cmd} | wq " {output_file}' run_cmd(cmd) before = readlines(output_file) @@ -62,7 +71,7 @@ def test_visual_selection_with_filetype_and_formatter(): for filename in listdir(dir_before): (filetype, formatter, start_line, end_line) = filename.split('_') output_file = '/tmp/neoformat_' + filename - cmd = f'nvim -u vimrc -c "set verbose=1 | {start_line},{end_line}Neoformat! {filetype} {formatter} | w! {output_file} | q! " --headless {dir_before + filename}' + cmd = f'vim -u vimrc -c "set verbose=1 | {start_line},{end_line}Neoformat! {filetype} {formatter} | w! {output_file} | q! " {dir_before + filename}' run_cmd(cmd) before = readlines(output_file) after = readlines(dir_after + filename) @@ -81,7 +90,7 @@ def test_formatprg_with_neoformat(): let &formatprg = 'css-beautify -s 6 -n' let g:neoformat_try_formatprg = 1 ''' - cmd = f'nvim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " --headless {dir_before + filename}' + cmd = f'vim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " {dir_before + filename}' run_cmd(cmd) before = readlines(output_file) after = readlines('./after/cssbeautify-indent-6.css') @@ -99,7 +108,7 @@ def test_formatprg_without_enable(): viml = ''' let &formatprg = 'css-beautify -s 6 -n' ''' - cmd = f'nvim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " --headless {dir_before + filename}' + cmd = f'vim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " {dir_before + filename}' run_cmd(cmd) before = readlines(output_file) after = readlines('./after/cssbeautify.css') @@ -110,7 +119,7 @@ def test_vader(): ''' run *.vader tests ''' - cmd = f'nvim -u vimrc -c "Vader! *.vader" --headless' + cmd = f'vim -u vimrc -c "Vader! *.vader" ' exit_code = run_cmd(cmd) assert exit_code == 0 @@ -119,7 +128,7 @@ def test_autocompletion(): ''' run the vim autocompletion tests ''' - cmd = f'nvim -u vimrc -c "source autocomplete_test.vim" --headless' + cmd = f'vim -u vimrc -c "source autocomplete_test.vim" ' exit_code = run_cmd(cmd) assert exit_code == 0 From 772e429cc1ba56c0f4407d86cac95594d53f315c Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sun, 27 Aug 2017 13:20:42 -0400 Subject: [PATCH 2/3] Fix: typo listdir --> os.listdir --- test/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.py b/test/test.py index af600e0a..47141fd3 100644 --- a/test/test.py +++ b/test/test.py @@ -68,7 +68,7 @@ def test_visual_selection_with_filetype_and_formatter(): ''' dir_before = 'visual_before/' dir_after = 'visual_after/' - for filename in listdir(dir_before): + for filename in os.listdir(dir_before): (filetype, formatter, start_line, end_line) = filename.split('_') output_file = '/tmp/neoformat_' + filename cmd = f'vim -u vimrc -c "set verbose=1 | {start_line},{end_line}Neoformat! {filetype} {formatter} | w! {output_file} | q! " {dir_before + filename}' From d57e05d5d2f5a468b8cf755500d83540fd9cffbd Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sun, 27 Aug 2017 13:39:37 -0400 Subject: [PATCH 3/3] Update: css to have different files --- test/after/cssbeautify.css | 2 +- test/after/prettydiff.css | 2 +- test/before/cssbeautify.css | 2 +- test/before/prettydiff.css | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/after/cssbeautify.css b/test/after/cssbeautify.css index b4197b16..c7a2c2e2 100644 --- a/test/after/cssbeautify.css +++ b/test/after/cssbeautify.css @@ -1,3 +1,3 @@ .body { - color: red; + color: green; } diff --git a/test/after/prettydiff.css b/test/after/prettydiff.css index f44498d3..295f92d4 100644 --- a/test/after/prettydiff.css +++ b/test/after/prettydiff.css @@ -1,4 +1,4 @@ .body { - color: red; + color: blue; } diff --git a/test/before/cssbeautify.css b/test/before/cssbeautify.css index 68748307..8fdcc720 100644 --- a/test/before/cssbeautify.css +++ b/test/before/cssbeautify.css @@ -1,3 +1,3 @@ .body { -color: red; +color: green; } diff --git a/test/before/prettydiff.css b/test/before/prettydiff.css index 68748307..5b840651 100644 --- a/test/before/prettydiff.css +++ b/test/before/prettydiff.css @@ -1,3 +1,3 @@ .body { -color: red; +color: blue; }