summaryrefslogtreecommitdiff
path: root/test/test_hdl_checker_options.vader
blob: 4bee0f55c962df46ca8130328d1d57cfd87117c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Before:
  call ale#assert#SetUpLinterTest('vhdl', 'hdl_checker')

  Save g:ale_hdl_checker_config_file
  Save g:ale_hdl_checker_options

  let g:default_config_file = has('unix') ? '.hdl_checker.config' : '_hdl_checker.config'

After:
  Restore
  call ale#assert#TearDownLinterTest()
  unlet! g:default_config_file

Execute(Get default initialization dict):
  AssertEqual
  \ {'project_file': g:default_config_file},
  \ ale#handlers#hdl_checker#GetInitOptions(bufnr(''))

Execute(Get custom initialization dict):
  let g:ale_hdl_checker_config_file = 'some_file_name'

  AssertEqual
  \ {'project_file': 'some_file_name'},
  \ ale#handlers#hdl_checker#GetInitOptions(bufnr(''))

Execute(Get the checker command without extra user parameters):
  AssertEqual
  \ ale#Escape('hdl_checker') . ' --lsp',
  \ ale#handlers#hdl_checker#GetCommand(bufnr(''))

Execute(Get the checker command with user configured parameters):
  let g:ale_hdl_checker_options = '--log-level DEBUG'

  AssertEqual
  \ ale#Escape('hdl_checker') . ' --lsp --log-level DEBUG',
  \ ale#handlers#hdl_checker#GetCommand(bufnr(''))

Execute(Customize executable):
  let g:ale_hdl_checker_executable = '/some/other/path'
  AssertEqual
  \ ale#Escape('/some/other/path') . ' --lsp',
  \ ale#handlers#hdl_checker#GetCommand(bufnr(''))

Execute(Get project root based on .git):
  call ale#test#SetFilename('hdl_server/with_git/files/foo.vhd')
  " Create .git file
  silent! call mkdir(g:dir . '/hdl_server/with_git/.git')
  AssertNotEqual '', glob(g:dir . '/hdl_server/with_git/.git')

  AssertEqual
  \ ale#path#Simplify(g:dir . '/hdl_server/with_git'),
  \ ale#handlers#hdl_checker#GetProjectRoot(bufnr(''))

Execute(Get project root based on config file):
  call ale#test#SetFilename('hdl_server/with_config_file/foo.vhd')

  AssertEqual
  \ ale#path#Simplify(g:dir . '/hdl_server/with_config_file'),
  \ ale#handlers#hdl_checker#GetProjectRoot(bufnr(''))

Execute(Return no project root if neither .git or config file are found):
  let g:call_count = 0

  " Mock this command to avoid the test to find ale's own .git folder
  function! ale#handlers#hdl_checker#IsDotGit(path) abort
    let g:call_count += 1
    return 0
  endfunction

  call ale#test#SetFilename('hdl_server/foo.vhd')

  AssertEqual
  \ '',
  \ ale#handlers#hdl_checker#GetProjectRoot(bufnr(''))

  AssertEqual g:call_count, 1

  unlet! g:call_count