Skip to content

Commit 549b8e8

Browse files
committed
test: add check for linter user option
1 parent 2ccb4d3 commit 549b8e8

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

src/features/linter-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class FortranLintingProvider {
200200
return;
201201
}
202202

203-
this.linter = this.getLinter();
203+
this.linter = this.getLinter(this.settings.compiler);
204204
const command = this.getLinterExecutable();
205205
const argList = this.constructArgumentList(textDocument);
206206
const filePath = path.parse(textDocument.fileName).dir;
@@ -251,8 +251,8 @@ export class FortranLintingProvider {
251251
}
252252
}
253253

254-
private getLinter(): GNULinter | GNUModernLinter | IntelLinter | NAGLinter {
255-
switch (this.settings.compiler) {
254+
private getLinter(compiler: string): GNULinter | GNUModernLinter | IntelLinter | NAGLinter {
255+
switch (compiler) {
256256
case 'gfortran':
257257
if (this.settings.modernGNU) return GNU_NEW;
258258
return GNU;

test/fortran/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"fortran.fortls.directories": ["./**"],
1919
"fortran.fortls.excludeSuffixes": [".snap"],
2020
"fortran.fortls.excludeDirectories": [".vscode/"],
21-
"fortran.fortls.notifyInit": true
21+
"fortran.fortls.notifyInit": true,
22+
"fortran.linter.compiler": "gfortran"
2223
}

test/linter-provider.test.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ suite('Linter integration', () => {
7474
deepStrictEqual(paths, refs);
7575
});
7676

77+
test('Linter user setting returns the right linter internally', () => {
78+
const names = ['gfortran', 'ifort', 'ifx', 'nagfor', 'fake'];
79+
for (const n of names) {
80+
const compiler = linter['getLinter'](n);
81+
if (n === 'gfortran') {
82+
if (linter['settings'].modernGNU) {
83+
strictEqual(compiler instanceof GNUModernLinter, true);
84+
} else {
85+
strictEqual(compiler instanceof GNULinter, true);
86+
}
87+
} else if (n === 'ifort' || n === 'ifx') {
88+
strictEqual(compiler instanceof IntelLinter, true);
89+
} else if (n === 'nagfor') {
90+
strictEqual(compiler instanceof NAGLinter, true);
91+
} else {
92+
strictEqual(compiler instanceof GNULinter, true);
93+
}
94+
}
95+
});
96+
7797
suiteTeardown(async function (): Promise<void> {
7898
await config.update('linter.includePaths', oldVals, false);
7999
});
@@ -122,25 +142,25 @@ C:\\Some\\random\\path\\sample.f90:4:18:
122142
| 1
123143
Error: Missing actual argument for argument ‘a’ at (1)
124144
`;
125-
// suite('REGEX matches', () => {
126-
// const matches = [...msg.matchAll(linter.regex)];
127-
// const g = matches[0].groups;
128-
// test('REGEX: filename', () => {
129-
// strictEqual(g?.['fname'], 'C:\\Some\\random\\path\\sample.f90');
130-
// });
131-
// test('REGEX: line number', () => {
132-
// strictEqual(g?.['ln'], '4');
133-
// });
134-
// test('REGEX: column number', () => {
135-
// strictEqual(g?.['cn'], '18');
136-
// });
137-
// test('REGEX: severity <sev1>', () => {
138-
// strictEqual(g?.['sev1'], 'Error');
139-
// });
140-
// test('REGEX: message <msg1>', () => {
141-
// strictEqual(g?.['msg1'], 'Missing actual argument for argument ‘a’ at (1)');
142-
// });
143-
// });
145+
suite('REGEX matches', () => {
146+
const matches = [...msg.matchAll(linter.regex)];
147+
const g = matches[0].groups;
148+
test('REGEX: filename', () => {
149+
strictEqual(g?.['fname'], 'C:\\Some\\random\\path\\sample.f90');
150+
});
151+
test('REGEX: line number', () => {
152+
strictEqual(g?.['ln'], '4');
153+
});
154+
test('REGEX: column number', () => {
155+
strictEqual(g?.['cn'], '18');
156+
});
157+
test('REGEX: severity <sev1>', () => {
158+
strictEqual(g?.['sev1'], 'Error');
159+
});
160+
test('REGEX: message <msg1>', () => {
161+
strictEqual(g?.['msg1'], 'Missing actual argument for argument ‘a’ at (1)');
162+
});
163+
});
144164
test('Diagnostics Array', () => {
145165
console.log(linter.parse(msg));
146166
const diags = linter.parse(msg);

0 commit comments

Comments
 (0)