Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: making tests more reliable #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/after/cssbeautify.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.body {
color: red;
color: green;
}
2 changes: 1 addition & 1 deletion test/after/prettydiff.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.body {
color: red;
color: blue;
}

2 changes: 1 addition & 1 deletion test/before/cssbeautify.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.body {
color: red;
color: green;
}
2 changes: 1 addition & 1 deletion test/before/prettydiff.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.body {
color: red;
color: blue;
}
24 changes: 0 additions & 24 deletions test/install.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected]
npm install -g [email protected]
Expand All @@ -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
Expand Down
31 changes: 20 additions & 11 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -59,10 +68,10 @@ 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'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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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

Expand All @@ -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

Expand Down