/ test / test_prepare_command.vader
test_prepare_command.vader
 1  Before:
 2    Save &shell
 3    Save &shellcmdflag
 4    Save g:ale_shell
 5    Save g:ale_shell_arguments
 6  
 7    Save b:ale_shell
 8    Save b:ale_shell_arguments
 9  
10    unlet! b:ale_shell
11    unlet! b:ale_shell_arguments
12  
13    unlet! g:ale_shell
14    unlet! g:ale_shell_arguments
15  
16  After:
17    Restore
18  
19  Execute(sh should be used when the shell is fish):
20    if !has('win32')
21      " Set something else, so we will replace that too.
22      let &shellcmdflag = '-f'
23      let &shell = 'fish'
24  
25      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
26  
27      let &shell = '/usr/bin/fish'
28  
29      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
30  
31      let &shell = '/usr/local/bin/fish'
32  
33      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
34    endif
35  
36  Execute(sh should be used when the shell is powershell):
37    if !has('win32')
38      " Set something else, so we will replace that too.
39      let &shellcmdflag = '-f'
40      let &shell = 'pwsh'
41  
42      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
43  
44      let &shell = '/usr/bin/pwsh'
45  
46      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
47  
48      let &shell = '/usr/local/bin/pwsh'
49  
50      AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
51    endif
52  
53  Execute(Other shells should be used when set):
54    if !has('win32')
55      let &shell = '/bin/bash'
56      let &shellcmdflag = '-c'
57      let g:ale_shell = &shell
58  
59      AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
60    endif
61  
62  Execute(cmd /s/c as a string should be used on Windows):
63    if has('win32')
64      let &shell = 'who cares'
65      let &shellcmdflag = 'whatever'
66  
67      AssertEqual 'cmd /s/c "foobar"', ale#job#PrepareCommand(bufnr(''), 'foobar')
68    endif
69  
70  Execute(Setting g:ale_shell should cause ale#job#PrepareCommand to use set shell):
71    let g:ale_shell = '/foo/bar'
72  
73    if has('win32')
74      AssertEqual ['/foo/bar', '/c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")
75    else
76      AssertEqual ['/foo/bar', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")
77    endif
78  
79    let g:ale_shell_arguments = '-x'
80  
81    AssertEqual ['/foo/bar', '-x', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")
82  
83  Execute(Setting b:ale_shell should cause ale#job#PrepareCommand to use set shell):
84    let g:ale_shell = '/wrong/foo/bar'
85    let b:ale_shell = '/foo/bar'
86  
87    if has('win32')
88      AssertEqual ['/foo/bar', '/c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")
89    else
90      AssertEqual ['/foo/bar', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")
91    endif
92  
93    let g:ale_shell_arguments = '--verbose -x'
94    let b:ale_shell_arguments = '-x'
95  
96    AssertEqual ['/foo/bar', '-x', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar")