Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
- added vader tests
- made test.sh install necessary dependencies, i.e. neovim & vader
- added custom autcomplete_test, since vader did not work
  • Loading branch information
sbdchd committed May 25, 2016
1 parent c12472f commit a681743
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/$VADER_OUTPUT_FILE
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ install:
- sudo pip install vim-vint

script:
- bash test/test.sh;
- bash test/test.sh
4 changes: 2 additions & 2 deletions autoload/neoformat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function! neoformat#Neoformat(user_formatter) abort
else
let formatters = s:get_enabled_formatters(&filetype)
if formatters == []
call neoformat#utils#msg('no formatter defined for the ' . &filetype . ' filetype')
call neoformat#utils#msg('formatter not defined for ' . &filetype . ' filetype')
return neoformat#format#BasicFormat()
endif

Expand All @@ -27,7 +27,7 @@ function! neoformat#Neoformat(user_formatter) abort
elseif exists('g:neoformat#' . &filetype . '#' . formatter)
let definition = g:neoformat#{&filetype}#{formatter}
else
call neoformat#utils#log('no definition found for formatter: ' . formatter)
call neoformat#utils#log('definition not found for formatter: ' . formatter)
if !empty(a:user_formatter)
call neoformat#utils#msg('formatter definition for ' . a:user_formatter . ' not found')
return neoformat#format#BasicFormat()
Expand Down
64 changes: 64 additions & 0 deletions test/autocomplete_test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let s:tests = {}
" Utilities
function! s:Run(function)
let o = &filetype
" let output = call(a:function, [''])
" call function(a:function)
let output = call(a:function, [])
let &filetype = o
" expecting output to either be a 1 or 0
let s:tests[a:function[2:]] = output
return output
endfunction

function! s:Cleanup()
let error = 0
for test in keys(s:tests)
if !s:tests[test]
let error = 1
endif
echom test . ' : ' . s:tests[test]
endfor

if error
" make vim exit with a non-zero value
cquit!
else
qall!
endif
endfunction

" Test Definitions
function! s:valid_option()
let &filetype = 'python'

let g:neoformat_python_enabled = ['autopep8', 'yapf']
let out = neoformat#CompleteFormatters('auto','', 0)

return ['autopep8'] == out
endfunction

function! s:invalid_option()
let &filetype = 'javascript'

let g:neoformat_python_enabled = ['autopep8']
let out = neoformat#CompleteFormatters('autopep8', '', 0)

return [] == out
endfunction

function! s:multi_options()
let &filetype = 'python'
let g:neoformat_python_enabled = ['autopep8', 'yapf']
let out = neoformat#CompleteFormatters('autopep8', '', 0)

return [] == out
endfunction

" Run Tests
call s:Run('s:valid_option')
call s:Run('s:invalid_option')


" Check the outputs
call s:Cleanup()
43 changes: 43 additions & 0 deletions test/neoformat.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Before:
function! g:CmdOutput(cmd)
redir => out
silent exe a:cmd
redir END
return out[1:]
endfunction

Execute (empty filetype):
let &filetype = ''
let out = g:CmdOutput('Neoformat')
AssertEqual 'Neoformat: formatter not defined for filetype', out

Execute (filetype without defined formatter):
let &filetype = 'not_real_filetype'
let out = g:CmdOutput('Neoformat')

AssertEqual 'Neoformat: formatter not defined for ' . &filetype . ' filetype', out

Execute (formatter defined for other filetype, but is called via user cmd):
let &filetype = 'javascript'
let out = g:CmdOutput('Neoformat autopep8')

AssertEqual 'Neoformat: formatter definition for autopep8 not found', out

Execute (user disabled all formatters for current (python) filetype):
let g:neoformat_enabled_python= []
let &filetype = 'python'
let out = g:CmdOutput('Neoformat')

AssertEqual 'Neoformat: formatter not defined for ' . &filetype . ' filetype', out

Execute (user disabled all formatters for current (python) filetype):
let g:neoformat_enabled_python= ['not_real_formatter']
let &filetype = 'python'
let out = g:CmdOutput('Neoformat')

AssertEqual 'Neoformat: attempted all formatters available for current filetype', out

Execute (invalid user cmd: formatter not defined):
let out = g:CmdOutput('Neoformat not_a_real_formatter')

AssertEqual 'Neoformat: formatter definition for not_a_real_formatter not found', out
32 changes: 31 additions & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
#!/usr/bin/env bash

if [[ $OSTYPE == darwin* ]]; then
OS='mac'
elif [[ $OSTYPE == linux-gnu* ]]; then
OS='linux'
else
OS='unknown'
fi

# Vint
if ! hash vint 2>/dev/null; then
pip install vint
fi

vint .

# Vader
if [ ! -d "$HOME/.vim/plugged/vader.vim" ]; then
git clone https://github.com/junegunn/vader.vim.git ~/.vim/plugged/vader.vim
fi

# Make sure neovim is installed
if ! hash nvim 2>/dev/null; then
if [[ $OS == 'linux' ]]; then
sudo add-apt-repository -y ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install -y neovim
elif [[ $OS == 'mac' ]]; then
brew install neovim
fi
fi

# Run Vader Tests
cd "$( dirname "${BASH_SOURCE[0]}" )" && nvim -u vimrc -c 'Vader! *.vader' > /dev/null

# Run Autocomplete Tests
nvim -u vimrc -c 'source autocomplete_test.vim' > /dev/null
26 changes: 26 additions & 0 deletions test/utils.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Before:
function! g:CmdOutput(cmd)
redir => out
silent exe 'call ' . a:cmd
redir END
return out[1:]
endfunction

Execute (test log util):
let g:neoformat_verbose = 1
let out = g:CmdOutput('neoformat#utils#log("test")')

let g:neoformat_verbose = 0
AssertEqual 'Neoformat: test', out

Execute (test msg util):
let g:neoformat_verbose = 0
let out = g:CmdOutput('neoformat#utils#msg("test")')

AssertEqual 'Neoformat: test', out

Execute (test warn util):
let g:neoformat_verbose = 0
let out = g:CmdOutput('neoformat#utils#warn("test")')

AssertEqual 'Neoformat: test', out
6 changes: 6 additions & 0 deletions test/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
filetype off
set runtimepath+=$HOME/.vim/plugged/vader.vim
set runtimepath+=../
filetype plugin indent on
syntax enable
set nocompatible

0 comments on commit a681743

Please sign in to comment.