From 0f0cae5d152e76ed75956c86a8b76618829ec23f Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Wed, 18 Sep 2024 17:03:03 +0700 Subject: [PATCH] Update `vim/sensei.test.vim` --- vim/sensei.test.vim | 172 ++++++++++++++-------------- vim/{run-tests.vim => test/run.vim} | 18 +-- vim/test/watch.sh | 2 +- 3 files changed, 95 insertions(+), 97 deletions(-) rename vim/{run-tests.vim => test/run.vim} (52%) diff --git a/vim/sensei.test.vim b/vim/sensei.test.vim index 40c9a64..770173d 100644 --- a/vim/sensei.test.vim +++ b/vim/sensei.test.vim @@ -21,139 +21,145 @@ function PopulateQuickFixList(name) return filter(getqflist(), 'v:val.valid') endfunction -for name in glob("vim/test/assets/lexical-error.hs.*.errors", v:true, v:true) +function GhcErrorsFor(name) + let foo = glob("vim/test/assets/" . a:name . ".*.errors", v:true, v:true) + call ShouldBe(len(foo), 5) + return foo +endfunction + +for name in GhcErrorsFor("lexical-error.hs") let errors = PopulateQuickFixList(name) - call assert_equal(1, len(errors)) + call ShouldBe(len(errors), 1) let err = errors[0] - call assert_equal("lexical-error.hs", bufname(err.bufnr)) - call assert_equal(1, err.lnum) - call assert_equal(11, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "lexical-error.hs") + call ShouldBe(err.lnum, 1) + call ShouldBe(err.col, 11) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(21231, err.nr) + call ShouldBe(err.nr, 21231) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n lexical error in string/character literal at character '\\n'", err.text) + call ShouldBe(err.text, "\n lexical error in string/character literal at character '\\n'") endfor -for name in glob("vim/test/assets/parse-error.hs.*.errors", v:true, v:true) +for name in GhcErrorsFor("parse-error.hs") let errors = PopulateQuickFixList(name) - call assert_equal(1, len(errors)) + call ShouldBe(len(errors), 1) let err = errors[0] - call assert_equal("parse-error.hs", bufname(err.bufnr)) - call assert_equal(1, err.lnum) - call assert_equal(1, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "parse-error.hs") + call ShouldBe(err.lnum, 1) + call ShouldBe(err.col, 1) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,8]) - call assert_equal(25277, err.nr) + call ShouldBe(err.nr, 25277) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n Parse error: module header, import declaration\n or top-level declaration expected.", err.text) + call ShouldBe(err.text, "\n Parse error: module header, import declaration\n or top-level declaration expected.") endfor -for name in glob("vim/test/assets/type-error.hs.*.errors", v:true, v:true) +for name in GhcErrorsFor("type-error.hs") let errors = PopulateQuickFixList(name) - call assert_equal(1, len(errors)) + call ShouldBe(len(errors), 1) let err = errors[0] - call assert_equal("type-error.hs", bufname(err.bufnr)) - call assert_equal(2, err.lnum) - call assert_equal(7, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "type-error.hs") + call ShouldBe(err.lnum, 2) + call ShouldBe(err.col, 7) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(83865, err.nr) - call assert_equal("\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int", err.text) + call ShouldBe(err.nr, 83865) + call ShouldBe(err.text, "\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int") else - call assert_equal(-1, err.nr) - call assert_equal("\n • Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int\n • In the expression: 23 :: Int\n In an equation for ‘foo’: foo = 23 :: Int", err.text) + call ShouldBe(err.nr, -1) + call ShouldBe(err.text, "\n • Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int\n • In the expression: 23 :: Int\n In an equation for ‘foo’: foo = 23 :: Int") endif endfor -for name in glob("vim/test/assets/suggested-fix.hs.*.errors", v:true, v:true) +for name in GhcErrorsFor("suggested-fix.hs") let errors = PopulateQuickFixList(name) - call assert_equal(2, len(errors)) + call ShouldBe(len(errors), 2) let err = errors[0] - call assert_equal("suggested-fix.hs", bufname(err.bufnr)) - call assert_equal(1, err.lnum) - call assert_equal(1, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "suggested-fix.hs") + call ShouldBe(err.lnum, 1) + call ShouldBe(err.col, 1) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(44432, err.nr) + call ShouldBe(err.nr, 44432) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n The type signature for ‘foo’ lacks an accompanying binding", err.text) + call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding") let err = errors[1] - call assert_equal("suggested-fix.hs", bufname(err.bufnr)) - call assert_equal(4, err.lnum) - call assert_equal(1, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "suggested-fix.hs") + call ShouldBe(err.lnum, 4) + call ShouldBe(err.col, 1) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(44432, err.nr) + call ShouldBe(err.nr, 44432) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n The type signature for ‘bar’ lacks an accompanying binding", err.text) + call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding") endfor -for name in glob("vim/test/assets/suggested-fix-multiline.hs.*.errors", v:true, v:true) +for name in GhcErrorsFor("suggested-fix-multiline.hs") let errors = PopulateQuickFixList(name) - call assert_equal(2, len(errors)) + call ShouldBe(len(errors), 2) let err = errors[0] - call assert_equal("suggested-fix-multiline.hs", bufname(err.bufnr)) - call assert_equal(1, err.lnum) - call assert_equal(1, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs") + call ShouldBe(err.lnum, 1) + call ShouldBe(err.col, 1) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(44432, err.nr) + call ShouldBe(err.nr, 44432) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n The type signature for ‘foo’ lacks an accompanying binding", err.text) + call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding") let err = errors[1] - call assert_equal("suggested-fix-multiline.hs", bufname(err.bufnr)) - call assert_equal(4, err.lnum) - call assert_equal(1, err.col) - call assert_equal(0, err.end_lnum) - call assert_equal(0, err.end_col) - call assert_equal('e', err.type) + call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs") + call ShouldBe(err.lnum, 4) + call ShouldBe(err.col, 1) + call ShouldBe(err.end_lnum, 0) + call ShouldBe(err.end_col, 0) + call ShouldBe(err.type, 'e') if Require(GhcVersion(name), [9,6]) - call assert_equal(44432, err.nr) + call ShouldBe(err.nr, 44432) else - call assert_equal(-1, err.nr) + call ShouldBe(err.nr, -1) endif - call assert_equal("\n The type signature for ‘bar’ lacks an accompanying binding", err.text) + call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding") endfor let errors = PopulateQuickFixList("vim/test/assets/hspec.hs.errors") -call assert_equal(1, len(errors)) +call ShouldBe(len(errors), 1) let err = errors[0] -call assert_equal("vim/test/assets/hspec.hs", bufname(err.bufnr)) -call assert_equal(6, err.lnum) -call assert_equal(11, err.col) -call assert_equal(0, err.end_lnum) -call assert_equal(0, err.end_col) -call assert_equal('', err.type) -call assert_equal(-1, err.nr) -call assert_equal("", err.text) +call ShouldBe(bufname(err.bufnr), "vim/test/assets/hspec.hs") +call ShouldBe(err.lnum, 6) +call ShouldBe(err.col, 11) +call ShouldBe(err.end_lnum, 0) +call ShouldBe(err.end_col, 0) +call ShouldBe(err.type, '') +call ShouldBe(err.nr, -1) +call ShouldBe(err.text, "") diff --git a/vim/run-tests.vim b/vim/test/run.vim similarity index 52% rename from vim/run-tests.vim rename to vim/test/run.vim index e2bd27f..d9204a7 100755 --- a/vim/run-tests.vim +++ b/vim/test/run.vim @@ -9,14 +9,9 @@ highlight green ctermfg=green command -nargs=* FAILURE echohl red | echo | echohl none command -nargs=* SUCCESS echohl green | echo | echohl none -function CheckResults() - if !empty(v:errors) - FAILURE "FAILURES:\n" - for error in v:errors - echo "\n" - FAILURE substitute(substitute(substitute(error, "^command line..script ", "", ""), " Expected ", "\n\nexpected: ", ""), " but got", "\n but got:", "") - endfor - cquit +function ShouldBe(actual, expected) + if !(a:actual ==# a:expected) + throw "expected: " . a:expected . "\n but got: " . a:actual endif endfunction @@ -26,14 +21,11 @@ try execute "source " . name endfor catch - FAILURE substitute(v:throwpoint, "^command line..script ", "", "") + FAILURE substitute(substitute(v:throwpoint, "^command line..script ", "", ""), expand("