summaryrefslogtreecommitdiff
path: root/test/linter/test_c_cc.vader
blob: ce4bd162e2b34b7603c9191f411151d372970ce0 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Before:
  Save g:ale_c_parse_makefile
  Save g:ale_history_enabled

  let g:ale_c_parse_makefile = 0
  let g:ale_history_enabled = 0

  let g:get_cflags_return_value = ''
  let g:executable_map = {}

  runtime autoload/ale/c.vim
  runtime autoload/ale/engine.vim

  function! ale#engine#IsExecutable(buffer, executable) abort
    return has_key(g:executable_map, a:executable)
  endfunction

  function! ale#c#GetCFlags(buffer, output) abort
    return g:get_cflags_return_value
  endfunction

  call ale#assert#SetUpLinterTest('c', 'cc')

  let b:command_tail = ' -S -x c'
  \   . ' -o ' . (has('win32') ? 'nul': '/dev/null')
  \   . ' -iquote %s:h'
  \   . ' -std=c11 -Wall -'

After:
  unlet! g:get_cflags_return_value
  unlet! g:executable_map
  unlet! b:command_tail

  runtime autoload/ale/c.vim
  runtime autoload/ale/engine.vim

  call ale#assert#TearDownLinterTest()

Execute(clang should be used instead of gcc, if available):
  let g:executable_map = {'clang': 1}

  AssertLinter 'clang', [ale#Escape('clang') . b:command_tail]

Execute(The executable should be configurable):
  AssertLinter 'gcc', [ale#Escape('gcc') . b:command_tail]

  let b:ale_c_cc_executable = 'foobar'

  AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail]

Execute(The -std flag should be replaced by parsed C flags):
  let b:command_tail = substitute(b:command_tail, 'c11', 'c99 ', '')
  let g:get_cflags_return_value = '-std=c99'

  AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail

Execute(gcc should not use -x c-header with header files by default):
  call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')

  AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail

Execute(clang should use -x c-header with header files by default):
  let g:executable_map = {'clang': 1}
  let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')

  call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')

  AssertLinter 'clang', ale#Escape('clang') . b:command_tail

Execute(gcc should use -x c-header with header files if configured to do so):
  let b:ale_c_cc_use_header_lang_flag = 1
  let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')

  call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')

  AssertLinter 'gcc', ale#Escape('gcc') . b:command_tail

Execute(clang should not use -x c-header with header files if configured to do so):
  let g:executable_map = {'clang': 1}
  let b:ale_c_cc_use_header_lang_flag = 0

  call ale#test#SetFilename('../test-files/c/makefile_project/subdir/test.h')

  AssertLinter 'clang', ale#Escape('clang') . b:command_tail

Execute(The header file extensions should be configurable):
  let g:executable_map = {'clang': 1}
  let b:command_tail = substitute(b:command_tail, '-x c', '-x c-header', '')

  call ale#assert#SetUpLinterTest('c', 'cc')
  let b:ale_c_cc_header_exts = ['json']
  call ale#test#SetFilename('../test-files/c/json_project/build/compile_commands.json')

  AssertLinter 'clang', ale#Escape('clang') . b:command_tail