thinca / vim-themis

A testing framework for Vim script.
zlib License
237 stars 34 forks source link

Vimspec style tests fail in vim9 script #74

Open mmktomato opened 2 years ago

mmktomato commented 2 years ago

Describe the bug

Vimspec style tests fail in vim9 script.

How to reproduce the problem from Vim startup

Create test.vimspec as follows:

vim9script

Describe d
    Context c
        It should pass
            Assert Equals(3, 1 + 2)
        End
    End
End

Then run ./bin/themis test.vimspec.

$ ./bin/themis test.vimspec
Bail out!  Error occurred in script loading.                                                                                                            
# function themis/Runner.load_scripts(files_with_styles, target_bundle) abort dict  Line:11  [ Absolute Line: 130 ]  (~/vimfiles/pack/cui/start/vim-them
is/autoload/themis/runner.vim)                                                                                                                          
# function themis/style['vimspec'].load_script(filename, runner) abort dict  Line:5  [ Absolute Line: 298 ]  (~/vimfiles/pack/cui/start/vim-themis/autol
oad/themis/style/vimspec.vim)                                                                                                                           
# function script()  This function is already deleted.                                                                                                  
#   1:                                                                                                                                                  
# Vim(vim9script):E1039: "vim9script" must be the first command in a script

On the other hand, basic style tests don't fail.

vim9script

var assert = themis#helper('assert')

def MyTest()
    assert.equals(3, 1 + 2)
enddef
$ ./bin/themis test.vim
1..0                                                                                                                                                    

# tests 0                                                                                                                                               
# passes 0 

Expected behavior

I expect vimspec style tests don't fail in vim9 script as well as basic style tests.

Actual behavior

See above.

Your environment

igbanam commented 1 year ago

So… right of the top, methinks this is a translation issue. Since this was built in legacy vimscript, it was built for legacy vimscript.

Digging…

igbanam commented 1 year ago

Digging a bit deeper, my original assumption seems right. Turns out the translation assumes legacy vimscript. If you look at the style/vimspec.vim, you'd realize that the parse_<> functions — s:parse_describe, s:parse_hook s:parse_example and s:parse_end — all assume translations into legacy vimscript.

One solution here is to define a vim9script strategy which could auto-detect on the vim9script keyword and parse accordingly.