Skip to content

Commit

Permalink
Add support for testing .NET Core SDK projects
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinCampbell committed Jul 5, 2017
1 parent 7b33551 commit c0396fd
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ scripts/Omnisharp*
# Build folder
.dotnet/
.dotnet-legacy/
.dotnet-future/
tools/*
!tools/packages.config

Expand Down
24 changes: 24 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class BuildPlan
public string DotNetChannel { get; set; }
public string DotNetVersion { get; set; }
public string LegacyDotNetVersion { get; set; }
public string FutureDotNetVersion { get; set; }
public string DownloadURL { get; set; }
public string MSBuildRuntimeForMono { get; set; }
public string MSBuildLibForMono { get; set; }
Expand All @@ -38,6 +39,7 @@ public class BuildPlan
public string[] TestProjects { get; set; }
public string[] TestAssets { get; set; }
public string[] LegacyTestAssets { get; set; }
public string[] FutureTestAssets { get; set; }

private string currentRid;
private string[] targetRids;
Expand Down Expand Up @@ -331,6 +333,12 @@ Task("BuildEnvironment")
version: buildPlan.LegacyDotNetVersion,
installFolder: env.Folders.LegacyDotNetSdk);
// Install future .NET Core SDK (used for testing non-stable future SDK projects)
InstallDotNetSdk(env, buildPlan,
version: buildPlan.FutureDotNetVersion,
installFolder: env.Folders.FutureDotNetSdk);
// Capture 'dotnet --info' output and parse out RID.
var lines = new List<string>();
Expand Down Expand Up @@ -412,6 +420,22 @@ Task("PrepareTestAssets")
RunTool(env.LegacyDotNetCommand, $"build", folder)
.ExceptionOnError($"Failed to restore '{folder}'.");
}
// Restore and build future test assets with future .NET Core SDK
foreach (var project in buildPlan.FutureTestAssets)
{
var folder = CombinePaths(env.Folders.TestAssets, "test-projects", project);
Information($"Restoring packages in {folder}...");
RunTool(env.FutureDotNetCommand, "restore", folder)
.ExceptionOnError($"Failed to restore '{folder}'.");
Information($"Building {folder}...");
RunTool(env.FutureDotNetCommand, $"build", folder)
.ExceptionOnError($"Failed to restore '{folder}'.");
}
});

void BuildProject(BuildEnvironment env, string projectName, string projectFilePath, string configuration)
Expand Down
6 changes: 5 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"DotNetInstallScriptURL": "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain",
"DotNetInstallScriptURL": "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0/scripts/obtain",
"DotNetChannel": "preview",
"DotNetVersion": "1.0.4",
"LegacyDotNetVersion": "1.0.0-preview2-1-003177",
"FutureDotNetVersion": "2.0.0-preview2-006497",
"DownloadURL": "https://omnisharpdownload.blob.core.windows.net/ext",
"MSBuildRuntimeForMono": "Microsoft.Build.Runtime.Mono-alpha4.zip",
"MSBuildLibForMono": "Microsoft.Build.Lib.Mono-alpha4.zip",
Expand Down Expand Up @@ -34,5 +35,8 @@
"LegacyNunitTestProject",
"LegacyXunitTestProject",
"LegacyMSTestProject"
],
"FutureTestAssets": [
"ProjectWithSdkProperty"
]
}
4 changes: 4 additions & 0 deletions scripts/common.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Folders
{
public string DotNetSdk { get; }
public string LegacyDotNetSdk { get; }
public string FutureDotNetSdk { get; }
public string Tools { get; }

public string MSBuild { get; }
Expand All @@ -33,6 +34,7 @@ public class Folders
{
this.DotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet");
this.LegacyDotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet-legacy");
this.FutureDotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet-future");
this.Tools = PathHelper.Combine(workingDirectory, "tools");

this.MSBuild = PathHelper.Combine(workingDirectory, "msbuild");
Expand All @@ -55,6 +57,7 @@ public class BuildEnvironment

public string DotNetCommand { get; }
public string LegacyDotNetCommand { get; }
public string FutureDotNetCommand { get; }

public string ShellCommand { get; }
public string ShellArgument { get; }
Expand All @@ -71,6 +74,7 @@ public class BuildEnvironment
: PathHelper.Combine(this.Folders.DotNetSdk, "dotnet");

this.LegacyDotNetCommand = PathHelper.Combine(this.Folders.LegacyDotNetSdk, "dotnet");
this.FutureDotNetCommand = PathHelper.Combine(this.Folders.FutureDotNetSdk, "dotnet");

this.ShellCommand = isWindows ? "powershell" : "bash";
this.ShellArgument = isWindows ? "-NoProfile /Command" : "-C";
Expand Down
12 changes: 12 additions & 0 deletions test-assets/test-projects/ProjectWithSdkProperty/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ProjectWithSdkProperty
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<Sdk Name="Microsoft.NET.Sdk" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ internal GetTestStartInfoService GetRequestHandler(OmniSharpTestHost host)
}


public abstract bool UseLegacyDotNetCli { get; }
public abstract DotNetCliVersion DotNetCliVersion { get; }

protected async Task GetDotNetTestStartInfoAsync(string projectName, string methodName, string testFramework)
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync(projectName))
using (var host = CreateOmniSharpHost(testProject.Directory, useLegacyDotNetCli: UseLegacyDotNetCli))
using (var host = CreateOmniSharpHost(testProject.Directory, dotNetCliVersion: DotNetCliVersion))
{
var service = GetRequestHandler(host);

Expand Down
4 changes: 2 additions & 2 deletions tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ internal RunTestService GetRequestHandler(OmniSharpTestHost host)
return host.GetRequestHandler<RunTestService>(OmniSharpEndpoints.V2.RunTest);
}

public abstract bool UseLegacyDotNetCli { get; }
public abstract DotNetCliVersion DotNetCliVersion { get; }

protected async Task<RunTestResponse> RunDotNetTestAsync(string projectName, string methodName, string testFramework, bool shouldPass, bool expectResults = true)
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync(projectName))
using (var host = CreateOmniSharpHost(testProject.Directory, useLegacyDotNetCli: UseLegacyDotNetCli))
using (var host = CreateOmniSharpHost(testProject.Directory, dotNetCliVersion: DotNetCliVersion))
{
var service = GetRequestHandler(host);

Expand Down
3 changes: 2 additions & 1 deletion tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using TestUtility;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -10,7 +11,7 @@ public GetTestStartInfoFacts(ITestOutputHelper output) : base(output)
{
}

public override bool UseLegacyDotNetCli { get; } = false;
public override DotNetCliVersion DotNetCliVersion { get; } = DotNetCliVersion.Current;

[Fact]
public async Task RunXunitTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using TestUtility;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -10,7 +11,7 @@ public LegacyGetTestStartInfoFacts(ITestOutputHelper testOutput) : base(testOutp
{
}

public override bool UseLegacyDotNetCli { get; } = true;
public override DotNetCliVersion DotNetCliVersion { get; } = DotNetCliVersion.Legacy;

[Fact]
public async Task RunXunitTest()
Expand Down
4 changes: 2 additions & 2 deletions tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Threading.Tasks;
using TestUtility;
using Xunit;
using Xunit.Abstractions;


namespace OmniSharp.DotNetTest.Tests
{
/// <summary>
Expand All @@ -15,7 +15,7 @@ public LegacyRunTestFacts(ITestOutputHelper output)
{
}

public override bool UseLegacyDotNetCli { get; } = true;
public override DotNetCliVersion DotNetCliVersion { get; } = DotNetCliVersion.Legacy;

[Fact]
public async Task RunXunitTest()
Expand Down
3 changes: 2 additions & 1 deletion tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using TestUtility;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -11,7 +12,7 @@ public RunTestFacts(ITestOutputHelper testOutput)
{
}

public override bool UseLegacyDotNetCli { get; } = false;
public override DotNetCliVersion DotNetCliVersion { get; } = DotNetCliVersion.Current;

[Fact]
public async Task RunXunitTest()
Expand Down
2 changes: 1 addition & 1 deletion tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public TestDiscoveryFacts(ITestOutputHelper output)
public async Task FoundFactsBasedTest(string projectName, string fileName, int line, int column, bool found, string expectedFeatureName)
{
using (var testProject = await this._testAssets.GetTestProjectAsync(projectName))
using (var host = CreateOmniSharpHost(testProject.Directory, useLegacyDotNetCli: true))
using (var host = CreateOmniSharpHost(testProject.Directory, dotNetCliVersion: DotNetCliVersion.Legacy))
{
var filePath = Path.Combine(testProject.Directory, fileName);
var solution = host.Workspace.CurrentSolution;
Expand Down
18 changes: 18 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public async Task TwoProjectsWithSolution()
Assert.Equal("netstandard1.3", secondProject.TargetFrameworks[0].ShortName);
}
}

[Fact]
public async Task TwoProjectWithGeneratedFile()
{
Expand All @@ -87,6 +88,23 @@ public async Task TwoProjectWithGeneratedFile()
}
}

[Fact]
public async Task ProjectWithSdkProperty()
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithSdkProperty"))
using (var host = CreateOmniSharpHost(testProject.Directory, dotNetCliVersion: DotNetCliVersion.Future))
{
var workspaceInfo = await GetWorkspaceInfoAsync(host);

Assert.NotNull(workspaceInfo.Projects);
Assert.Equal(1, workspaceInfo.Projects.Count);

var project = workspaceInfo.Projects[0];
Assert.Equal("ProjectWithSdkProperty.csproj", Path.GetFileName(project.Path));
Assert.Equal(3, project.SourceFiles.Count);
}
}

private static async Task<MSBuildWorkspaceInfo> GetWorkspaceInfoAsync(OmniSharpTestHost host)
{
var service = host.GetWorkspaceInformationService();
Expand Down
40 changes: 36 additions & 4 deletions tests/OmniSharp.Tests/DotNetCliServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DotNetCliServiceFacts(ITestOutputHelper output)
[Fact]
public void LegacyGetVersion()
{
using (var host = CreateOmniSharpHost(useLegacyDotNetCli: true))
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Legacy))
{
var dotNetCli = host.GetExport<DotNetCliService>();

Expand All @@ -31,7 +31,7 @@ public void LegacyGetVersion()
[Fact]
public void LegacyGetInfo()
{
using (var host = CreateOmniSharpHost(useLegacyDotNetCli: true))
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Legacy))
{
var dotNetCli = host.GetExport<DotNetCliService>();

Expand All @@ -47,7 +47,7 @@ public void LegacyGetInfo()
[Fact]
public void GetVersion()
{
using (var host = CreateOmniSharpHost(useLegacyDotNetCli: false))
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Current))
{
var dotNetCli = host.GetExport<DotNetCliService>();

Expand All @@ -63,7 +63,7 @@ public void GetVersion()
[Fact]
public void GetInfo()
{
using (var host = CreateOmniSharpHost(useLegacyDotNetCli: false))
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Current))
{
var dotNetCli = host.GetExport<DotNetCliService>();

Expand All @@ -75,5 +75,37 @@ public void GetInfo()
Assert.Equal("", info.Version.Release);
}
}

[Fact]
public void FutureGetVersion()
{
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Future))
{
var dotNetCli = host.GetExport<DotNetCliService>();

var version = dotNetCli.GetVersion();

Assert.Equal(2, version.Major);
Assert.Equal(0, version.Minor);
Assert.Equal(0, version.Patch);
Assert.Equal("preview2-006497", version.Release);
}
}

[Fact]
public void FutureGetInfo()
{
using (var host = CreateOmniSharpHost(dotNetCliVersion: DotNetCliVersion.Future))
{
var dotNetCli = host.GetExport<DotNetCliService>();

var info = dotNetCli.GetInfo();

Assert.Equal(2, info.Version.Major);
Assert.Equal(0, info.Version.Minor);
Assert.Equal(0, info.Version.Patch);
Assert.Equal("preview2-006497", info.Version.Release);
}
}
}
}
4 changes: 2 additions & 2 deletions tests/TestUtility/AbstractTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected OmniSharpTestHost CreateEmptyOmniSharpHost()
return host;
}

protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, bool useLegacyDotNetCli = false) =>
OmniSharpTestHost.Create(path, this.TestOutput, configurationData, useLegacyDotNetCli);
protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current) =>
OmniSharpTestHost.Create(path, this.TestOutput, configurationData, dotNetCliVersion);

protected OmniSharpTestHost CreateOmniSharpHost(params TestFile[] testFiles) =>
CreateOmniSharpHost(testFiles, null);
Expand Down
9 changes: 9 additions & 0 deletions tests/TestUtility/DotNetCliVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TestUtility
{
public enum DotNetCliVersion
{
Current,
Legacy,
Future
}
}
15 changes: 13 additions & 2 deletions tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ protected override void DisposeCore(bool disposing)
this.Workspace.Dispose();
}

public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, bool useLegacyDotNetCli = false)
private static string GetDotNetCliFolderName(DotNetCliVersion dotNetCliVersion)
{
switch (dotNetCliVersion)
{
case DotNetCliVersion.Current: return ".dotnet";
case DotNetCliVersion.Future: return ".dotnet-future";
case DotNetCliVersion.Legacy: return ".dotnet-legacy";
default: throw new ArgumentException($"Unknown {nameof(dotNetCliVersion)}: {dotNetCliVersion}", nameof(dotNetCliVersion));
}
}

public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current)
{
var dotNetPath = Path.Combine(
TestAssets.Instance.RootFolder,
useLegacyDotNetCli ? ".dotnet-legacy" : ".dotnet",
GetDotNetCliFolderName(dotNetCliVersion),
"dotnet");

if (!File.Exists(dotNetPath))
Expand Down

0 comments on commit c0396fd

Please sign in to comment.