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

covimerage doesn't handle execute "function! ... | ... | endfunction" #73

Closed
tyru opened this issue May 30, 2019 · 4 comments · Fixed by #74
Closed

covimerage doesn't handle execute "function! ... | ... | endfunction" #73

tyru opened this issue May 30, 2019 · 4 comments · Fixed by #74
Labels

Comments

@tyru
Copy link
Contributor

tyru commented May 30, 2019

As of Vim 8.1.0365, Vim shows the places to be defined of functions (Defined: /path/to/src.vim line XXX).
But covimerage can't handle functions created by execute {string}.

Vim script example)

https://github.com/vim-jp/vital.vim/blob/3bf594477df06f006a9de60012e7ae3d75479a14/autoload/vital/__vital__/Web/URI.vim#L640-L644

Workaround

Currently removing Defined: lines from the profile output.
vim-jp/vital.vim#651

cc: @ichizok

@ichizok
Copy link

ichizok commented May 30, 2019

Simple reproducible example

test.vim

execute join([
     \ 'function! Foo()',
     \ '  return 0',
     \ 'endfunction',
     \ ], "\n")
call Foo()
$ vim -es --clean +'profile start prof.log' +'profile file *' +'profile func *' +'so test.vim' +'qa'
$ covimerage write_coverage prof.log
Traceback (most recent call last):
  File "/usr/local/bin/covimerage", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/covimerage/cli.py", line 59, in write_coverage
    m.add_profile_files(*profile_file)
  File "/usr/local/lib/python3.7/site-packages/covimerage/__init__.py", line 91, in add_profile_files
    p.parse()
  File "/usr/local/lib/python3.7/site-packages/covimerage/__init__.py", line 350, in parse
    return self._parse(self._fobj)
  File "/usr/local/lib/python3.7/site-packages/covimerage/__init__.py", line 440, in _parse
    self.map_functions(functions)
  File "/usr/local/lib/python3.7/site-packages/covimerage/__init__.py", line 446, in map_functions
    if self.map_function(f):
  File "/usr/local/lib/python3.7/site-packages/covimerage/__init__.py", line 488, in map_function
    assert 0, 'Script line matches function line.'
AssertionError: Script line matches function line.

prof.log

SCRIPT  /path/to/test.vim
Sourced 1 time
Total time:   0.000099
 Self time:   0.000092

count  total (s)   self (s)
    1              0.000042 execute join([
                                 \ 'function! Foo()',
                                 \ '  return 0',
                                 \ 'endfunction',
                                 \ ], "\n")
    1   0.000039   0.000032 call Foo()

FUNCTION  Foo()
    Defined: /path/to/test.vim line 3
Called 1 time
Total time:   0.000007
 Self time:   0.000007

count  total (s)   self (s)
    1              0.000005   return 0

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   0.000007             Foo()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1              0.000007  Foo()

@blueyed blueyed added the bug label May 30, 2019
@blueyed
Copy link
Member

blueyed commented Jun 1, 2019

Thanks for the detailed report, will look into fixing the crash.

However, isn't the line number wrong to begin with?

Defined: /path/to/test.vim line 3

It should probably be 1, where the execute is.

With the following it will be "defined" at line 3 and line 8:

execute join([
     \ 'function! F_via_execute_1()',
     \ '  return 0',
     \ 'endfunction',
     \ ], "\n")
execute join([
     \ 'function! F_via_execute_2()',
     \ '  " comment',
     \ '  return 0',
     \ 'endfunction',
     \ ], "\n")
call F_via_execute_1()
call F_via_execute_2()

And with the following at lines -1 and 0:

execute "function! F_via_execute_1()\nreturn 0\nendfunction"
execute "function! F_via_execute_2()\nreturn 0\nendfunction"
call F_via_execute_1()
call F_via_execute_2()

Anyway, this is a bug in Vim apparently - do you know how to fix this already maybe? Otherwise we should report it there.

@blueyed
Copy link
Member

blueyed commented Jun 1, 2019

v0.1.6 in the process of being released.

@blueyed
Copy link
Member

blueyed commented Jun 7, 2019

Reported for Vim at vim/vim#4511.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants