From a5bb91c2cb25ef3411ae7e80608ae463e4b320c4 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 5 Jun 2018 10:11:24 -0700 Subject: [PATCH] Prevent 2.1 template tests from corrupting machine state --- build/dependencies.props | 10 ++++---- .../Helpers/TemplatePackageInstaller.cs | 23 +++++++++++++------ .../Helpers/TemplateTestBase.cs | 9 ++------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index dda10a01d3..e6db0bb6c0 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -40,12 +40,12 @@ 2.1.0 2.1.1-rtm-30818 2.0.3 - 0.19.0 - 3.7.0 - 16.16299.0 - 3.7.0 + 0.20.0 + 3.12.1 + 17.17134.0 + 3.12.1 4.5.0 - 0.8.0 + 0.9.0 2.3.1 2.4.0-beta.1.build3945 diff --git a/test/Templates.Test/Helpers/TemplatePackageInstaller.cs b/test/Templates.Test/Helpers/TemplatePackageInstaller.cs index cd5de94a73..4493d1fb31 100644 --- a/test/Templates.Test/Helpers/TemplatePackageInstaller.cs +++ b/test/Templates.Test/Helpers/TemplatePackageInstaller.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.IO; using System.Linq; using Microsoft.Extensions.CommandLineUtils; @@ -21,19 +24,25 @@ namespace Templates.Test.Helpers "Microsoft.DotNet.Web.Spa.ProjectTemplates", }; - public static void EnsureTemplatePackagesWereReinstalled(ITestOutputHelper output) + public static string CustomHivePath { get; } = Path.Combine(AppContext.BaseDirectory, ".templateengine"); + + public static void EnsureTemplatingEngineInitialized(ITestOutputHelper output) { lock (_templatePackagesReinstallationLock) { if (!_haveReinstalledTemplatePackages) { - ReinstallTemplatePackages(output); + if (Directory.Exists(CustomHivePath)) + { + Directory.Delete(CustomHivePath, recursive: true); + } + InstallTemplatePackages(output); _haveReinstalledTemplatePackages = true; } } } - private static void ReinstallTemplatePackages(ITestOutputHelper output) + private static void InstallTemplatePackages(ITestOutputHelper output) { // Remove any previous or prebundled version of the template packages foreach (var packageName in _templatePackages) @@ -42,7 +51,7 @@ namespace Templates.Test.Helpers output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), - $"new --uninstall {packageName}"); + $"new --uninstall {packageName} --debug:custom-hive \"{CustomHivePath}\""); // We don't need this command to succeed, because we'll verify next that // uninstallation had the desired effect. This command is expected to fail @@ -65,7 +74,7 @@ namespace Templates.Test.Helpers output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), - $"new --install \"{packagePath}\""); + $"new --install \"{packagePath}\" --debug:custom-hive \"{CustomHivePath}\""); proc.WaitForExit(assertSuccess: true); } } @@ -83,7 +92,7 @@ namespace Templates.Test.Helpers output, tempDir, DotNetMuxer.MuxerPathOrDefault(), - $"new \"{templateName}\""); + $"new \"{templateName}\" --debug:custom-hive \"{CustomHivePath}\""); proc.WaitForExit(assertSuccess: false); diff --git a/test/Templates.Test/Helpers/TemplateTestBase.cs b/test/Templates.Test/Helpers/TemplateTestBase.cs index c93cd5d17b..f698c11ba2 100644 --- a/test/Templates.Test/Helpers/TemplateTestBase.cs +++ b/test/Templates.Test/Helpers/TemplateTestBase.cs @@ -25,7 +25,7 @@ namespace Templates.Test public TemplateTestBase(ITestOutputHelper output) { - TemplatePackageInstaller.EnsureTemplatePackagesWereReinstalled(output); + TemplatePackageInstaller.EnsureTemplatingEngineInitialized(output); Output = output; ProjectGuid = Guid.NewGuid().ToString("N"); @@ -57,16 +57,11 @@ $@" File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent); } - protected void InstallTemplatePackages() - { - throw new NotImplementedException(); - } - protected void RunDotNetNew(string templateName, string targetFrameworkOverride, string auth = null, string language = null, bool useLocalDB = false, bool noHttps = false) { SetAfterDirectoryBuildPropsContents(); - var args = $"new {templateName}"; + var args = $"new {templateName} --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\""; if (!string.IsNullOrEmpty(targetFrameworkOverride)) {