diff --git a/.gitignore b/.gitignore index ffb6a8cf76..a91920be6c 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ scripts/Omnisharp* # Build folder .dotnet/ .dotnet-legacy/ +.dotnet-future/ tools/* !tools/packages.config diff --git a/build.cake b/build.cake index 2105bf6867..63ce321958 100644 --- a/build.cake +++ b/build.cake @@ -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; } @@ -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; @@ -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(); @@ -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) diff --git a/build.json b/build.json index b5116761b0..4e5b4c8ac6 100644 --- a/build.json +++ b/build.json @@ -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", @@ -34,5 +35,8 @@ "LegacyNunitTestProject", "LegacyXunitTestProject", "LegacyMSTestProject" + ], + "FutureTestAssets": [ + "ProjectWithSdkProperty" ] } diff --git a/scripts/common.cake b/scripts/common.cake index 04eb736ce1..b073b94ea3 100644 --- a/scripts/common.cake +++ b/scripts/common.cake @@ -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; } @@ -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"); @@ -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; } @@ -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"; diff --git a/test-assets/test-projects/ProjectWithSdkProperty/Program.cs b/test-assets/test-projects/ProjectWithSdkProperty/Program.cs new file mode 100644 index 0000000000..2b675a18fc --- /dev/null +++ b/test-assets/test-projects/ProjectWithSdkProperty/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ProjectWithSdkProperty +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} \ No newline at end of file diff --git a/test-assets/test-projects/ProjectWithSdkProperty/ProjectWithSdkProperty.csproj b/test-assets/test-projects/ProjectWithSdkProperty/ProjectWithSdkProperty.csproj new file mode 100644 index 0000000000..f5028bf9db --- /dev/null +++ b/test-assets/test-projects/ProjectWithSdkProperty/ProjectWithSdkProperty.csproj @@ -0,0 +1,7 @@ + + + + Exe + netcoreapp2.0 + + \ No newline at end of file diff --git a/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs index 53e8d94a5b..8ea8afe0a6 100644 --- a/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs @@ -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); diff --git a/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs index c5428b4d54..4cce4bd3d7 100644 --- a/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs @@ -27,12 +27,12 @@ internal RunTestService GetRequestHandler(OmniSharpTestHost host) return host.GetRequestHandler(OmniSharpEndpoints.V2.RunTest); } - public abstract bool UseLegacyDotNetCli { get; } + public abstract DotNetCliVersion DotNetCliVersion { get; } protected async Task 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); diff --git a/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs index bcafee96ff..6ae274534b 100644 --- a/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using TestUtility; using Xunit; using Xunit.Abstractions; @@ -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() diff --git a/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs index 8d013e4adb..225275d684 100644 --- a/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using TestUtility; using Xunit; using Xunit.Abstractions; @@ -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() diff --git a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs index 9e13bf8cfb..7baee01c6f 100644 --- a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs @@ -1,8 +1,8 @@ using System.Threading.Tasks; +using TestUtility; using Xunit; using Xunit.Abstractions; - namespace OmniSharp.DotNetTest.Tests { /// @@ -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() diff --git a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs index 14aa53faba..463abba4e6 100644 --- a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using TestUtility; using Xunit; using Xunit.Abstractions; @@ -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() diff --git a/tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs b/tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs index 686cf10217..98be41d405 100644 --- a/tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs @@ -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; diff --git a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs index e7d001909c..addc83648a 100644 --- a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs @@ -70,6 +70,7 @@ public async Task TwoProjectsWithSolution() Assert.Equal("netstandard1.3", secondProject.TargetFrameworks[0].ShortName); } } + [Fact] public async Task TwoProjectWithGeneratedFile() { @@ -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 GetWorkspaceInfoAsync(OmniSharpTestHost host) { var service = host.GetWorkspaceInformationService(); diff --git a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs index c6ee7dec54..a9d2b2aabd 100644 --- a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs +++ b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); + + 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(); + + 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); + } + } } } diff --git a/tests/TestUtility/AbstractTestFixture.cs b/tests/TestUtility/AbstractTestFixture.cs index 22b5ae2f3b..b9647e3765 100644 --- a/tests/TestUtility/AbstractTestFixture.cs +++ b/tests/TestUtility/AbstractTestFixture.cs @@ -24,8 +24,8 @@ protected OmniSharpTestHost CreateEmptyOmniSharpHost() return host; } - protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable> configurationData = null, bool useLegacyDotNetCli = false) => - OmniSharpTestHost.Create(path, this.TestOutput, configurationData, useLegacyDotNetCli); + protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable> configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current) => + OmniSharpTestHost.Create(path, this.TestOutput, configurationData, dotNetCliVersion); protected OmniSharpTestHost CreateOmniSharpHost(params TestFile[] testFiles) => CreateOmniSharpHost(testFiles, null); diff --git a/tests/TestUtility/DotNetCliVersion.cs b/tests/TestUtility/DotNetCliVersion.cs new file mode 100644 index 0000000000..3b0a632c73 --- /dev/null +++ b/tests/TestUtility/DotNetCliVersion.cs @@ -0,0 +1,9 @@ +namespace TestUtility +{ + public enum DotNetCliVersion + { + Current, + Legacy, + Future + } +} diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index dde0e7cde8..e45050d525 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -69,11 +69,22 @@ protected override void DisposeCore(bool disposing) this.Workspace.Dispose(); } - public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable> 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> configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current) { var dotNetPath = Path.Combine( TestAssets.Instance.RootFolder, - useLegacyDotNetCli ? ".dotnet-legacy" : ".dotnet", + GetDotNetCliFolderName(dotNetCliVersion), "dotnet"); if (!File.Exists(dotNetPath))