Skip to content

Commit 7feab71

Browse files
committed
Added unittest for NAG linter
1 parent 92d0fd7 commit 7feab71

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

test/linter-provider.test.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as path from 'path';
12
import { strictEqual, deepStrictEqual } from 'assert';
2-
import { Diagnostic, DiagnosticSeverity, Range, Position } from 'vscode';
3+
import { Diagnostic, DiagnosticSeverity, Range, Position, window, workspace, Uri } from 'vscode';
34
import { FortranLintingProvider } from '../src/features/linter-provider';
5+
import { delay } from '../src/lib/helper';
46

57
suite('GNU (gfortran) lint single', () => {
68
const linter = new FortranLintingProvider();
@@ -232,8 +234,8 @@ suite('Intel (ifort) lint single', () => {
232234
linter['compiler'] = 'ifort';
233235
const msg = `
234236
/fetch/radiant/RADIANT_Matrix_Free_Subgrid_Scale.F90(102): error #5082: Syntax error, found '::' when expecting one of: ( : % [ . = =>
235-
PetscInt :: ierr
236-
---------------^
237+
PetscInt :: ierr
238+
---------------^
237239
`;
238240
suite('REGEX matches', () => {
239241
const regex = linter['getCompilerREGEX'](linter['compiler']);
@@ -514,3 +516,44 @@ C:\\Some\\random\\path\\sample.f90(4): error #6631: A non-optional actual argume
514516
deepStrictEqual(matches, ref);
515517
});
516518
});
519+
520+
// -----------------------------------------------------------------------------
521+
suite('NAG (nagfor) lint single', () => {
522+
const linter = new FortranLintingProvider();
523+
linter['compiler'] = 'nagfor';
524+
const msg = `
525+
Sequence Error: lint/err-mod.f90, line 3: The IMPLICIT statement cannot occur here
526+
`;
527+
suite('REGEX matches', () => {
528+
const regex = linter['getCompilerREGEX'](linter['compiler']);
529+
const matches = [...msg.matchAll(regex)];
530+
const g = matches[0].groups;
531+
test('REGEX: filename', () => {
532+
strictEqual(g['fname'], 'lint/err-mod.f90');
533+
});
534+
test('REGEX: line number', () => {
535+
strictEqual(g['ln'], '3');
536+
});
537+
test('REGEX: severity <sev1>', () => {
538+
strictEqual(g['sev1'], 'Sequence Error');
539+
});
540+
test('REGEX: message <msg1>', () => {
541+
strictEqual(g['msg1'], 'The IMPLICIT statement cannot occur here');
542+
});
543+
});
544+
test('Diagnostics Array', async () => {
545+
const fileUri = Uri.file(path.resolve(__dirname, '../../test/fortran/lint/err-mod.f90'));
546+
const doc = await workspace.openTextDocument(fileUri);
547+
await window.showTextDocument(doc);
548+
await delay(100);
549+
const matches = linter['getLinterResults'](msg);
550+
const ref = [
551+
new Diagnostic(
552+
new Range(new Position(2, 0), new Position(2, 17)),
553+
'The IMPLICIT statement cannot occur here',
554+
DiagnosticSeverity.Error
555+
),
556+
];
557+
deepStrictEqual(matches, ref);
558+
});
559+
});

0 commit comments

Comments
 (0)