Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
starting
  • Loading branch information
Bryan MacFarlane committed Mar 27, 2020
1 parent 1c06f0e commit 3422318
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
69 changes: 69 additions & 0 deletions __tests__/setup-go.test.ts
Expand Up @@ -9,6 +9,9 @@ import * as main from '../src/main';
import * as im from '../src/installer';

let goJsonData = require('./data/golang-dl.json');
let matchers = require('../matchers.json');
let matcherPattern = matchers.problemMatcher[0].pattern[0];
let matcherRegExp = new RegExp(matcherPattern.regexp);

describe('setup-go', () => {
let inputs = {} as any;
Expand Down Expand Up @@ -322,6 +325,72 @@ describe('setup-go', () => {
expect(added).toBeTruthy;
});

interface Annotation {
file: string,
line: number,
column: number,
message: string
}

//
// problem matcher regex pattern tests

function testMatch(line: string): Annotation {
let annotation = <Annotation>{};

let match = matcherRegExp.exec(line);
if (match) {
annotation.line = parseInt(match[matcherPattern.line], 10);
annotation.column = parseInt(match[matcherPattern.column], 10);
annotation.file = match[matcherPattern.file].trim();
annotation.message = match[matcherPattern.message].trim();
}

return annotation;
}

it('matches on rooted unix path', async () => {
let line = '/assert.go:4:1: missing return at end of function';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(4);
expect(annotation.column).toBe(1);
expect(annotation.file).toBe('/assert.go');
expect(annotation.message).toBe('missing return at end of function');
});

it('matches on relative unix path', async () => {
let line = './a/path/assert.go:6:1: missing return at end of function';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(6);
expect(annotation.column).toBe(1);
expect(annotation.file).toBe('./a/path/assert.go');
expect(annotation.message).toBe('missing return at end of function');
});

it('matches on rooted unix path', async () => {
let line = '/assert.go:4:1: missing return at end of function';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(4);
expect(annotation.column).toBe(1);
expect(annotation.file).toBe('/assert.go');
expect(annotation.message).toBe('missing return at end of function');
});

it('matches on rooted unix path with whitespace', async () => {
let line = ' /assert.go:5:2: missing return at end of function ';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(5);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('/assert.go');
expect(annotation.message).toBe('missing return at end of function');
});



// 1.13.1 => 1.13.1
// 1.13 => 1.13.0
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
Expand Down
10 changes: 5 additions & 5 deletions matchers.json
Expand Up @@ -4,11 +4,11 @@
"owner": "go",
"pattern": [
{
"regexp": "^([^:]*: )?((.:)?[^:]*):(\\d+)(:(\\d+))?: (.*)$",
"file": 2,
"line": 4,
"column": 6,
"message": 7
"regexp": "((?:.{0,2}\\/|.{0,2}\\\\)(?:.+\\.go)):(?:(\\d+):(\\d+):)? (.*)",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
Expand Down

0 comments on commit 3422318

Please sign in to comment.