test_compiler.vim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. " Test the :compiler command
  2. source check.vim
  3. source shared.vim
  4. func Test_compiler()
  5. CheckExecutable perl
  6. CheckFeature quickfix
  7. let save_LC_ALL = $LC_ALL
  8. let $LC_ALL= "C"
  9. let save_shellslash = &shellslash
  10. " Nvim doesn't allow setting value of a hidden option to non-default value
  11. if exists('+shellslash')
  12. " %:S does not work properly with 'shellslash' set
  13. set noshellslash
  14. endif
  15. e Xfoo.pl
  16. compiler perl
  17. call assert_equal('perl', b:current_compiler)
  18. call assert_fails('let g:current_compiler', 'E121:')
  19. let verbose_efm = execute('verbose set efm')
  20. call assert_match('Last set from .*[/\\]compiler[/\\]perl.vim ', verbose_efm)
  21. call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1'])
  22. w!
  23. call feedkeys(":make\<CR>\<CR>", 'tx')
  24. call assert_fails('clist', 'E42:')
  25. call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1'])
  26. w!
  27. call feedkeys(":make\<CR>\<CR>", 'tx')
  28. let a=execute('clist')
  29. call assert_match('\n \d\+ Xfoo.pl:3: Global symbol "$foo" '
  30. \ . 'requires explicit package name', a)
  31. let &shellslash = save_shellslash
  32. call delete('Xfoo.pl')
  33. bw!
  34. let $LC_ALL = save_LC_ALL
  35. endfunc
  36. func GetCompilerNames()
  37. return glob('$VIMRUNTIME/compiler/*.vim', 0, 1)
  38. \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})
  39. \ ->sort()
  40. endfunc
  41. func Test_compiler_without_arg()
  42. let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
  43. let a = split(execute('compiler'))
  44. let exp = GetCompilerNames()
  45. call assert_match(runtime .. '/compiler/' .. exp[0] .. '.vim$', a[0])
  46. call assert_match(runtime .. '/compiler/' .. exp[1] .. '.vim$', a[1])
  47. call assert_match(runtime .. '/compiler/' .. exp[-1] .. '.vim$', a[-1])
  48. endfunc
  49. func Test_compiler_completion()
  50. let clist = GetCompilerNames()->join(' ')
  51. call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx')
  52. call assert_match('^"compiler ' .. clist .. '$', @:)
  53. call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
  54. call assert_match('"compiler pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
  55. call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
  56. call assert_match('"compiler! pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
  57. endfunc
  58. func Test_compiler_error()
  59. let g:current_compiler = 'abc'
  60. call assert_fails('compiler doesnotexist', 'E666:')
  61. call assert_equal('abc', g:current_compiler)
  62. call assert_fails('compiler! doesnotexist', 'E666:')
  63. unlet! g:current_compiler
  64. endfunc