]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/linter/test_cargo.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / linter / test_cargo.vader
1 Before:
2   call ale#assert#SetUpLinterTest('rust', 'cargo')
3   call ale#test#SetFilename('../test-files/cargo/test.rs')
4
5   let g:cd = 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/cargo')) . ' && '
6   let g:suffix = ' --frozen --message-format=json -q'
7   let g:ale_rust_cargo_avoid_whole_workspace = 0
8
9   " Test with version 0.22.0 by default.
10   GivenCommandOutput ['cargo 0.22.0 (3423351a5 2017-10-06)']
11
12 After:
13   call ale#assert#TearDownLinterTest()
14
15   unlet! g:cd
16   unlet! g:suffix
17
18 Execute(The linter should not be executed when there's no Cargo.toml file):
19   call ale#test#SetFilename('../foo.rs')
20   AssertLinterNotExecuted
21
22 Execute(The linter should be executed when there is a Cargo.toml file):
23   GivenCommandOutput []
24   AssertLinter 'cargo', 'cargo build --frozen --message-format=json -q'
25
26 Execute(`cargo check` should be used when the version is new enough):
27   GivenCommandOutput ['cargo 0.17.0 (3423351a5 2017-10-06)']
28   AssertLinter 'cargo', [
29   \ ale#Escape('cargo') . ' --version',
30   \ 'cargo check' . g:suffix,
31   \]
32
33   " We should cache the version check
34   GivenCommandOutput []
35   AssertLinter 'cargo', ['cargo check' . g:suffix]
36
37 Execute(`cargo build` should be used when cargo is too old):
38   GivenCommandOutput ['cargo 0.16.0 (3423351a5 2017-10-06)']
39   AssertLinter 'cargo', [
40   \ ale#Escape('cargo') . ' --version',
41   \ 'cargo build' . g:suffix,
42   \]
43
44   GivenCommandOutput []
45   AssertLinter 'cargo', ['cargo build' . g:suffix]
46
47 Execute(`cargo build` should be used when g:ale_rust_cargo_use_check is set to 0):
48   let g:ale_rust_cargo_use_check = 0
49
50   GivenCommandOutput ['cargo 0.24.0 (3423351a5 2017-10-06)']
51   AssertLinter 'cargo', [
52   \ ale#Escape('cargo') . ' --version',
53   \ 'cargo build' . g:suffix,
54   \]
55
56   " We should cache the version check
57   GivenCommandOutput []
58   AssertLinter 'cargo', ['cargo build' . g:suffix]
59
60 Execute(`cargo check` should be used when the version is new enough):
61   AssertLinter 'cargo', [
62   \ ale#Escape('cargo') . ' --version',
63   \ 'cargo check' . g:suffix,
64   \]
65
66   " We should cache the version check
67   GivenCommandOutput []
68   AssertLinter 'cargo', ['cargo check' . g:suffix]
69
70 Execute(--all-targets should be used when g:ale_rust_cargo_check_all_targets is set to 1):
71   let g:ale_rust_cargo_check_all_targets = 1
72
73   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --all-targets' . g:suffix]
74   " We should cache the version check
75   AssertLinter 'cargo', ['cargo check --all-targets' . g:suffix]
76
77 Execute(--tests should be used when g:ale_rust_cargo_check_tests is set to 1):
78   let g:ale_rust_cargo_check_tests = 1
79
80   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --tests' . g:suffix]
81
82   " We should cache the version check
83   GivenCommandOutput []
84   AssertLinter 'cargo', ['cargo check --tests' . g:suffix]
85
86 Execute(--examples should be used when g:ale_rust_cargo_check_examples is set to 1):
87   let g:ale_rust_cargo_check_examples = 1
88
89   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --examples' . g:suffix]
90
91   " We should cache the version check
92   GivenCommandOutput []
93   AssertLinter 'cargo', ['cargo check --examples' . g:suffix]
94
95 Execute(--no-default-features should be used when g:ale_rust_cargo_default_feature_behavior is none):
96   let b:ale_rust_cargo_default_feature_behavior = 'none'
97
98   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features']
99
100 Execute(g:ale_rust_cargo_include_features added when g:ale_rust_cargo_default_feature_behavior is none):
101   let b:ale_rust_cargo_default_feature_behavior = 'none'
102   let b:ale_rust_cargo_include_features = 'foo bar'
103
104   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features --features ' . ale#Escape('foo bar')]
105
106 Execute(g:ale_rust_cargo_include_features added and escaped):
107   let b:ale_rust_cargo_default_feature_behavior = 'default'
108   let b:ale_rust_cargo_include_features = "foo bar baz"
109
110   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --features ' . ale#Escape('foo bar baz')]
111
112 Execute(--all-features should be used when g:ale_rust_cargo_default_feature_behavior is all):
113   let b:ale_rust_cargo_default_feature_behavior = 'all'
114   " When all features are enabled we should ignore extra features to add
115   " since it won't do anything
116   let b:ale_rust_cargo_include_features = 'foo bar'
117
118   GivenCommandOutput ['cargo 0.22.0 (3423351a5 2017-10-06)']
119   AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --all-features']
120
121 Execute(Cargo should run from the crate directory when set to avoid the workspace):
122   let g:ale_rust_cargo_avoid_whole_workspace = 1
123   call ale#test#SetFilename('../test-files/cargo/workspace_paths/subpath/test.rs')
124
125   AssertLinterCwd ale#path#Simplify(g:dir . '/../test-files/cargo/workspace_paths/subpath')
126   call ale#semver#ResetVersionCache()
127   AssertLinter 'cargo', [
128   \ ale#Escape('cargo') . ' --version',
129   \ 'cargo check --frozen --message-format=json -q',
130   \]
131
132 Execute(Cargo should not run from the crate directory when not set to avoid the workspace):
133   let g:ale_rust_cargo_avoid_whole_workspace = 0
134   call ale#test#SetFilename('../test-files/cargo/workspace_paths/subpath/test.rs')
135
136   AssertLinterCwd ''
137   call ale#semver#ResetVersionCache()
138   AssertLinter 'cargo', [
139   \ ale#Escape('cargo') . ' --version',
140   \ 'cargo check --frozen --message-format=json -q',
141   \]
142
143 Execute(When ale_rust_cargo_use_clippy is set, cargo-clippy is used as linter):
144   let b:ale_rust_cargo_use_clippy = 1
145
146   AssertLinter 'cargo', [
147   \ ale#Escape('cargo') . ' --version',
148   \ 'cargo clippy --frozen --message-format=json -q',
149   \]
150
151 Execute(When ale_rust_cargo_clippy_options is set, cargo-clippy appends it to commandline):
152   let b:ale_rust_cargo_use_clippy = 1
153   let b:ale_rust_cargo_clippy_options = '-- -D warnings'
154
155   AssertLinter 'cargo', [
156   \ ale#Escape('cargo') . ' --version',
157   \ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
158   \]
159
160 Execute(Clippy options work without prepending --):
161   let b:ale_rust_cargo_use_clippy = 1
162   let b:ale_rust_cargo_clippy_options = '-D warnings'
163
164   AssertLinter 'cargo', [
165   \ ale#Escape('cargo') . ' --version',
166   \ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
167   \]
168
169 Execute(Build supports all cargo flags):
170   let g:ale_rust_cargo_use_check = 0
171   let g:ale_rust_cargo_check_all_targets = 1
172   let g:ale_rust_cargo_check_tests = 1
173   let g:ale_rust_cargo_check_examples = 1
174   let b:ale_rust_cargo_default_feature_behavior = 'all'
175   let b:ale_rust_cargo_target_dir = 'target/ale'
176
177   AssertLinter 'cargo', [
178   \ ale#Escape('cargo') . ' --version',
179   \ 'cargo build --all-targets --examples --tests --target-dir ' . ale#Escape('target/ale') . ' --frozen --message-format=json -q --all-features',
180   \]
181
182 Execute(Clippy supports all cargo flags):
183   let b:ale_rust_cargo_use_clippy = 1
184   let g:ale_rust_cargo_check_all_targets = 1
185   let g:ale_rust_cargo_check_tests = 1
186   let g:ale_rust_cargo_check_examples = 1
187   let b:ale_rust_cargo_default_feature_behavior = 'all'
188   let b:ale_rust_cargo_clippy_options = '-D warnings'
189   let b:ale_rust_cargo_target_dir = 'target/ale'
190
191   AssertLinter 'cargo', [
192   \ ale#Escape('cargo') . ' --version',
193   \ 'cargo clippy --all-targets --examples --tests --target-dir ' . ale#Escape('target/ale') . ' --frozen --message-format=json -q --all-features -- -D warnings',
194   \]
195
196 Execute(cargo-check does not refer ale_rust_cargo_clippy_options):
197   let b:ale_rust_cargo_use_clippy = 0
198   let b:ale_rust_cargo_use_check = 1
199   let b:ale_rust_cargo_clippy_options = '-- -D warnings'
200
201   AssertLinter 'cargo', [
202   \ ale#Escape('cargo') . ' --version',
203   \ 'cargo check --frozen --message-format=json -q',
204   \]
205
206 Execute(`cargo --target-dir` should be used when the version is new enough and it is set):
207   let b:ale_rust_cargo_target_dir = 'target/ale'
208
209   GivenCommandOutput ['cargo 0.17.0 (3423351a5 2017-10-06)']
210   AssertLinter 'cargo', [
211   \ ale#Escape('cargo') . ' --version',
212   \ 'cargo check --target-dir ' . ale#Escape('target/ale') . g:suffix,
213   \]
214
215 Execute(`cargo --target-dir` should not be used when the version is not new enough and it is set):
216   let b:ale_rust_cargo_target_dir = 'target/ale'
217
218   GivenCommandOutput ['cargo 0.16.0 (3423351a5 2017-10-06)']
219   AssertLinter 'cargo', [
220   \ ale#Escape('cargo') . ' --version',
221   \ 'cargo build' . g:suffix,
222   \]