ale/test/test_c_import_paths.vader

273 lines
10 KiB
Plaintext
Raw Normal View History

Before:
Save g:ale_c_gcc_options
Save g:ale_c_clang_options
Save g:ale_cpp_gcc_options
Save g:ale_cpp_clang_options
call ale#test#SetDirectory('/testplugin/test')
let g:ale_c_gcc_options = ''
let g:ale_c_clang_options = ''
let g:ale_cpp_gcc_options = ''
let g:ale_cpp_clang_options = ''
After:
Restore
call ale#test#RestoreDirectory()
call ale#linter#Reset()
" Run this only once for this series of tests. The cleanup Execute step
" will run at the bottom of this file.
"
" We need to move .git/HEAD away so we don't match it, as we need to test
" functions which look for .git/HEAD.
Execute(Move .git/HEAD to a temp dir):
let g:temp_head_filename = tempname()
let g:head_filename = findfile('.git/HEAD', ';')
if !empty(g:head_filename)
call writefile(readfile(g:head_filename, 'b'), g:temp_head_filename, 'b')
call delete(g:head_filename)
endif
Execute(The C GCC handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/c/gcc.vim
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
\ 'gcc -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
\ . ' -'
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
Execute(The C GCC handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/c/gcc.vim
call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.c')
AssertEqual
\ 'gcc -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/configure_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/configure_project/include') . ' '
\ . ' -'
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
Execute(The C GCC handler should include root directories for projects with .h files in them):
runtime! ale_linters/c/gcc.vim
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
AssertEqual
\ 'gcc -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
\ . ' -'
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
Execute(The C GCC handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/c/gcc.vim
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')
AssertEqual
\ 'gcc -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
\ . ' -'
\ , ale_linters#c#gcc#GetCommand(bufnr(''))
Execute(The C Clang handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/c/clang.vim
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
\ . ' -'
\ , ale_linters#c#clang#GetCommand(bufnr(''))
Execute(The C Clang handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/c/clang.vim
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
AssertEqual
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
\ . ' -'
\ , ale_linters#c#clang#GetCommand(bufnr(''))
Execute(The C Clang handler should include root directories for projects with .h files in them):
runtime! ale_linters/c/clang.vim
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
AssertEqual
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
\ . ' -'
\ , ale_linters#c#clang#GetCommand(bufnr(''))
Execute(The C Clang handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/c/clang.vim
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')
AssertEqual
\ ale#Escape('clang')
\ . ' -S -x c -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
\ . ' -'
\ , ale_linters#c#clang#GetCommand(bufnr(''))
Execute(The C++ GCC handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/cpp/gcc.vim
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')
AssertEqual
\ 'gcc -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
Execute(The C++ GCC handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/cpp/gcc.vim
call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')
AssertEqual
\ 'gcc -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/configure_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/configure_project/include') . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
Execute(The C++ GCC handler should include root directories for projects with .h files in them):
runtime! ale_linters/cpp/gcc.vim
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')
AssertEqual
\ 'gcc -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
Execute(The C++ GCC handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/cpp/gcc.vim
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')
AssertEqual
\ 'gcc -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
\ . ' -'
\ , ale_linters#cpp#gcc#GetCommand(bufnr(''))
Execute(The C++ Clang handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/cpp/clang.vim
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')
AssertEqual
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
Execute(The C++ Clang handler should include 'include' directories for projects with a configure file):
runtime! ale_linters/cpp/clang.vim
call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')
AssertEqual
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/configure_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/configure_project/include') . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
Execute(The C++ Clang handler should include root directories for projects with .h files in them):
runtime! ale_linters/cpp/clang.vim
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')
AssertEqual
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
Execute(The C++ Clang handler should include root directories for projects with .hpp files in them):
runtime! ale_linters/cpp/clang.vim
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')
AssertEqual
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
Execute(The C++ Clang handler shoud use the include directory based on the .git location):
runtime! ale_linters/cpp/clang.vim
if !isdirectory(g:dir . '/test_c_projects/git_and_nested_makefiles/.git')
call mkdir(g:dir . '/test_c_projects/git_and_nested_makefiles/.git')
endif
if !filereadable(g:dir . '/test_c_projects/git_and_nested_makefiles/.git/HEAD')
call writefile([], g:dir . '/test_c_projects/git_and_nested_makefiles/.git/HEAD')
endif
call ale#test#SetFilename('test_c_projects/git_and_nested_makefiles/src/file.cpp')
AssertEqual
\ ale#Escape('clang++')
\ . ' -S -x c++ -fsyntax-only '
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/src') . ' '
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/include') . ' '
\ . ' -'
\ , ale_linters#cpp#clang#GetCommand(bufnr(''))
Execute(The C++ ClangTidy handler should include json folders for projects with suitable build directory in them):
runtime! ale_linters/cpp/clangtidy.vim
call ale#test#SetFilename('test_c_projects/json_project/subdir/file.cpp')
AssertEqual
\ 'clang-tidy -checks=''*'' %s '
\ . '-p ' . ale#Escape(g:dir . '/test_c_projects/json_project/build')
\ , ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
Execute(Move .git/HEAD back):
if !empty(g:head_filename)
call writefile(readfile(g:temp_head_filename, 'b'), g:head_filename, 'b')
call delete(g:temp_head_filename)
endif
unlet! g:temp_head_filename
unlet! g:head_filename