From 9bfe67a8e8f02e2d22f9518e769ba2475edfe5e1 Mon Sep 17 00:00:00 2001 From: John Beisner Date: Thu, 6 Apr 2017 11:58:19 -0700 Subject: [PATCH] Adding backwards compat tests to the CLI test catalog. https://github.com/dotnet/cli/issues/6227 https://github.com/dotnet/cli/issues/6228 --- Microsoft.DotNet.Cli.sln | 27 +++++++ .../GivenBackCompat.cs | 72 +++++++++++++++++++ .../dotnet-back-compat.Tests.csproj | 22 ++++++ 3 files changed, 121 insertions(+) create mode 100644 test/dotnet-back-compat.Tests/GivenBackCompat.cs create mode 100644 test/dotnet-back-compat.Tests/dotnet-back-compat.Tests.csproj diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 073ed9822..184ee1d36 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -222,6 +222,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{ build\templates\templates.csproj = build\templates\templates.csproj EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-back-compat.Tests", "test\dotnet-back-compat.Tests\dotnet-back-compat.Tests.csproj", "{A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1510,6 +1512,30 @@ Global {CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|x64.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|x64.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|x86.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Debug|x86.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|Any CPU.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|x64.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|x64.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|x86.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.Release|x86.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6}.RelWithDebInfo|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1578,5 +1604,6 @@ Global {CACA427D-5A71-45E6-88DC-3E2DB6C4D52D} = {FF498306-2DE2-47F6-8C35-3CF0589CF2B8} {3275D006-54C8-4C64-A537-B9941C5D2F0C} = {89905EC4-BC0F-443B-8ADF-691321F10108} {DE4D1AEB-871B-4E7C-945A-453F9A490C06} = {89905EC4-BC0F-443B-8ADF-691321F10108} + {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection EndGlobal diff --git a/test/dotnet-back-compat.Tests/GivenBackCompat.cs b/test/dotnet-back-compat.Tests/GivenBackCompat.cs new file mode 100644 index 000000000..1dbc5f9ee --- /dev/null +++ b/test/dotnet-back-compat.Tests/GivenBackCompat.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; +using System.Linq; +using System.Xml.Linq; + +namespace Microsoft.DotNet.Cli.Build.Tests +{ + public class GivenBackCompat : TestBase + { + [Theory] + [InlineData("netcoreapp1.0", false, true)] + [InlineData("netcoreapp1.1", false, true)] + [InlineData("netstandard1.3", true, false)] + [InlineData("netstandard1.6", true, false)] + + public void ItRestoresBuildsPacksRuns(string target, bool createNuGetPackage, bool executeProgram) + { + + var testAppName = "TestAppSimple"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance(testAppName + "_" + target.Replace('.', '_')) + .WithSourceFiles(); + + // Replace the 'TargetFramework' + string projectFile = Path.Combine(testInstance.Root.ToString(), $"{testAppName}.csproj"); + var projectXml = XDocument.Load(projectFile); + var ns = projectXml.Root.Name.Namespace; + var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First(); + var rootNamespaceElement = propertyGroup.Element(ns + "TargetFramework"); + rootNamespaceElement.SetValue(target); + projectXml.Save(projectFile); + + new RestoreCommand() + .WithWorkingDirectory(testInstance.Root) + .Execute() + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testInstance.Root) + .Execute() + .Should().Pass(); + + if (createNuGetPackage) + { + new PackCommand() + .WithWorkingDirectory(testInstance.Root) + .Execute() + .Should().Pass(); + } + + if (executeProgram) + { + var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; + + var outputDll = testInstance.Root.GetDirectory("bin", configuration, target) + .GetFile($"{testAppName}.dll"); + + new DotnetCommand() + .ExecuteWithCapturedOutput(outputDll.FullName) + .Should().Pass() + .And.HaveStdOutContaining("Hello World"); + } + } + + } +} diff --git a/test/dotnet-back-compat.Tests/dotnet-back-compat.Tests.csproj b/test/dotnet-back-compat.Tests/dotnet-back-compat.Tests.csproj new file mode 100644 index 000000000..fe6a0442e --- /dev/null +++ b/test/dotnet-back-compat.Tests/dotnet-back-compat.Tests.csproj @@ -0,0 +1,22 @@ + + + + + $(CliTargetFramework) + $(CLI_SharedFrameworkVersion) + true + dotnet-back-compat.Tests + $(PackageTargetFallback);dotnet5.4;portable-net451+win8 + + + + + + + + + + + + +