diff --git a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs b/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs deleted file mode 100644 index f9903bdb5..000000000 --- a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs +++ /dev/null @@ -1,133 +0,0 @@ -// 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.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; - -namespace Microsoft.DotNet.TestFramework -{ - public class TestInstance - { - // made tolower because the rest of the class works with normalized tolower strings - private static readonly IEnumerable<string> BuildArtifactBlackList = new List<string>() {".IncrementalCache", ".SDKVersion"}.Select(s => s.ToLower()).ToArray(); - - private string _testDestination; - private string _testAssetRoot; - - internal TestInstance(string testAssetRoot, string testDestination) - { - Console.WriteLine($"Copying {testAssetRoot} to {testDestination}"); - if (string.IsNullOrEmpty(testAssetRoot)) - { - throw new ArgumentException("testScenario"); - } - - if (string.IsNullOrEmpty(testDestination)) - { - throw new ArgumentException("testDestination"); - } - - _testAssetRoot = testAssetRoot; - _testDestination = testDestination; - - if (Directory.Exists(testDestination)) - { - Directory.Delete(testDestination, true); - } - - Directory.CreateDirectory(testDestination); - CopySource(); - } - - private void CopySource() - { - var sourceDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories) - .Where(dir => - { - dir = dir.ToLower(); - return !dir.EndsWith($"{Path.DirectorySeparatorChar}bin") - && !dir.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}") - && !dir.EndsWith($"{Path.DirectorySeparatorChar}obj") - && !dir.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}"); - }); - - foreach (string sourceDir in sourceDirs) - { - Directory.CreateDirectory(sourceDir.Replace(_testAssetRoot, _testDestination)); - } - - var sourceFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories) - .Where(file => - { - file = file.ToLower(); - return !file.EndsWith("project.lock.json") - && !file.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}") - && !file.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}"); - }); - - foreach (string srcFile in sourceFiles) - { - string destFile = srcFile.Replace(_testAssetRoot, _testDestination); - File.Copy(srcFile, destFile, true); - } - } - - public TestInstance WithLockFiles() - { - foreach (string lockFile in Directory.GetFiles(_testAssetRoot, "project.lock.json", SearchOption.AllDirectories)) - { - string destinationLockFile = lockFile.Replace(_testAssetRoot, _testDestination); - File.Copy(lockFile, destinationLockFile, true); - } - - return this; - } - - public TestInstance WithBuildArtifacts() - { - var binDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories) - .Where(dir => - { - dir = dir.ToLower(); - return dir.EndsWith($"{Path.DirectorySeparatorChar}bin") - || dir.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}") - || dir.EndsWith($"{Path.DirectorySeparatorChar}obj") - || dir.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}"); - }); - - foreach (string dirPath in binDirs) - { - Directory.CreateDirectory(dirPath.Replace(_testAssetRoot, _testDestination)); - } - - var binFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories) - .Where(file => - { - file = file.ToLower(); - - var isArtifact = file.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}") - || file.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}"); - - var isBlackListed = BuildArtifactBlackList.Any(b => file.Contains(b)); - - return isArtifact && !isBlackListed; - }); - - foreach (string binFile in binFiles) - { - string destFile = binFile.Replace(_testAssetRoot, _testDestination); - File.Copy(binFile, destFile, true); - } - - return this; - } - - public string TestRoot - { - get { return _testDestination; } - } - } -} diff --git a/src/Microsoft.DotNet.TestFramework/TestAssetsManager.cs b/src/Microsoft.DotNet.TestFramework/TestAssetsManager.cs index e31e00b01..61872b1b2 100644 --- a/src/Microsoft.DotNet.TestFramework/TestAssetsManager.cs +++ b/src/Microsoft.DotNet.TestFramework/TestAssetsManager.cs @@ -102,7 +102,7 @@ namespace Microsoft.DotNet.TestFramework var testInstance = new TestInstance(testProjectDir, testDestination); return testInstance; } - + public TestDirectory CreateTestDirectory([CallerMemberName] string callingMethod = "", string identifier = "") { string testDestination = Path.Combine(AppContext.BaseDirectory, callingMethod + identifier); diff --git a/src/Microsoft.DotNet.TestFramework/TestDirectory.cs b/src/Microsoft.DotNet.TestFramework/TestDirectory.cs index e599b79e7..d76387d8a 100644 --- a/src/Microsoft.DotNet.TestFramework/TestDirectory.cs +++ b/src/Microsoft.DotNet.TestFramework/TestDirectory.cs @@ -22,9 +22,9 @@ namespace Microsoft.DotNet.TestFramework EnsureExistsAndEmpty(Path); } - + public string Path { get; private set; } - + private static void EnsureExistsAndEmpty(string path) { if (Directory.Exists(path)) diff --git a/src/Microsoft.DotNet.TestFramework/TestInstance.cs b/src/Microsoft.DotNet.TestFramework/TestInstance.cs index d6489bf34..a5fd9bee7 100644 --- a/src/Microsoft.DotNet.TestFramework/TestInstance.cs +++ b/src/Microsoft.DotNet.TestFramework/TestInstance.cs @@ -11,6 +11,9 @@ namespace Microsoft.DotNet.TestFramework { public class TestInstance: TestDirectory { + // made tolower because the rest of the class works with normalized tolower strings + private static readonly IEnumerable<string> BuildArtifactBlackList = new List<string>() {".IncrementalCache", ".SDKVersion"}.Select(s => s.ToLower()).ToArray(); + private string _testAssetRoot; internal TestInstance(string testAssetRoot, string testDestination) : base(testDestination) @@ -21,7 +24,7 @@ namespace Microsoft.DotNet.TestFramework } _testAssetRoot = testAssetRoot; - + CopySource(); } @@ -92,8 +95,13 @@ namespace Microsoft.DotNet.TestFramework .Where(file => { file = file.ToLower(); - return file.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}") + + var isArtifact = file.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}") || file.Contains($"{System.IO.Path.DirectorySeparatorChar}obj{System.IO.Path.DirectorySeparatorChar}"); + + var isBlackListed = BuildArtifactBlackList.Any(b => file.Contains(b)); + + return isArtifact && !isBlackListed; }); foreach (string binFile in binFiles) diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index fd8fcbb31..4a6641ba2 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -42,9 +42,9 @@ namespace Microsoft.DotNet.Cli public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); - + new MulticoreJitActivator().TryActivateMulticoreJit(); - + if (Env.GetEnvironmentVariableAsBool("DOTNET_CLI_CAPTURE_TIMING", false)) { PerfTrace.Enabled = true; diff --git a/test/dotnet-build.Tests/ProjectNameArgumentTests.cs b/test/dotnet-build.Tests/ProjectNameArgumentTests.cs index 611540b1c..c46ee18f3 100644 --- a/test/dotnet-build.Tests/ProjectNameArgumentTests.cs +++ b/test/dotnet-build.Tests/ProjectNameArgumentTests.cs @@ -96,6 +96,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests { Test(new string[] { }, new[] { "L21" }, workingDirectory: Path.Combine("src", "L21")); } + [Fact] public void TestFailsIfNoProjectJsonInCurrentDirectoryWithNoArguments() { diff --git a/test/dotnet.Tests/GivenThatIWantToManageMulticoreJIT.cs b/test/dotnet.Tests/GivenThatIWantToManageMulticoreJIT.cs index 97d80a577..d3dcc3e3b 100644 --- a/test/dotnet.Tests/GivenThatIWantToManageMulticoreJIT.cs +++ b/test/dotnet.Tests/GivenThatIWantToManageMulticoreJIT.cs @@ -110,7 +110,7 @@ namespace Microsoft.DotNet.Tests var rid = PlatformServices.Default.Runtime.GetRuntimeIdentifier(); return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? $@"Microsoft\dotnet\sdk\{version}{rid}\optimizationdata" + ? $@"Microsoft\dotnet\sdk\{version}\{rid}\optimizationdata" : $@".dotnet/sdk/{version}/{rid}/optimizationdata"; }