From 903572577ca41e0eb4ca3d1493b18134301469ed Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 6 Nov 2016 20:55:24 +0100 Subject: [PATCH 1/3] Fix tests: mark xfailing ones, add Makefile and Travis --- .travis.yml | 2 ++ Makefile | 6 ++++++ tests/README.md | 7 ++++--- tests/basic_vimrc_for_test_running | 1 + tests/fixtures-detected-correctly.vader | 25 ++++++++++++++++++++----- 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 .travis.yml create mode 100644 Makefile diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0d6dfc4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +sudo: false +script: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..61de8cb --- /dev/null +++ b/Makefile @@ -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" diff --git a/tests/README.md b/tests/README.md index 4fd0cb1..701c660 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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: diff --git a/tests/basic_vimrc_for_test_running b/tests/basic_vimrc_for_test_running index 871fcf2..f7e134b 100644 --- a/tests/basic_vimrc_for_test_running +++ b/tests/basic_vimrc_for_test_running @@ -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 diff --git a/tests/fixtures-detected-correctly.vader b/tests/fixtures-detected-correctly.vader index fff340a..8885c02 100644 --- a/tests/fixtures-detected-correctly.vader +++ b/tests/fixtures-detected-correctly.vader @@ -8,16 +8,22 @@ 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 +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 +Execute (TODO: FountainMusic-FMDisplayItem.c: shiftwidth): + tabnew tests/fixtures/FountainMusic-FMDisplayItem.c + DetectIndent AssertEqual 8, shiftwidth() Execute (FountainMusic-FMDisplayItem.h): @@ -68,20 +74,29 @@ Execute (parslet-scope.rb): AssertEqual 1, &expandtab 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 +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 +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 +Execute (TODO: vared.fish: shiftwidth): + tabnew tests/fixtures/vared.fish + DetectIndent AssertEqual 8, shiftwidth() From 33232eb26b11726ac6c1a8a9d2802d83296d87b8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 6 Nov 2016 21:13:45 +0100 Subject: [PATCH 2/3] Let's not make testing hard: use shiftwidth() wrapper This is also required for the old Vim on Travis! --- tests/_setup.vader | 14 +++++++++++ tests/config-options-are-respected.vader | 16 ++++++------ tests/fixtures-detected-correctly.vader | 32 +++++++++++------------- 3 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 tests/_setup.vader diff --git a/tests/_setup.vader b/tests/_setup.vader new file mode 100644 index 0000000..18fce10 --- /dev/null +++ b/tests/_setup.vader @@ -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 diff --git a/tests/config-options-are-respected.vader b/tests/config-options-are-respected.vader index a753236..911c879 100644 --- a/tests/config-options-are-respected.vader +++ b/tests/config-options-are-respected.vader @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/fixtures-detected-correctly.vader b/tests/fixtures-detected-correctly.vader index 8885c02..aba0aec 100644 --- a/tests/fixtures-detected-correctly.vader +++ b/tests/fixtures-detected-correctly.vader @@ -1,8 +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 - -" 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 @@ -15,7 +11,7 @@ Execute (Coursera-The_Hardware-Software_Interface-lab1-bits.c: expandtab): 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() + AssertEqual 2, Shiftwidth() Execute (FountainMusic-FMDisplayItem.c: expandtab): tabnew tests/fixtures/FountainMusic-FMDisplayItem.c @@ -24,55 +20,55 @@ Execute (FountainMusic-FMDisplayItem.c: expandtab): Execute (TODO: FountainMusic-FMDisplayItem.c: shiftwidth): tabnew tests/fixtures/FountainMusic-FMDisplayItem.c DetectIndent - AssertEqual 8, shiftwidth() + 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 (TODO: semver.md – no indentation at all: expandtab): tabnew tests/fixtures/semver.md @@ -81,7 +77,7 @@ Execute (TODO: semver.md – no indentation at all: expandtab): Execute (TODO: semver.md – no indentation at all: shiftwidth): tabnew tests/fixtures/semver.md DetectIndent - AssertEqual 8, shiftwidth() + AssertEqual 8, Shiftwidth() Execute (starbuzz_beverage_cost_calculator-core.clj: expandtab): tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj @@ -90,7 +86,7 @@ Execute (starbuzz_beverage_cost_calculator-core.clj: expandtab): Execute (TODO: starbuzz_beverage_cost_calculator-core.clj: shiftwidth): tabnew tests/fixtures/starbuzz_beverage_cost_calculator-core.clj DetectIndent - AssertEqual 2, shiftwidth() + AssertEqual 2, Shiftwidth() Execute (vared.fish: expandtab): tabnew tests/fixtures/vared.fish @@ -99,4 +95,4 @@ Execute (vared.fish: expandtab): Execute (TODO: vared.fish: shiftwidth): tabnew tests/fixtures/vared.fish DetectIndent - AssertEqual 8, shiftwidth() + AssertEqual 8, Shiftwidth() From 878f468424c03aef724f7e55b5ae2fcd90f332d4 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 6 Nov 2016 21:24:14 +0100 Subject: [PATCH 3/3] Debug 'check that all four options are changed to a correct value' --- tests/all-options-are-set.vader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/all-options-are-set.vader b/tests/all-options-are-set.vader index 3843a3e..8f3e953 100644 --- a/tests/all-options-are-set.vader +++ b/tests/all-options-are-set.vader @@ -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