Browse Source

Fixed SD2-743: Double clicking NUnit console errors in output window does not open up corresponding file

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1269 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
43a84fc82d
  1. 33
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs
  2. 32
      src/Main/Base/Test/OutputTextLineParserTestFixture.cs

33
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs

@ -14,6 +14,12 @@ namespace ICSharpCode.SharpDevelop.Gui
/// Parses output text in the Output Build pad window and extracts source code /// Parses output text in the Output Build pad window and extracts source code
/// file references. /// file references.
/// </summary> /// </summary>
/// <remarks>
/// Supported formats:
/// C#: "d:\somedir\somefile.ext(12,34)"
/// NUnit: "in d:\somedir\somefile.ext:line 12" (stacktrace format)
/// C++: "d:\somedir\somefile.ext(12)" (also VB and some NUnit failures)
/// </remarks>
public static class OutputTextLineParser public static class OutputTextLineParser
{ {
/// <summary> /// <summary>
@ -25,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public static FileLineReference GetCSharpCompilerFileLineReference(string lineText) public static FileLineReference GetCSharpCompilerFileLineReference(string lineText)
{ {
if (lineText != null) { if (lineText != null) {
Match match = Regex.Match(lineText, @"^.*?(\w+:[/\\].*?)\(([\d]*),([\d]*)\)"); Match match = Regex.Match(lineText, @"\b(\w:[/\\].*?)\((\d+),(\d+)\)");
if (match.Success) { if (match.Success) {
try { try {
// Take off 1 for line/col since SharpDevelop is zero index based. // Take off 1 for line/col since SharpDevelop is zero index based.
@ -33,7 +39,8 @@ namespace ICSharpCode.SharpDevelop.Gui
int col = Convert.ToInt32(match.Groups[3].Value) - 1; int col = Convert.ToInt32(match.Groups[3].Value) - 1;
return new FileLineReference(match.Groups[1].Value, line, col); return new FileLineReference(match.Groups[1].Value, line, col);
} catch (Exception) { } catch (FormatException) {
} catch (OverflowException) {
// Ignore. // Ignore.
} }
} }
@ -65,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
/// <summary> /// <summary>
/// Extracts source code file reference from NUnit output. /// Extracts source code file reference from NUnit output. (stacktrace format)
/// </summary> /// </summary>
/// <param name="line">The text line to parse.</param> /// <param name="line">The text line to parse.</param>
/// <param name="multiline">The <paramref name="line"/> text is multilined.</param> /// <param name="multiline">The <paramref name="line"/> text is multilined.</param>
@ -75,20 +82,23 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
RegexOptions regexOptions = multiline ? RegexOptions.Multiline : RegexOptions.None; RegexOptions regexOptions = multiline ? RegexOptions.Multiline : RegexOptions.None;
FileLineReference result = null;
if (lineText != null) { if (lineText != null) {
Match match = Regex.Match(lineText, @"^.*?\sin\s(.*?):line\s(\d*)?\r?$", regexOptions); Match match = Regex.Match(lineText, @"\sin\s(.*?):line\s(\d+)?\r?$", regexOptions);
while (match.Success) {
if (match.Success) {
try { try {
int line = Convert.ToInt32(match.Groups[2].Value) - 1; int line = Convert.ToInt32(match.Groups[2].Value) - 1;
return new FileLineReference(match.Groups[1].Value, line); result = new FileLineReference(match.Groups[1].Value, line);
} catch (Exception) { } catch (FormatException) {
} catch (OverflowException) {
// Ignore. // Ignore.
} }
match = match.NextMatch();
} }
} }
return null; return result;
} }
/// <summary> /// <summary>
@ -101,7 +111,7 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
if (lineText != null ) { if (lineText != null ) {
Match match = Regex.Match(lineText, @"^.*?(\w+:[/\\].*?)\(([\d]*)\) :"); Match match = Regex.Match(lineText, @"\b(\w:[/\\].*?)\((\d+)\)");
if (match.Success) { if (match.Success) {
try { try {
@ -109,7 +119,8 @@ namespace ICSharpCode.SharpDevelop.Gui
int line = Convert.ToInt32(match.Groups[2].Value) - 1; int line = Convert.ToInt32(match.Groups[2].Value) - 1;
return new FileLineReference(match.Groups[1].Value.Trim(), line); return new FileLineReference(match.Groups[1].Value.Trim(), line);
} catch (Exception) { } catch (FormatException) {
} catch (OverflowException) {
// Ignore. // Ignore.
} }
} }

32
src/Main/Base/Test/OutputTextLineParserTestFixture.cs

@ -12,7 +12,7 @@ using System;
namespace ICSharpCode.SharpDevelop.Tests namespace ICSharpCode.SharpDevelop.Tests
{ {
[TestFixture] [TestFixture]
public class NUnitOutputParserTestFixture public class OutputTextLineParserTests
{ {
[Test] [Test]
public void Multiline() public void Multiline()
@ -34,5 +34,35 @@ namespace ICSharpCode.SharpDevelop.Tests
Assert.AreEqual(0, lineRef.Column); Assert.AreEqual(0, lineRef.Column);
} }
[Test]
public void MultipleLines()
{
string output = " at NunitFoo.Tests.FooTest.Foo() in c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs:line 11\r\n" +
" at NunitFoo.Tests.FooTest.Foo() in c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs:line 22\r\n";
FileLineReference lineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(output, true);
Assert.AreEqual(lineRef.FileName, "c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs");
Assert.AreEqual(21, lineRef.Line);
Assert.AreEqual(0, lineRef.Column);
}
[Test]
public void NUnitConsoleFailure()
{
string output = "c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs(22)";
FileLineReference lineRef = OutputTextLineParser.GetFileLineReference(output);
Assert.AreEqual(lineRef.FileName, "c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs");
Assert.AreEqual(21, lineRef.Line);
Assert.AreEqual(0, lineRef.Column);
}
[Test]
public void CompilerFailure()
{
string output = "c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs(22,10)";
FileLineReference lineRef = OutputTextLineParser.GetFileLineReference(output);
Assert.AreEqual(lineRef.FileName, "c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs");
Assert.AreEqual(21, lineRef.Line);
Assert.AreEqual(9, lineRef.Column);
}
} }
} }

Loading…
Cancel
Save