aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/test/utils/diagnotics/rust.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/test/utils/diagnotics/rust.test.ts')
-rw-r--r--editors/code/src/test/utils/diagnotics/rust.test.ts92
1 files changed, 64 insertions, 28 deletions
diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts
index 327d15046..358325cc8 100644
--- a/editors/code/src/test/utils/diagnotics/rust.test.ts
+++ b/editors/code/src/test/utils/diagnotics/rust.test.ts
@@ -6,14 +6,14 @@ import {
6 MappedRustDiagnostic, 6 MappedRustDiagnostic,
7 mapRustDiagnosticToVsCode, 7 mapRustDiagnosticToVsCode,
8 RustDiagnostic, 8 RustDiagnostic,
9 SuggestionApplicability 9 SuggestionApplicability,
10} from '../../../utils/diagnostics/rust'; 10} from '../../../utils/diagnostics/rust';
11 11
12function loadDiagnosticFixture(name: string): RustDiagnostic { 12function loadDiagnosticFixture(name: string): RustDiagnostic {
13 const jsonText = fs 13 const jsonText = fs
14 .readFileSync( 14 .readFileSync(
15 // We're actually in our JavaScript output directory, climb out 15 // We're actually in our JavaScript output directory, climb out
16 `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json` 16 `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json`,
17 ) 17 )
18 .toString(); 18 .toString();
19 19
@@ -33,12 +33,12 @@ function mapFixtureToVsCode(name: string): MappedRustDiagnostic {
33describe('mapRustDiagnosticToVsCode', () => { 33describe('mapRustDiagnosticToVsCode', () => {
34 it('should map an incompatible type for trait error', () => { 34 it('should map an incompatible type for trait error', () => {
35 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 35 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
36 'error/E0053' 36 'error/E0053',
37 ); 37 );
38 38
39 assert.strictEqual( 39 assert.strictEqual(
40 diagnostic.severity, 40 diagnostic.severity,
41 vscode.DiagnosticSeverity.Error 41 vscode.DiagnosticSeverity.Error,
42 ); 42 );
43 assert.strictEqual(diagnostic.source, 'rustc'); 43 assert.strictEqual(diagnostic.source, 'rustc');
44 assert.strictEqual( 44 assert.strictEqual(
@@ -46,8 +46,8 @@ describe('mapRustDiagnosticToVsCode', () => {
46 [ 46 [
47 `method \`next\` has an incompatible type for trait`, 47 `method \`next\` has an incompatible type for trait`,
48 `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``, 48 `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``,
49 ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\`` 49 ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\``,
50 ].join('\n') 50 ].join('\n'),
51 ); 51 );
52 assert.strictEqual(diagnostic.code, 'E0053'); 52 assert.strictEqual(diagnostic.code, 'E0053');
53 assert.deepStrictEqual(diagnostic.tags, []); 53 assert.deepStrictEqual(diagnostic.tags, []);
@@ -61,24 +61,24 @@ describe('mapRustDiagnosticToVsCode', () => {
61 61
62 it('should map an unused variable warning', () => { 62 it('should map an unused variable warning', () => {
63 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 63 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
64 'warning/unused_variables' 64 'warning/unused_variables',
65 ); 65 );
66 66
67 assert.strictEqual( 67 assert.strictEqual(
68 diagnostic.severity, 68 diagnostic.severity,
69 vscode.DiagnosticSeverity.Warning 69 vscode.DiagnosticSeverity.Warning,
70 ); 70 );
71 assert.strictEqual( 71 assert.strictEqual(
72 diagnostic.message, 72 diagnostic.message,
73 [ 73 [
74 'unused variable: `foo`', 74 'unused variable: `foo`',
75 '#[warn(unused_variables)] on by default' 75 '#[warn(unused_variables)] on by default',
76 ].join('\n') 76 ].join('\n'),
77 ); 77 );
78 assert.strictEqual(diagnostic.code, 'unused_variables'); 78 assert.strictEqual(diagnostic.code, 'unused_variables');
79 assert.strictEqual(diagnostic.source, 'rustc'); 79 assert.strictEqual(diagnostic.source, 'rustc');
80 assert.deepStrictEqual(diagnostic.tags, [ 80 assert.deepStrictEqual(diagnostic.tags, [
81 vscode.DiagnosticTag.Unnecessary 81 vscode.DiagnosticTag.Unnecessary,
82 ]); 82 ]);
83 83
84 // No related information 84 // No related information
@@ -89,29 +89,29 @@ describe('mapRustDiagnosticToVsCode', () => {
89 const [suggestedFix] = suggestedFixes; 89 const [suggestedFix] = suggestedFixes;
90 assert.strictEqual( 90 assert.strictEqual(
91 suggestedFix.title, 91 suggestedFix.title,
92 'consider prefixing with an underscore: `_foo`' 92 'consider prefixing with an underscore: `_foo`',
93 ); 93 );
94 assert.strictEqual( 94 assert.strictEqual(
95 suggestedFix.applicability, 95 suggestedFix.applicability,
96 SuggestionApplicability.MachineApplicable 96 SuggestionApplicability.MachineApplicable,
97 ); 97 );
98 }); 98 });
99 99
100 it('should map a wrong number of parameters error', () => { 100 it('should map a wrong number of parameters error', () => {
101 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 101 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
102 'error/E0061' 102 'error/E0061',
103 ); 103 );
104 104
105 assert.strictEqual( 105 assert.strictEqual(
106 diagnostic.severity, 106 diagnostic.severity,
107 vscode.DiagnosticSeverity.Error 107 vscode.DiagnosticSeverity.Error,
108 ); 108 );
109 assert.strictEqual( 109 assert.strictEqual(
110 diagnostic.message, 110 diagnostic.message,
111 [ 111 [
112 'this function takes 2 parameters but 3 parameters were supplied', 112 'this function takes 2 parameters but 3 parameters were supplied',
113 'expected 2 parameters' 113 'expected 2 parameters',
114 ].join('\n') 114 ].join('\n'),
115 ); 115 );
116 assert.strictEqual(diagnostic.code, 'E0061'); 116 assert.strictEqual(diagnostic.code, 'E0061');
117 assert.strictEqual(diagnostic.source, 'rustc'); 117 assert.strictEqual(diagnostic.source, 'rustc');
@@ -120,7 +120,8 @@ describe('mapRustDiagnosticToVsCode', () => {
120 // One related information for the original definition 120 // One related information for the original definition
121 const relatedInformation = diagnostic.relatedInformation; 121 const relatedInformation = diagnostic.relatedInformation;
122 if (!relatedInformation) { 122 if (!relatedInformation) {
123 return assert.fail('Related information unexpectedly undefined'); 123 assert.fail('Related information unexpectedly undefined');
124 return;
124 } 125 }
125 assert.strictEqual(relatedInformation.length, 1); 126 assert.strictEqual(relatedInformation.length, 1);
126 const [related] = relatedInformation; 127 const [related] = relatedInformation;
@@ -132,12 +133,12 @@ describe('mapRustDiagnosticToVsCode', () => {
132 133
133 it('should map a Clippy copy pass by ref warning', () => { 134 it('should map a Clippy copy pass by ref warning', () => {
134 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 135 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
135 'clippy/trivially_copy_pass_by_ref' 136 'clippy/trivially_copy_pass_by_ref',
136 ); 137 );
137 138
138 assert.strictEqual( 139 assert.strictEqual(
139 diagnostic.severity, 140 diagnostic.severity,
140 vscode.DiagnosticSeverity.Warning 141 vscode.DiagnosticSeverity.Warning,
141 ); 142 );
142 assert.strictEqual(diagnostic.source, 'clippy'); 143 assert.strictEqual(diagnostic.source, 'clippy');
143 assert.strictEqual( 144 assert.strictEqual(
@@ -145,8 +146,8 @@ describe('mapRustDiagnosticToVsCode', () => {
145 [ 146 [
146 'this argument is passed by reference, but would be more efficient if passed by value', 147 'this argument is passed by reference, but would be more efficient if passed by value',
147 '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]', 148 '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]',
148 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref' 149 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref',
149 ].join('\n') 150 ].join('\n'),
150 ); 151 );
151 assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref'); 152 assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref');
152 assert.deepStrictEqual(diagnostic.tags, []); 153 assert.deepStrictEqual(diagnostic.tags, []);
@@ -154,7 +155,8 @@ describe('mapRustDiagnosticToVsCode', () => {
154 // One related information for the lint definition 155 // One related information for the lint definition
155 const relatedInformation = diagnostic.relatedInformation; 156 const relatedInformation = diagnostic.relatedInformation;
156 if (!relatedInformation) { 157 if (!relatedInformation) {
157 return assert.fail('Related information unexpectedly undefined'); 158 assert.fail('Related information unexpectedly undefined');
159 return;
158 } 160 }
159 assert.strictEqual(relatedInformation.length, 1); 161 assert.strictEqual(relatedInformation.length, 1);
160 const [related] = relatedInformation; 162 const [related] = relatedInformation;
@@ -165,27 +167,27 @@ describe('mapRustDiagnosticToVsCode', () => {
165 const [suggestedFix] = suggestedFixes; 167 const [suggestedFix] = suggestedFixes;
166 assert.strictEqual( 168 assert.strictEqual(
167 suggestedFix.title, 169 suggestedFix.title,
168 'consider passing by value instead: `self`' 170 'consider passing by value instead: `self`',
169 ); 171 );
170 // Clippy does not mark this with any applicability 172 // Clippy does not mark this with any applicability
171 assert.strictEqual( 173 assert.strictEqual(
172 suggestedFix.applicability, 174 suggestedFix.applicability,
173 SuggestionApplicability.Unspecified 175 SuggestionApplicability.Unspecified,
174 ); 176 );
175 }); 177 });
176 178
177 it('should map a mismatched type error', () => { 179 it('should map a mismatched type error', () => {
178 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 180 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
179 'error/E0308' 181 'error/E0308',
180 ); 182 );
181 183
182 assert.strictEqual( 184 assert.strictEqual(
183 diagnostic.severity, 185 diagnostic.severity,
184 vscode.DiagnosticSeverity.Error 186 vscode.DiagnosticSeverity.Error,
185 ); 187 );
186 assert.strictEqual( 188 assert.strictEqual(
187 diagnostic.message, 189 diagnostic.message,
188 ['mismatched types', 'expected usize, found u32'].join('\n') 190 ['mismatched types', 'expected usize, found u32'].join('\n'),
189 ); 191 );
190 assert.strictEqual(diagnostic.code, 'E0308'); 192 assert.strictEqual(diagnostic.code, 'E0308');
191 assert.strictEqual(diagnostic.source, 'rustc'); 193 assert.strictEqual(diagnostic.source, 'rustc');
@@ -197,4 +199,38 @@ describe('mapRustDiagnosticToVsCode', () => {
197 // There are no suggested fixes 199 // There are no suggested fixes
198 assert.strictEqual(suggestedFixes.length, 0); 200 assert.strictEqual(suggestedFixes.length, 0);
199 }); 201 });
202
203 it('should map a macro invocation location to normal file path', () => {
204 const { location, diagnostic, suggestedFixes } = mapFixtureToVsCode(
205 'error/E0277',
206 );
207
208 assert.strictEqual(
209 diagnostic.severity,
210 vscode.DiagnosticSeverity.Error,
211 );
212 assert.strictEqual(
213 diagnostic.message,
214 [
215 "can't compare `{integer}` with `&str`",
216 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`',
217 ].join('\n'),
218 );
219 assert.strictEqual(diagnostic.code, 'E0277');
220 assert.strictEqual(diagnostic.source, 'rustc');
221 assert.deepStrictEqual(diagnostic.tags, []);
222
223 // No related information
224 assert.deepStrictEqual(diagnostic.relatedInformation, []);
225
226 // There are no suggested fixes
227 assert.strictEqual(suggestedFixes.length, 0);
228
229 // The file url should be normal file
230 // Ignore the first part because it depends on vs workspace location
231 assert.strictEqual(
232 location.uri.path.substr(-'src/main.rs'.length),
233 'src/main.rs',
234 );
235 });
200}); 236});