Make the test C import path test fail less

This commit is contained in:
w0rp 2018-07-23 22:03:28 +01:00
parent d9579dbbe9
commit 2a861dfd40
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 21 additions and 31 deletions

View File

@ -4,8 +4,11 @@
call ale#Set('c_parse_makefile', 0) call ale#Set('c_parse_makefile', 0)
let s:sep = has('win32') ? '\' : '/' let s:sep = has('win32') ? '\' : '/'
" Set just so tests can override it.
let g:__ale_c_project_filenames = ['.git/HEAD', 'configure', 'Makefile', 'CMakeLists.txt']
function! ale#c#FindProjectRoot(buffer) abort function! ale#c#FindProjectRoot(buffer) abort
for l:project_filename in ['.git/HEAD', 'configure', 'Makefile', 'CMakeLists.txt'] for l:project_filename in g:__ale_c_project_filenames
let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename) let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename)
if !empty(l:full_path) if !empty(l:full_path)

View File

@ -1,8 +1,21 @@
Before: Before:
" Make sure the c.vim file is loaded first.
call ale#c#FindProjectRoot(bufnr(''))
Save g:ale_c_gcc_options Save g:ale_c_gcc_options
Save g:ale_c_clang_options Save g:ale_c_clang_options
Save g:ale_cpp_gcc_options Save g:ale_cpp_gcc_options
Save g:ale_cpp_clang_options Save g:ale_cpp_clang_options
Save g:__ale_c_project_filenames
let g:original_project_filenames = g:__ale_c_project_filenames
" Remove the .git/HEAD dir for C import paths for these tests.
" The tests run inside of a git repo.
let g:__ale_c_project_filenames = filter(
\ copy(g:__ale_c_project_filenames),
\ 'v:val isnot# ''.git/HEAD'''
\)
call ale#test#SetDirectory('/testplugin/test') call ale#test#SetDirectory('/testplugin/test')
@ -14,23 +27,11 @@ Before:
After: After:
Restore Restore
unlet! g:original_project_filenames
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
call ale#linter#Reset() 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): Execute(The C GCC handler should include 'include' directories for projects with a Makefile):
runtime! ale_linters/c/gcc.vim runtime! ale_linters/c/gcc.vim
@ -242,13 +243,8 @@ Execute(The C++ Clang handler should include root directories for projects with
Execute(The C++ Clang handler shoud use the include directory based on the .git location): Execute(The C++ Clang handler shoud use the include directory based on the .git location):
runtime! ale_linters/cpp/clang.vim runtime! ale_linters/cpp/clang.vim
if !isdirectory(g:dir . '/test_c_projects/git_and_nested_makefiles/.git') " Restore the .git/HEAD check for just this test.
call mkdir(g:dir . '/test_c_projects/git_and_nested_makefiles/.git') let g:__ale_c_project_filenames = g:original_project_filenames
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') call ale#test#SetFilename('test_c_projects/git_and_nested_makefiles/src/file.cpp')
@ -270,12 +266,3 @@ Execute(The C++ ClangTidy handler should include json folders for projects with
\ . ' -checks=' . ale#Escape('*') . ' %s ' \ . ' -checks=' . ale#Escape('*') . ' %s '
\ . '-p ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/json_project/build')) \ . '-p ' . ale#Escape(ale#path#Simplify(g:dir . '/test_c_projects/json_project/build'))
\ , ale_linters#cpp#clangtidy#GetCommand(bufnr('')) \ , 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