Skip to content

Commit 6c4dcc9

Browse files
committed
duplications for platform-specific tests
1 parent 5311530 commit 6c4dcc9

11 files changed

Lines changed: 1576 additions & 39 deletions

Tests/FileCoverageForBitbucketTests.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,11 @@ public class FileCoverageForBitbucketTests
88
[Test]
99
[TestCase(@"/home/user/foo", @"/home/user/foo/baz.txt", ExpectedResult = @"baz.txt")]
1010
[TestCase(@"C:\foo", @"C:\foo/bar/baz.txt", ExpectedResult = "bar/baz.txt")]
11+
[TestCase(@"C:\foo", @"C:/foo/bar/baz.txt", ExpectedResult = "bar/baz.txt", IncludePlatform = "WIN")]
12+
[TestCase(@"C:\nonfoo", @"C:\foo/bar/baz.txt", ExpectedResult = @"C:/foo/bar/baz.txt", IncludePlatform = "WIN")]
13+
[TestCase(@"/home/user/nonfoo", @"/home/user/foo/baz.txt", ExpectedResult = @"/home/user/foo/baz.txt", IncludePlatform = "UNIX")]
1114
public string TestPathTransform(string cwd, string filePath)
1215
{
1316
return FileCoverageForBitbucket.TransformToUnixPath(cwd, filePath);
1417
}
15-
16-
[Test]
17-
[Platform("WIN")]
18-
[TestCase(@"C:\foo", @"C:\foo\bar\baz.txt", ExpectedResult = "bar/baz.txt")]
19-
[TestCase(@"C:\foo", @"C:/foo/bar/baz.txt", ExpectedResult = "bar/baz.txt")]
20-
[TestCase(@"C:\nonfoo", @"C:\foo/bar/baz.txt", ExpectedResult = @"C:/foo/bar/baz.txt")]
21-
public string TestPathTransform_Windows(string cwd, string filePath)
22-
{
23-
return FileCoverageForBitbucket.TransformToUnixPath(cwd, filePath);
24-
}
25-
26-
[Test]
27-
[Platform("Unix")]
28-
[TestCase(@"/home/user/nonfoo", @"/home/user/foo/baz.txt", ExpectedResult = @"/home/user/foo/baz.txt")]
29-
public string TestPathTransform_Unix(string cwd, string filePath)
30-
{
31-
return FileCoverageForBitbucket.TransformToUnixPath(cwd, filePath);
32-
}
3318
}

Tests/FunctionalTests.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ public void Setup()
1010
{
1111
}
1212

13+
//Unfortunately, path-handling in .NET is runtime-dependent,
14+
//and no good platform-agnostic path-handling library or VFS exist
15+
//Therefore we have to copy test data with path modifications and guard them by platform
16+
1317
[Test]
14-
public async Task ReportGeneratorWithPlugin_ShouldGenerateJson()
18+
[TestCase("win", IncludePlatform = "WIN")]
19+
[TestCase("unix", IncludePlatform = "UNIX")]
20+
public async Task ReportGeneratorWithPlugin_ShouldGenerateJson(string dir)
1521
{
16-
var g = new Generator();
17-
var confBuilder = new ReportConfigurationBuilder();
18-
var p = Combine(GetDirectoryName(Assembly.GetExecutingAssembly().Location),
19-
"ReportGenerator.BitbucketServerCodeCoverage.dll");
20-
Environment.SetEnvironmentVariable("SORT_FILE_PATHS", "1");
21-
var targetdir = Combine("../../../", nameof(ReportGeneratorWithPlugin_ShouldGenerateJson));
22+
var (g, confBuilder, p) = AssignStep();
23+
var targetdir = Combine("../../../", nameof(ReportGeneratorWithPlugin_ShouldGenerateJson), dir);
2224

2325
var conf = confBuilder.Create(new Dictionary<string, string>
2426
{
2527
["reporttypes"] = "BitbucketServer",
26-
["reports"] = Combine("./", nameof(ReportGeneratorWithPlugin_ShouldGenerateJson), "TestCoverage1.xml"),
28+
["reports"] = Combine("./", nameof(ReportGeneratorWithPlugin_ShouldGenerateJson), dir, "TestCoverage1.xml"),
2729
["targetdir"] = targetdir,
2830
["verbosity"] = "Verbose",
2931
["plugins"] = p,
@@ -32,6 +34,16 @@ public async Task ReportGeneratorWithPlugin_ShouldGenerateJson()
3234
await AssertStepAsync(g, conf, targetdir);
3335
}
3436

37+
private static (Generator g, ReportConfigurationBuilder confBuilder, string p) AssignStep()
38+
{
39+
var g = new Generator();
40+
var confBuilder = new ReportConfigurationBuilder();
41+
var p = Combine(GetDirectoryName(Assembly.GetExecutingAssembly().Location),
42+
"ReportGenerator.BitbucketServerCodeCoverage.dll");
43+
Environment.SetEnvironmentVariable("SORT_FILE_PATHS", "1");
44+
return (g, confBuilder, p);
45+
}
46+
3547
private static async Task AssertStepAsync(Generator g, ReportConfiguration conf, string targetdir)
3648
{
3749
Assert.That(g.GenerateReport(conf), Is.True);
@@ -42,21 +54,19 @@ private static async Task AssertStepAsync(Generator g, ReportConfiguration conf,
4254
}
4355

4456
[Test]
45-
public async Task ReportGeneratorWithPlugin_ShouldMergeCoverage()
57+
[TestCase("win", IncludePlatform = "WIN")]
58+
[TestCase("unix", IncludePlatform = "UNIX")]
59+
public async Task ReportGeneratorWithPlugin_ShouldMergeCoverage(string dir)
4660
{
47-
var g = new Generator();
48-
var confBuilder = new ReportConfigurationBuilder();
49-
var p = Combine(GetDirectoryName(Assembly.GetExecutingAssembly().Location),
50-
"ReportGenerator.BitbucketServerCodeCoverage.dll");
51-
Environment.SetEnvironmentVariable("SORT_FILE_PATHS", "1");
52-
var targetdir = Combine("../../../", nameof(ReportGeneratorWithPlugin_ShouldMergeCoverage));
61+
var (g, confBuilder, p) = AssignStep();
62+
var targetdir = Combine("../../../", nameof(ReportGeneratorWithPlugin_ShouldMergeCoverage), dir);
5363

5464
var conf = confBuilder.Create(new Dictionary<string, string>
5565
{
5666
["reporttypes"] = "BitbucketServer",
57-
["reports"] = Combine("./", nameof(ReportGeneratorWithPlugin_ShouldMergeCoverage), "MergeTests.xml"),
67+
["reports"] = Combine("./", nameof(ReportGeneratorWithPlugin_ShouldMergeCoverage), dir, "MergeTests.xml"),
5868
["targetdir"] = targetdir,
59-
["plugins"] = p,
69+
["plugins"] = p
6070
});
6171

6272
await AssertStepAsync(g, conf, targetdir);

0 commit comments

Comments
 (0)