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.
2 call ale#assert#SetUpLinterTest('rust', 'cargo')
3 call ale#test#SetFilename('../test-files/cargo/test.rs')
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
9 " Test with version 0.22.0 by default.
10 GivenCommandOutput ['cargo 0.22.0 (3423351a5 2017-10-06)']
13 call ale#assert#TearDownLinterTest()
18 Execute(The linter should not be executed when there's no Cargo.toml file):
19 call ale#test#SetFilename('../foo.rs')
20 AssertLinterNotExecuted
22 Execute(The linter should be executed when there is a Cargo.toml file):
24 AssertLinter 'cargo', 'cargo build --frozen --message-format=json -q'
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,
33 " We should cache the version check
35 AssertLinter 'cargo', ['cargo check' . g:suffix]
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,
45 AssertLinter 'cargo', ['cargo build' . g:suffix]
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
50 GivenCommandOutput ['cargo 0.24.0 (3423351a5 2017-10-06)']
51 AssertLinter 'cargo', [
52 \ ale#Escape('cargo') . ' --version',
53 \ 'cargo build' . g:suffix,
56 " We should cache the version check
58 AssertLinter 'cargo', ['cargo build' . g:suffix]
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,
66 " We should cache the version check
68 AssertLinter 'cargo', ['cargo check' . g:suffix]
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
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]
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
80 AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --tests' . g:suffix]
82 " We should cache the version check
84 AssertLinter 'cargo', ['cargo check --tests' . g:suffix]
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
89 AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --examples' . g:suffix]
91 " We should cache the version check
93 AssertLinter 'cargo', ['cargo check --examples' . g:suffix]
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'
98 AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features']
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'
104 AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features --features ' . ale#Escape('foo bar')]
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"
110 AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --features ' . ale#Escape('foo bar baz')]
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'
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']
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')
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',
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')
137 call ale#semver#ResetVersionCache()
138 AssertLinter 'cargo', [
139 \ ale#Escape('cargo') . ' --version',
140 \ 'cargo check --frozen --message-format=json -q',
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
146 AssertLinter 'cargo', [
147 \ ale#Escape('cargo') . ' --version',
148 \ 'cargo clippy --frozen --message-format=json -q',
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'
155 AssertLinter 'cargo', [
156 \ ale#Escape('cargo') . ' --version',
157 \ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
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'
164 AssertLinter 'cargo', [
165 \ ale#Escape('cargo') . ' --version',
166 \ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
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'
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',
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'
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',
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'
201 AssertLinter 'cargo', [
202 \ ale#Escape('cargo') . ' --version',
203 \ 'cargo check --frozen --message-format=json -q',
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'
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,
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'
218 GivenCommandOutput ['cargo 0.16.0 (3423351a5 2017-10-06)']
219 AssertLinter 'cargo', [
220 \ ale#Escape('cargo') . ' --version',
221 \ 'cargo build' . g:suffix,