update findAnnotationPoint to use first entry with non-zero line number (#138)

* update findAnnotationPoint to use first entry with non-zero line number

* misc: improve comment in findAnnotationPoint
pull/139/head
Jason Millard 2021-07-22 13:22:55 -04:00 committed by GitHub
parent c56b66a41b
commit dfd8e1e91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -112,6 +112,25 @@ class ResultsParser {
} }
static findAnnotationPoint(trace) { static findAnnotationPoint(trace) {
// Find first entry with non-zero line number in stack trace
const items = trace.match(/at .* in ((?<path>[^:]+):(?<line>\d+))/g);
if (Array.isArray(items)) {
const result = [];
items.forEach(item => {
const match = item.match(/at .* in ((?<path>[^:]+):(?<line>\d+))/);
const point = {
path: match ? match.groups.path : '',
line: match ? Number(match.groups.line) : 0,
};
if (point.line > 0) {
result.push(point);
}
});
if (result.length > 0) {
return result[0];
}
}
// If all entries have zero line number match fallback pattern
const match = trace.match(/at .* in ((?<path>[^:]+):(?<line>\d+))/); const match = trace.match(/at .* in ((?<path>[^:]+):(?<line>\d+))/);
return { return {
path: match ? match.groups.path : '', path: match ? match.groups.path : '',

View File

@ -195,6 +195,16 @@ at UnityEngine.TestTools.TestEnumerator+<Execute>d__6.MoveNext () [0x00038] in /
expect(result.line).toBe(39); expect(result.line).toBe(39);
}); });
test('first entry with non-zero line number annotation point', () => {
const result = ResultsParser.findAnnotationPoint(`at FluentAssertions.Execution.LateBoundTestFramework.Throw (System.String message) [0x00044] in <527a5493e59e45679b35c1e8d65350b3>:0
at FluentAssertions.Execution.TestFrameworkProvider.Throw (System.String message) [0x00011] in <527a5493e59e45679b35c1e8d65350b3>:0
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure (System.String message) [0x00005] in <527a5493e59e45679b35c1e8d65350b3>:0
at Tests.PlayModeTest+<FailedUnityTest>d__5.MoveNext () [0x0002e] in /github/workspace/unity-project/Assets/Tests/PlayModeTest.cs:39
at UnityEngine.TestTools.TestEnumerator+<Execute>d__6.MoveNext () [0x00038] in /github/workspace/unity-project/Library/PackageCache/com.unity.test-framework@1.1.19/UnityEngine.TestRunner/NUnitExtensions/Attributes/TestEnumerator.cs:36`);
expect(result.path).toBe('/github/workspace/unity-project/Assets/Tests/PlayModeTest.cs');
expect(result.line).toBe(39);
});
test('setup annotation point', () => { test('setup annotation point', () => {
const result = ResultsParser.findAnnotationPoint(`SetUp const result = ResultsParser.findAnnotationPoint(`SetUp
at Tests.SetupFailedTest.SetUp () [0x00000] in /github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs:10`); at Tests.SetupFailedTest.SetUp () [0x00000] in /github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs:10`);