Skip to content

Commit 92a407b

Browse files
author
Gurpreet Singh
committed
fix path scrubber to work with windows and linux
1 parent 0ae45ff commit 92a407b

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class MarkDownReportBuilderTests
1212
[MethodImpl(MethodImplOptions.NoInlining)]
1313
public void ShouldProduceExpectedMarkdown()
1414
{
15-
var model = new FileReportModel(new ReportTestData().CreateMixContainingEachTypeOfOutcome().ToReportModel());
15+
var reportModel = new ReportTestData().CreateMixContainingEachTypeOfOutcome().ToReportModel();
16+
var model = new FileReportModel(reportModel);
1617
var sut = new MarkDownReportBuilder();
1718
ReportApprover.Approve(model, sut);
1819
}
@@ -21,12 +22,14 @@ public void ShouldProduceExpectedMarkdown()
2122
[MethodImpl(MethodImplOptions.NoInlining)]
2223
public void ShouldProduceExpectedMarkdownWithExamples()
2324
{
24-
var model =
25-
new FileReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
26-
.ToReportModel())
27-
{
28-
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
29-
};
25+
var reportModel = new ReportTestData()
26+
.CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
27+
.ToReportModel();
28+
29+
var model = new FileReportModel(reportModel)
30+
{
31+
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
32+
};
3033

3134
var sut = new MarkDownReportBuilder();
3235
ReportApprover.Approve(model, sut);

src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static string ScrubLineNumbers(string source)
3535

3636
static string ScrubPaths(string source)
3737
{
38-
var result = new Regex(@"\b\w:[\\\w.\s-]+\\").Replace(source, "...\\");
38+
var result = Regex.Replace(source, @"^.*[\\/]", @"...\");
39+
//var result = new Regex(@"\b\w:[\\\w.\s-]+\\").Replace(source, "...\\");
3940
return result;
4041
}
4142
}

src/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace TestStack.BDDfy.Reporters.MarkDown
88
{
99
public class MarkDownReportBuilder : IReportBuilder
1010
{
11-
private readonly List<Exception> _exceptions = new();
11+
private readonly List<Exception> _exceptions = [];
1212

1313
public string CreateReport(FileReportModel model)
1414
{
@@ -38,7 +38,7 @@ public string CreateReport(FileReportModel model)
3838
var exampleScenario = story.Scenarios.First();
3939
report.AppendLine(string.Format("### {0}", exampleScenario.Title));
4040

41-
if (exampleScenario.Steps.Any())
41+
if (exampleScenario.Steps.Count != 0)
4242
{
4343
foreach (var step in exampleScenario.Steps.Where(s => s.ShouldReport))
4444
report.AppendLine(" " + WebUtility.HtmlEncode(step.Title) + " ");
@@ -72,9 +72,9 @@ public string CreateReport(FileReportModel model)
7272
return report.ToString();
7373
}
7474

75-
private void ReportTags(StringBuilder report, List<string> tags)
75+
private static void ReportTags(StringBuilder report, List<string> tags)
7676
{
77-
if (!tags.Any())
77+
if (tags.Count == 0)
7878
return;
7979

8080
report.AppendLine(string.Format("Tags: {0}", string.Join(", ", tags.Select(t => string.Format("`{0}`", t)))));
@@ -91,7 +91,7 @@ private void WriteExamples(StringBuilder report, ReportModel.Scenario exampleSce
9191
var maxWidth = new int[numberColumns];
9292
var rows = new List<string[]>();
9393

94-
Action<IEnumerable<string>, string, string> addRow = (cells, result, error) =>
94+
void addRow(IEnumerable<string> cells, string result, string error)
9595
{
9696
var row = new string[numberColumns];
9797
var index = 0;
@@ -113,7 +113,7 @@ private void WriteExamples(StringBuilder report, ReportModel.Scenario exampleSce
113113
}
114114

115115
rows.Add(row);
116-
};
116+
}
117117

118118
addRow(exampleScenario.Example.Headers, "Result", "Errors");
119119
foreach (var scenario in scenarios)
@@ -130,7 +130,7 @@ private void WriteExamples(StringBuilder report, ReportModel.Scenario exampleSce
130130
WriteExampleRow(report, row, maxWidth);
131131
}
132132

133-
private void WriteExampleRow(StringBuilder report, string[] row, int[] maxWidth)
133+
private static void WriteExampleRow(StringBuilder report, string[] row, int[] maxWidth)
134134
{
135135
report.Append(" ");
136136
for (int index = 0; index < row.Length; index++)
@@ -173,7 +173,7 @@ void ReportExceptions(StringBuilder report)
173173
else
174174
report.AppendLine();
175175

176-
var stackTrace = string.Join(Environment.NewLine, exception.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
176+
var stackTrace = string.Join(Environment.NewLine, exception.StackTrace.Split([Environment.NewLine], StringSplitOptions.None)
177177
.Select(s => " " + s));
178178
report.AppendLine(stackTrace);
179179
}
@@ -185,7 +185,7 @@ static string FlattenExceptionMessage(string message)
185185
{
186186
return string.Join(" ", message
187187
.Replace("\t", " ") // replace tab with one space
188-
.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)
188+
.Split(["\r\n", "\n"], StringSplitOptions.None)
189189
.Select(s => s.Trim()))
190190
.TrimEnd(','); // chop any , from the end
191191
}

0 commit comments

Comments
 (0)