Skip to content

Commit bd9b67e

Browse files
committed
(GH-8) Add tests
1 parent c59dce0 commit bd9b67e

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

Source/Cake.VsMetrics.Tests/VsMetricsRunnerFixture.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
using System.Collections.Generic;
2+
using Cake.Core;
23
using Cake.Core.IO;
4+
using Cake.Testing;
35
using Cake.Testing.Fixtures;
46

57
namespace Cake.VsMetrics.Tests
68
{
79
internal sealed class VsMetricsRunnerFixture : ToolFixture<VsMetricsSettings>
810
{
9-
public VsMetricsRunnerFixture()
10-
: base("metrics.exe")
11+
public VsMetricsRunnerFixture(bool defaultToolExist = true, PlatformFamily platform = PlatformFamily.Windows)
12+
: base("/Working/tools/metrics.exe")
1113
{
1214
InputFilePaths = new FilePath[] { "c:/tool.exe" };
1315
OutputFilePath = "metrics_result.xml";
16+
17+
if (defaultToolExist)
18+
{
19+
FileSystem.CreateFile("/Working/tools/metrics.exe");
20+
}
21+
22+
Environment = new FakeEnvironment(platform);
23+
Environment.WorkingDirectory = "/Working";
1424
}
1525

1626
public IEnumerable<FilePath> InputFilePaths { get; set; }

Source/Cake.VsMetrics.Tests/VsMetricsRunnerTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,51 @@ public void RunFixtureWithSettings()
5959

6060
Assert.AreEqual("/f:\"c:/tool.exe\" /o:\"/Working/metrics_result.xml\" /d:\"/Working\" /gac", result.Args);
6161
}
62+
63+
[TestMethod]
64+
public void RunFixtureWithAlternativePathWindows()
65+
{
66+
AssertAlternativePath(VsMetricsToolVersion.Default, "/ProgramFilesX86/Microsoft Visual Studio 14.0/Team Tools/Static Analysis Tools/FxCop/metrics.exe");
67+
AssertAlternativePath(VsMetricsToolVersion.VS2015, "/ProgramFilesX86/Microsoft Visual Studio 14.0/Team Tools/Static Analysis Tools/FxCop/metrics.exe");
68+
AssertAlternativePath(VsMetricsToolVersion.VS2013, "/ProgramFilesX86/Microsoft Visual Studio 12.0/Team Tools/Static Analysis Tools/FxCop/metrics.exe");
69+
}
70+
71+
[TestMethod]
72+
[ExpectedException(typeof(CakeException))]
73+
public void RunFixtureWithAlternativePathWindowsNotSupported()
74+
{
75+
var fixture = new VsMetricsRunnerFixture(false)
76+
{
77+
Settings = { ToolVersion = (VsMetricsToolVersion)1000 }
78+
};
79+
80+
fixture.Environment.SetSpecialPath(SpecialPath.ProgramFilesX86, "/ProgramFilesX86");
81+
82+
fixture.Run();
83+
}
84+
85+
[TestMethod]
86+
[ExpectedException(typeof(CakeException))]
87+
public void RunFixtureWithAlternativePathLinuxNotSupported()
88+
{
89+
var fixture = new VsMetricsRunnerFixture(false, PlatformFamily.Linux);
90+
91+
fixture.Run();
92+
}
93+
94+
private void AssertAlternativePath(VsMetricsToolVersion version, string expectedPath)
95+
{
96+
var fixture = new VsMetricsRunnerFixture(false)
97+
{
98+
Settings = { ToolVersion = version }
99+
};
100+
101+
fixture.FileSystem.CreateFile(expectedPath);
102+
fixture.Environment.SetSpecialPath(SpecialPath.ProgramFilesX86, "/ProgramFilesX86");
103+
104+
var result = fixture.Run();
105+
106+
Assert.AreEqual(expectedPath, result.Path.FullPath);
107+
}
62108
}
63109
}

Source/Cake.VsMetrics/VsMetricsRunner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Cake.Core;
45
using Cake.Core.IO;
56
using Cake.Core.Tooling;
@@ -76,7 +77,7 @@ protected override IEnumerable<FilePath> GetAlternativeToolPaths(VsMetricsSettin
7677
{
7778
if (_environment.Platform.IsUnix())
7879
{
79-
return new FilePath[] { };
80+
return Enumerable.Empty<FilePath>();
8081
}
8182

8283
var programFiles = _environment.GetSpecialPath(SpecialPath.ProgramFilesX86);
@@ -96,7 +97,7 @@ protected override IEnumerable<FilePath> GetAlternativeToolPaths(VsMetricsSettin
9697
return new FilePath[] { metrics2015 };
9798
}
9899

99-
return base.GetAlternativeToolPaths(settings);
100+
return Enumerable.Empty<FilePath>();
100101
}
101102

102103
private ProcessArgumentBuilder GetArguments(IEnumerable<FilePath> inputFilePaths, FilePath outputFilePath, VsMetricsSettings settings)

0 commit comments

Comments
 (0)