Skip to content

Commit

Permalink
Changed Console.WriteLine to ITestOutputHelper in tests (#1305)
Browse files Browse the repository at this point in the history
* Changed Console.WriteLine to ITestOutputHelper in tests

* Added ITestOutputHelper
  • Loading branch information
tznind authored May 16, 2021
1 parent e9b3289 commit fe9c984
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
55 changes: 40 additions & 15 deletions UnitTests/GraphViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Attribute = Terminal.Gui.Attribute;
using System.Text;
using System.Text.RegularExpressions;
using Xunit.Abstractions;

namespace Terminal.Gui.Views {

Expand Down Expand Up @@ -77,7 +78,7 @@ public static GraphView GetGraph ()
}

#pragma warning disable xUnit1013 // Public method should be marked as test
public static void AssertDriverContentsAre (string expectedLook)
public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output)
{
#pragma warning restore xUnit1013 // Public method should be marked as test

Expand Down Expand Up @@ -108,8 +109,8 @@ public static void AssertDriverContentsAre (string expectedLook)
expectedLook = expectedLook.Replace ("\r\n", "\n");
actualLook = actualLook.Replace ("\r\n", "\n");

Console.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
Console.WriteLine ("But Was:" + Environment.NewLine + actualLook);
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);

Assert.Equal (expectedLook, actualLook);
}
Expand Down Expand Up @@ -514,6 +515,12 @@ public void DrawSeries (GraphView graph, Rect bounds, RectangleF graphBounds)

public class MultiBarSeriesTests{

readonly ITestOutputHelper output;

public MultiBarSeriesTests(ITestOutputHelper output)
{
this.output = output;
}

[Fact]
public void MultiBarSeries_BarSpacing(){
Expand Down Expand Up @@ -643,7 +650,7 @@ public void TestRendering_MultibarSeries(){
│ MM MM MM
┼──┬M──┬M──┬M──────
heytherebob ";
GraphViewTests.AssertDriverContentsAre (looksLike);
GraphViewTests.AssertDriverContentsAre (looksLike, output);
}
}

Expand Down Expand Up @@ -1008,6 +1015,12 @@ public void TestVAxisLocation_MarginLeft ()
}

public class TextAnnotationTests {
readonly ITestOutputHelper output;

public TextAnnotationTests(ITestOutputHelper output)
{
this.output = output;
}

[Fact]
public void TestTextAnnotation_ScreenUnits()
Expand All @@ -1029,7 +1042,7 @@ public void TestTextAnnotation_ScreenUnits()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

// user scrolls up one unit of graph space
gv.ScrollOffset = new PointF (0, 1f);
Expand All @@ -1046,7 +1059,7 @@ public void TestTextAnnotation_ScreenUnits()
1┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);
}


Expand All @@ -1070,7 +1083,7 @@ public void TestTextAnnotation_GraphUnits ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

// user scrolls up one unit of graph space
gv.ScrollOffset = new PointF (0, 1f);
Expand All @@ -1088,7 +1101,7 @@ public void TestTextAnnotation_GraphUnits ()
1┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);
}

[Fact]
Expand All @@ -1115,7 +1128,7 @@ public void TestTextAnnotation_LongText ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}

Expand All @@ -1141,7 +1154,7 @@ public void TestTextAnnotation_Offscreen ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}

Expand Down Expand Up @@ -1174,12 +1187,18 @@ public void TestTextAnnotation_EmptyText (string whitespace)
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}
}

public class LegendTests {
readonly ITestOutputHelper output;

public LegendTests(ITestOutputHelper output)
{
this.output = output;
}

[Fact]
public void LegendNormalUsage_WithBorder ()
Expand All @@ -1200,7 +1219,7 @@ public void LegendNormalUsage_WithBorder ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}

Expand All @@ -1226,12 +1245,18 @@ public void LegendNormalUsage_WithoutBorder ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}
}

public class PathAnnotationTests {
readonly ITestOutputHelper output;

public PathAnnotationTests( ITestOutputHelper output)
{
this.output = output;
}

[Fact]
public void PathAnnotation_Box()
Expand Down Expand Up @@ -1259,7 +1284,7 @@ public void PathAnnotation_Box()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected, output);

}

Expand Down Expand Up @@ -1288,7 +1313,7 @@ public void PathAnnotation_Diamond ()
0┼┬┬┬┬┬┬┬┬
0 5";

GraphViewTests.AssertDriverContentsAre (expected);
GraphViewTests.AssertDriverContentsAre (expected,output);

}
}
Expand Down
14 changes: 10 additions & 4 deletions UnitTests/TableViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
using Terminal.Gui;
using Xunit;
using System.Globalization;
using Xunit.Abstractions;

namespace Terminal.Gui.Views {

public class TableViewTests
{
readonly ITestOutputHelper output;

[Fact]
public TableViewTests(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void EnsureValidScrollOffsets_WithNoCells()
{
var tableView = new TableView();
Expand Down Expand Up @@ -434,7 +440,7 @@ public void TableView_ExpandLastColumn_True()
├─┼──────┤
│1│2 │
";
GraphViewTests.AssertDriverContentsAre(expected);
GraphViewTests.AssertDriverContentsAre(expected, output);
}


Expand All @@ -454,7 +460,7 @@ public void TableView_ExpandLastColumn_False()
├─┼─┼────┤
│1│2│ │
";
GraphViewTests.AssertDriverContentsAre(expected);
GraphViewTests.AssertDriverContentsAre(expected, output);
}

[Fact]
Expand All @@ -475,7 +481,7 @@ public void TableView_ExpandLastColumn_False_ExactBounds()
├─┼─┤
│1│2│
";
GraphViewTests.AssertDriverContentsAre(expected);
GraphViewTests.AssertDriverContentsAre(expected, output);
}

private TableView SetUpMiniTable ()
Expand Down

0 comments on commit fe9c984

Please sign in to comment.