private void TryParseLocationFromStack(GenericTest test, out string path, out int line) { // First line is the error message // Then there's one line of our framework; but just to be a bit more future-proof, exclude any that look like extension var matchingLine = test.ErrorStackTrace.Split('\n').Skip(1).FirstOrDefault(l => !l.ToLower().Contains(ExtensionFolder.ToLower())); var match = Regex.Match(matchingLine, @"\((.+):(\d+):\d+\)"); if (match.Groups.Count >= 3) { path = match.Groups[1].Value; line = int.Parse(match.Groups[2].Value); } else { path = null; line = 0; } }
private TestResult CreateTestResult(string source, GenericTest test) { var directory = Path.GetDirectoryName(source); // VS will open the file, but not jump to the line number if the path contais "\.\", so make sure we handle this var path = test.CodeFilePath != null?Path.Combine(directory, test.CodeFilePath.StartsWith(".\\")?test.CodeFilePath.Substring(2) : test.CodeFilePath) : null; var testCase = new TestCase(test.Name, ExecutorUri, source) { DisplayName = test.DisplayName, CodeFilePath = path, LineNumber = test.LineNumber }; return(new TestResult(testCase) { Outcome = test.Outcome, ErrorMessage = test.ErrorMessage, ErrorStackTrace = test.ErrorStackTrace }); }
private void TryParseLocationFromStack(GenericTest test, out string path, out int line) { // First line is the error message // Then there's one line of our framework; but just to be a bit more future-proof, exclude any that look like extension var possibleLines = test.ErrorStackTrace.Split('\n').Skip(1).Where(l => !l.ToLower().Contains(ExtensionFolder.ToLower())); foreach (var matchingLine in possibleLines) { var match = Regex.Match(matchingLine, @"\((.+):(\d+):\d+\)", RegexOptions.Compiled); if (match.Groups.Count >= 3) { path = match.Groups[1].Value.Replace("/", @"\"); line = int.Parse(match.Groups[2].Value); return; } } path = null; line = 0; }
private TestCase CreateTestCase(string source, GenericTest test) { var directory = Path.GetDirectoryName(source); // VS will open the file, but not jump to the line number if the path contais "\.\", so make sure we handle this var path = test.CodeFilePath != null?Path.Combine(directory, test.CodeFilePath.StartsWith(".\\")?test.CodeFilePath.Substring(2) : test.CodeFilePath) : null; var line = test.LineNumber; // SUPERBODGE (See Issue #4) // If we don't have the location of the test, but we have a stack, parse it out // This is temporary until we can find a better way to get filename/line numbers via Jasmine if (path == null && !string.IsNullOrWhiteSpace(test.ErrorStackTrace)) { TryParseLocationFromStack(test, out path, out line); } return(new TestCase(test.Name, ExecutorUri, source) { DisplayName = test.DisplayName, CodeFilePath = path, LineNumber = line }); }