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

Fix tests: mark xfailing ones, add Makefile and Travis #15

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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo: false
script: make test
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/vader.vim:
mkdir -p $(dir $@)
git clone --depth=1 https://github.com/junegunn/vader.vim $@

test: build/vader.vim
vim -u tests/basic_vimrc_for_test_running -c "Vader! tests/*.vader"
7 changes: 4 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ This folder, `tests`, contains the executable tests for DetectIndent.

## Running the tests

As a prerequisite, the [Vader](https://github.com/junegunn/vader.vim) testing plugin must be installed.
You can execute `make test` in the plugin folder (*not* this `tests` folder).

To run the tests, `cd` so your working is the root folder `detectindent`, *not* this `tests` folder. Then run the following:
$ make test

$ tests/run-all-tests
This will install [Vader](https://github.com/junegunn/vader.vim) automatically,
and then runs the test.

You should see output like the following:

Expand Down
14 changes: 14 additions & 0 deletions tests/_setup.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Execute (Setup):
" so it is clear what values later tests are working with
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8

if exists('*shiftwidth')
function! Shiftwidth()
return shiftwidth()
endfunction
else
Log "WARNING: shiftwidth() not available!"
function! Shiftwidth()
return &shiftwidth
endfunction
endif
4 changes: 2 additions & 2 deletions tests/all-options-are-set.vader
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Execute (check that all four options are changed to a correct value):
AssertEqual 1, &expandtab
AssertEqual 2, &tabstop
" the values of 'sts' and 'sw' can be different depending on the values that this version of Vim supports
Assert &softtabstop == -1 || &softtabstop == 2, "softtabstop was not set correctly"
Assert &shiftwidth == 0 || &shiftwidth == 2, "shiftwidth was not set correctly"
Assert &softtabstop == -1 || &softtabstop == 2, "softtabstop was not set correctly: ".&sts
Assert &shiftwidth == 0 || &shiftwidth == 2, "shiftwidth was not set correctly: ".&sw
bdelete
1 change: 1 addition & 0 deletions tests/basic_vimrc_for_test_running
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vader.vim
set rtp+=build/vader.vim
set rtp+=.
set rtp+=./after
filetype plugin indent on
Expand Down
16 changes: 7 additions & 9 deletions tests/config-options-are-respected.vader
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Execute (reset indent options to initial values):
" so it is clear what values later tests are working with
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8
Include: _setup.vader

Execute (g:detectindent_preferred_indent is respected):
let g:detectindent_preferred_indent = 4
Expand All @@ -9,7 +7,7 @@ Execute (g:detectindent_preferred_indent is respected):
" expect no change in expandtab
AssertEqual 0, &expandtab
" shiftwidth is 8 without the option; expect a difference
AssertEqual 4, shiftwidth()
AssertEqual 4, Shiftwidth()
bdelete
unlet g:detectindent_preferred_indent

Expand All @@ -20,7 +18,7 @@ Execute (g:detectindent_min_indent is respected for space indentation):
" expect no change in expandtab
AssertEqual 1, &expandtab
" shiftwidth is 2 without the option; expect a difference
AssertEqual 4, shiftwidth()
AssertEqual 4, Shiftwidth()
bdelete
unlet g:detectindent_min_indent

Expand All @@ -31,7 +29,7 @@ Execute (g:detectindent_max_indent is respected for space indentation):
" expect no change in expandtab
AssertEqual 1, &expandtab
" shiftwidth is 2 without the option; expect a difference
AssertEqual 1, shiftwidth()
AssertEqual 1, Shiftwidth()
bdelete
unlet g:detectindent_max_indent

Expand All @@ -42,7 +40,7 @@ Execute (g:detectindent_max_indent is respected for mixed-space-and-tab indentat
" expect no change in expandtab
AssertEqual 0, &expandtab
" shiftwidth should be 8 (though is currently 40) without the option; expect a difference
AssertEqual 6, shiftwidth()
AssertEqual 6, Shiftwidth()
bdelete
unlet g:detectindent_max_indent

Expand All @@ -57,7 +55,7 @@ Execute (g:detectindent_max_indent is ignored in favor of global options for pur
" expect no change in expandtab
AssertEqual 0, &expandtab
" expect no change in shiftwidth
AssertEqual 8, shiftwidth()
AssertEqual 8, Shiftwidth()
bdelete
unlet g:detectindent_max_indent

Expand All @@ -69,7 +67,7 @@ Execute (g:detect_min_indent and max_indent, when combined, override too-low det
tabnew tests/fixtures/jSnake-demo.html
DetectIndent
" shiftwidth is 2 without the two options; expect min_indent to be the deciding factor
AssertEqual 3, shiftwidth()
AssertEqual 3, Shiftwidth()
unlet g:detectindent_min_indent
unlet g:detectindent_max_indent
bdelete
57 changes: 34 additions & 23 deletions tests/fixtures-detected-correctly.vader
Original file line number Diff line number Diff line change
@@ -1,87 +1,98 @@
Execute (reset indent options to initial values):
" so it is clear what values later tests are working with
setglobal noexpandtab tabstop=8 softtabstop=0 shiftwidth=8

" Compatibility warning: these tests inspect `shiftwidth()`. If you get errors because your Vim is too old to have `shiftwidth()`, replace them locally with `&shiftwidth`. I use `shiftwidth()` instead of `&shiftwidth` to support possible future usage of the 0 value for 'shiftwidth', and to make the writers of language indent plugins aware of the need to migrate from checking `&sw` to checking `shiftwidth()`.
Include: _setup.vader

After:
" close the file that was just tested and its tab, and forget about it
bdelete

Execute (Coursera-The_Hardware-Software_Interface-lab1-bits.c):
Execute (Coursera-The_Hardware-Software_Interface-lab1-bits.c: expandtab):
tabnew tests/fixtures/Coursera-The_Hardware-Software_Interface-lab1-bits.c
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
Execute (TODO: Coursera-The_Hardware-Software_Interface-lab1-bits.c: shiftwidth):
tabnew tests/fixtures/Coursera-The_Hardware-Software_Interface-lab1-bits.c
DetectIndent
AssertEqual 2, Shiftwidth()

Execute (FountainMusic-FMDisplayItem.c):
Execute (FountainMusic-FMDisplayItem.c: expandtab):
tabnew tests/fixtures/FountainMusic-FMDisplayItem.c
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 8, shiftwidth()
Execute (TODO: FountainMusic-FMDisplayItem.c: shiftwidth):
tabnew tests/fixtures/FountainMusic-FMDisplayItem.c
DetectIndent
AssertEqual 8, Shiftwidth()

Execute (FountainMusic-FMDisplayItem.h):
tabnew tests/fixtures/FountainMusic-FMDisplayItem.h
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 8, shiftwidth()
AssertEqual 8, Shiftwidth()

Execute (GameOfLife.plaid – badly mixed indentation):
tabnew tests/fixtures/GameOfLife.plaid
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (general-level-1.indentc):
tabnew tests/fixtures/general-level-1.indentc
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 8, shiftwidth()
AssertEqual 8, Shiftwidth()

Execute (haml-action_view.haml):
tabnew tests/fixtures/haml-action_view.haml
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (haml-render_layout.haml):
tabnew tests/fixtures/haml-render_layout.haml
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (jSnake-demo.html):
tabnew tests/fixtures/jSnake-demo.html
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (jSnake-snake3.js):
tabnew tests/fixtures/jSnake-snake3.js
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (parslet-scope.rb):
tabnew tests/fixtures/parslet-scope.rb
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
AssertEqual 2, Shiftwidth()

Execute (semver.md – no indentation at all):
Execute (TODO: semver.md – no indentation at all: expandtab):
tabnew tests/fixtures/semver.md
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 8, shiftwidth()
Execute (TODO: semver.md – no indentation at all: shiftwidth):
tabnew tests/fixtures/semver.md
DetectIndent
AssertEqual 8, Shiftwidth()

Execute (starbuzz_beverage_cost_calculator-core.clj):
Execute (starbuzz_beverage_cost_calculator-core.clj: expandtab):
tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj
DetectIndent
AssertEqual 1, &expandtab
AssertEqual 2, shiftwidth()
Execute (TODO: starbuzz_beverage_cost_calculator-core.clj: shiftwidth):
tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj
DetectIndent
AssertEqual 2, Shiftwidth()

Execute (vared.fish):
Execute (vared.fish: expandtab):
tabnew tests/fixtures/vared.fish
DetectIndent
AssertEqual 0, &expandtab
AssertEqual 8, shiftwidth()
Execute (TODO: vared.fish: shiftwidth):
tabnew tests/fixtures/vared.fish
DetectIndent
AssertEqual 8, Shiftwidth()