Skip to content

Commit 2bda27f

Browse files
matt W10mpownby
authored andcommitted
cleaned up redundant Path.Combine
1 parent 516d361 commit 2bda27f

5 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/Stryker.Configuration/Options/Inputs/BaselineOutputInput.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using Stryker.Abstractions.Baseline;
23
using Stryker.Abstractions.Exceptions;
34

@@ -18,6 +19,11 @@ public string Validate(BaselineProvider baselineProvider, bool withBaseline)
1819
throw new InputException("BaselineOutput can't be null or whitespace");
1920
}
2021

22+
if (!Path.IsPathFullyQualified(SuppliedInput))
23+
{
24+
throw new InputException($"BaselineOutput must be a fully qualified path, but was: {SuppliedInput}");
25+
}
26+
2127
return SuppliedInput;
2228
}
2329
return Default;

src/Stryker.Core/Stryker.Core.UnitTest/Baseline/Providers/DiskBaselineProviderTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task ShouldWriteToDiskAsync()
2525
var options = new StrykerOptions()
2626
{
2727
ProjectPath = @"C:/Users/JohnDoe/Project/TestFolder",
28-
BaselineOutputPath = "StrykerOutput"
28+
BaselineOutputPath = @"C:/Users/JohnDoe/Project/TestFolder/StrykerOutput"
2929
};
3030
var sut = new DiskBaselineProvider(options, fileSystemMock);
3131

@@ -46,7 +46,7 @@ public async Task ShouldWriteToConfiguredBaselineOutputPathAsync()
4646
var options = new StrykerOptions()
4747
{
4848
ProjectPath = @"C:/Users/JohnDoe/Project/TestFolder",
49-
BaselineOutputPath = "custom-baseline"
49+
BaselineOutputPath = @"C:/Users/JohnDoe/Project/TestFolder/custom-baseline"
5050
};
5151
var sut = new DiskBaselineProvider(options, fileSystemMock);
5252

@@ -84,7 +84,7 @@ public async Task ShouldLoadReportFromConfiguredBaselineOutputPathAsync()
8484
var options = new StrykerOptions()
8585
{
8686
ProjectPath = @"C:/Users/JohnDoe/Project/TestFolder",
87-
BaselineOutputPath = "custom-baseline"
87+
BaselineOutputPath = @"C:/Users/JohnDoe/Project/TestFolder/custom-baseline"
8888
};
8989
var report = JsonReport.Build(options, ReportTestHelper.CreateProjectWith(), It.IsAny<ITestProjectsInfo>());
9090

@@ -103,7 +103,7 @@ public async Task ShouldHandleFileNotFoundExceptionOnLoadAsync()
103103
{
104104
// Arrange
105105
var fileSystemMock = new MockFileSystem();
106-
var options = new StrykerOptions { ProjectPath = "C:/Dev", BaselineOutputPath = "StrykerOutput" };
106+
var options = new StrykerOptions { ProjectPath = "C:/Dev", BaselineOutputPath = "C:/Dev/StrykerOutput" };
107107
var sut = new DiskBaselineProvider(options, fileSystemMock);
108108

109109
// Act
@@ -120,7 +120,7 @@ public async Task ShouldLoadReportFromDiskAsync()
120120
var options = new StrykerOptions()
121121
{
122122
ProjectPath = @"C:/Users/JohnDoe/Project/TestFolder",
123-
BaselineOutputPath = "StrykerOutput"
123+
BaselineOutputPath = @"C:/Users/JohnDoe/Project/TestFolder/StrykerOutput"
124124
};
125125
var report = JsonReport.Build(options, ReportTestHelper.CreateProjectWith(), It.IsAny<ITestProjectsInfo>());
126126

src/Stryker.Core/Stryker.Core.UnitTest/Options/Inputs/BaselineOutputInputTests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using Shouldly;
23
using Stryker.Abstractions.Baseline;
34
using Stryker.Abstractions.Exceptions;
@@ -30,11 +31,23 @@ public void ShouldThrow_WhenDiskBaselineAndNotSupplied(string input)
3031
[TestMethod]
3132
public void ShouldReturnSuppliedValue_WhenDiskBaseline()
3233
{
33-
var target = new BaselineOutputInput { SuppliedInput = "custom-baseline" };
34+
// a path that is fully qualified on whatever OS the tests run on
35+
var fullPath = Path.GetFullPath("custom-baseline");
36+
var target = new BaselineOutputInput { SuppliedInput = fullPath };
3437

3538
var result = target.Validate(BaselineProvider.Disk, withBaseline: true);
3639

37-
result.ShouldBe("custom-baseline");
40+
result.ShouldBe(fullPath);
41+
}
42+
43+
[TestMethod]
44+
[DataRow("custom-baseline")]
45+
[DataRow("relative/baseline")]
46+
public void ShouldThrow_WhenDiskBaselineAndNotFullyQualified(string input)
47+
{
48+
var target = new BaselineOutputInput { SuppliedInput = input };
49+
50+
Should.Throw<InputException>(() => target.Validate(BaselineProvider.Disk, withBaseline: true));
3851
}
3952

4053
[TestMethod]

src/Stryker.Core/Stryker.Core.UnitTest/Options/StrykerInputsTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void NotUsingDashboardBaselineStorageWithBaselineOrDashboardReporterShoul
176176
_target.BaselineProviderInput.SuppliedInput = "disk";
177177
_target.WithBaselineInput.SuppliedInput = true;
178178
_target.ProjectVersionInput.SuppliedInput = "develop";
179-
_target.BaselineOutputInput.SuppliedInput = "StrykerOutput";
179+
_target.BaselineOutputInput.SuppliedInput = Path.GetFullPath("StrykerOutput");
180180

181181
var result = _target.ValidateAll();
182182

@@ -198,8 +198,8 @@ public void WithBaselineShouldNotThrow_2743() // https://github.com/stryker-muta
198198
{
199199
_target.ProjectVersionInput.SuppliedInput = "1";
200200
_target.WithBaselineInput.SuppliedInput = true;
201-
// the disk baseline output is mandatory and is set from the output path by the CLI before validation
202-
_target.BaselineOutputInput.SuppliedInput = "StrykerOutput";
201+
// the disk baseline output is mandatory and is set from the output path (a full path) by the CLI before validation
202+
_target.BaselineOutputInput.SuppliedInput = Path.GetFullPath("StrykerOutput");
203203

204204
Should.NotThrow(() => _target.ValidateAll());
205205
}
@@ -226,11 +226,12 @@ public void ShouldSetBaselineOutputPathWhenSupplied()
226226
{
227227
_target.ProjectVersionInput.SuppliedInput = "1";
228228
_target.WithBaselineInput.SuppliedInput = true;
229-
_target.BaselineOutputInput.SuppliedInput = "custom-baseline";
229+
var fullPath = Path.GetFullPath("custom-baseline");
230+
_target.BaselineOutputInput.SuppliedInput = fullPath;
230231

231232
var result = _target.ValidateAll();
232233

233-
result.BaselineOutputPath.ShouldBe("custom-baseline");
234+
result.BaselineOutputPath.ShouldBe(fullPath);
234235
}
235236

236237
[TestMethod]

src/Stryker.Core/Stryker.Core/Baseline/Providers/DiskBaselineProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public DiskBaselineProvider(IStrykerOptions options, IFileSystem fileSystem = nu
2727

2828
public async Task<IJsonReport> Load(string version)
2929
{
30+
// at this point, BaseLineOutputPath is a fully qualified path
3031
var reportPath = FilePathUtils.NormalizePathSeparators(
31-
Path.Combine(_options.ProjectPath, _options.BaselineOutputPath, version, "stryker-report.json"));
32+
Path.Combine(_options.BaselineOutputPath, version, "stryker-report.json"));
3233

3334
if (_fileSystem.File.Exists(reportPath))
3435
{
@@ -43,8 +44,9 @@ public async Task<IJsonReport> Load(string version)
4344

4445
public async Task Save(IJsonReport report, string version)
4546
{
47+
// at this point, BaseLineOutputPath is a fully qualified path
4648
var reportDirectory = FilePathUtils.NormalizePathSeparators(
47-
Path.Combine(_options.ProjectPath, _options.BaselineOutputPath, version));
49+
Path.Combine(_options.BaselineOutputPath, version));
4850

4951
_fileSystem.Directory.CreateDirectory(reportDirectory);
5052

0 commit comments

Comments
 (0)