diff --git a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs index da4e8adc444..3c17cb2aea3 100644 --- a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs +++ b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs @@ -57,7 +57,7 @@ public class ProjectItem_Tests : IDisposable "; protected readonly TestEnvironment _env; - private DummyMappedDrive _mappedDrive = null; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); public ProjectItem_Tests() { @@ -67,7 +67,7 @@ public ProjectItem_Tests() public void Dispose() { _env.Dispose(); - _mappedDrive?.Dispose(); + _mappedDrive.Value?.Dispose(); } /// @@ -804,8 +804,7 @@ public void ProjectGetterResultsInDriveEnumerationException(string unevaluatedIn [InlineData(@"%DRIVE%:\**\*.cs")] public void ProjectGetterResultsInWindowsDriveEnumerationWarning(string unevaluatedInclude) { - var mappedDrive = GetDummyMappedDrive(); - unevaluatedInclude = UpdatePathToMappedDrive(unevaluatedInclude, mappedDrive.MappedDriveLetter); + unevaluatedInclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.Value.MappedDriveLetter); ProjectGetterResultsInDriveEnumerationWarning(unevaluatedInclude); } @@ -898,35 +897,12 @@ public void ThrowExceptionUponProjectInstanceCreationFromDriveEnumeratingContent @"%DRIVE%:\$(Microsoft_WindowsAzure_EngSys)**")] public void LogWindowsWarningUponProjectInstanceCreationFromDriveEnumeratingContent(string content, string placeHolder, string excludePlaceHolder = null) { - var mappedDrive = GetDummyMappedDrive(); - placeHolder = UpdatePathToMappedDrive(placeHolder, mappedDrive.MappedDriveLetter); - excludePlaceHolder = UpdatePathToMappedDrive(excludePlaceHolder, mappedDrive.MappedDriveLetter); + placeHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.Value.MappedDriveLetter); + excludePlaceHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(excludePlaceHolder, _mappedDrive.Value.MappedDriveLetter); content = string.Format(content, placeHolder, excludePlaceHolder); CleanContentsAndCreateProjectInstanceFromFileWithDriveEnumeratingWildcard(content, false); } - private DummyMappedDrive GetDummyMappedDrive() - { - if (NativeMethods.IsWindows) - { - // let's create the mapped drive only once it's needed by any test, then let's reuse; - _mappedDrive ??= new DummyMappedDrive(); - } - - return _mappedDrive; - } - - private static string UpdatePathToMappedDrive(string path, char driveLetter) - { - const string drivePlaceholder = "%DRIVE%"; - // if this seems to be rooted path - replace with the dummy mount - if (!string.IsNullOrEmpty(path) && path.StartsWith(drivePlaceholder)) - { - path = driveLetter + path.Substring(drivePlaceholder.Length); - } - return path; - } - [UnixOnlyTheory] [ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")] [InlineData( @@ -968,7 +944,7 @@ private static void CreateProjectInstanceFromFileWithDriveEnumeratingWildcard(Te { try { - // Reset state + // Reset state Helpers.ResetStateForDriveEnumeratingWildcardTests(env, throwException ? "1" : "0"); if (throwException) @@ -3782,10 +3758,10 @@ public void FileNameMetadataEvaluationShouldNotDependsFromPlatformSpecificSlashe public class ProjectItemWithOptimizations_Tests : ProjectItem_Tests { - public ProjectItemWithOptimizations_Tests() - { - // Make sure we always use the dictionary-based Remove logic. - _env.SetEnvironmentVariable("MSBUILDDICTIONARYBASEDITEMREMOVETHRESHOLD", "0"); - } + public ProjectItemWithOptimizations_Tests() + { + // Make sure we always use the dictionary-based Remove logic. + _env.SetEnvironmentVariable("MSBUILDDICTIONARYBASEDITEMREMOVETHRESHOLD", "0"); + } } } diff --git a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs index fbdf4b3742f..44a917968a2 100644 --- a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs +++ b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs @@ -12,6 +12,7 @@ using Microsoft.Build.Execution; using Microsoft.Build.Framework; using Microsoft.Build.Shared; +using Microsoft.Build.UnitTests.Shared; using Shouldly; using Xunit; using Xunit.NetCore.Extensions; @@ -24,12 +25,19 @@ namespace Microsoft.Build.UnitTests.OM.Instance /// /// Tests for ProjectItemInstance public members /// - public class ProjectItemInstance_Tests + public class ProjectItemInstance_Tests : IDisposable { /// /// The number of built-in metadata for items. /// public const int BuiltInMetadataCount = 15; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); + + + public void Dispose() + { + _mappedDrive.Value?.Dispose(); + } internal const string TargetItemWithInclude = @" @@ -999,33 +1007,30 @@ public void ThrowExceptionUponBuildingProjectWithDriveEnumeration(string content /// /// Log warning for drive enumerating wildcards that exist in projects on Windows platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] [WindowsOnlyTheory] [InlineData( TargetItemWithIncludeAndExclude, - @"z:$(Microsoft_WindowsAzure_EngSys)\**\*", + @"%DRIVE%:$(Microsoft_WindowsAzure_EngSys)\**\*", @"$(Microsoft_WindowsAzure_EngSys)\*.pdb;$(Microsoft_WindowsAzure_EngSys)\Microsoft.WindowsAzure.Storage.dll;$(Microsoft_WindowsAzure_EngSys)\Certificates\**\*")] - [InlineData( - TargetItemWithIncludeAndExclude, - @"$(Microsoft_WindowsAzure_EngSys)\*.pdb", - @"z:$(Microsoft_WindowsAzure_EngSys)\**\*")] - [InlineData( TargetWithDefinedPropertyAndItemWithInclude, @"$(Microsoft_WindowsAzure_EngSys)**", null, "Microsoft_WindowsAzure_EngSys", - @"z:\")] + @"%DRIVE%:\")] [InlineData( TargetWithDefinedPropertyAndItemWithInclude, @"$(Microsoft_WindowsAzure_EngSys)\**\*", null, "Microsoft_WindowsAzure_EngSys", - @"z:")] + @"%DRIVE%:")] public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string content, string include, string exclude = null, string property = null, string propertyValue = null) { + include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.Value.MappedDriveLetter); + exclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(exclude, _mappedDrive.Value.MappedDriveLetter); + propertyValue = DummyMappedDriveUtils.UpdatePathToMappedDrive(propertyValue, _mappedDrive.Value.MappedDriveLetter); content = (string.IsNullOrEmpty(property) && string.IsNullOrEmpty(propertyValue)) ? string.Format(content, include, exclude) : string.Format(content, property, propertyValue, include); @@ -1040,7 +1045,7 @@ public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string cont /// /// Log warning for drive enumerating wildcards that exist in projects on Unix platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] + [ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")] [UnixOnlyTheory] [InlineData( TargetWithDefinedPropertyAndItemWithInclude, diff --git a/src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj b/src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj index 57cba86c10c..f70d2b50fdb 100644 --- a/src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj +++ b/src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj @@ -81,6 +81,7 @@ + App.config Designer diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj index 92fc5c72239..9c8b26eafaf 100644 --- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj +++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj @@ -7,7 +7,7 @@ Microsoft.Build.Engine.UnitTests $(DefineConstants);MICROSOFT_BUILD_ENGINE_UNITTESTS - + $(DefineConstants);NO_MSBUILDTASKHOST @@ -21,16 +21,14 @@ - + all - + @@ -48,8 +46,7 @@ TargetFramework=$(LatestDotNetCoreForMSBuild) - + @@ -85,6 +82,9 @@ true + + + true @@ -144,14 +144,14 @@ - + @(PortableTaskResolvedProjectReferencePath->'%(RootDir)%(Directory)') @(TaskWithDependencyResolvedProjectReferencePath->'%(RootDir)%(Directory)') @@ -163,7 +163,7 @@ - + @@ -171,7 +171,7 @@ PreserveNewest - + diff --git a/src/Shared/UnitTests/FileMatcher_Tests.cs b/src/Shared/UnitTests/FileMatcher_Tests.cs index 26e8d9bd848..5e5c6aca707 100644 --- a/src/Shared/UnitTests/FileMatcher_Tests.cs +++ b/src/Shared/UnitTests/FileMatcher_Tests.cs @@ -10,6 +10,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Shared; using Microsoft.Build.Shared.FileSystem; +using Microsoft.Build.UnitTests.Shared; using Shouldly; using Xunit; using Xunit.Abstractions; @@ -22,6 +23,7 @@ namespace Microsoft.Build.UnitTests public class FileMatcherTest : IDisposable { private readonly TestEnvironment _env; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); public FileMatcherTest(ITestOutputHelper output) { @@ -31,6 +33,7 @@ public FileMatcherTest(ITestOutputHelper output) public void Dispose() { _env.Dispose(); + _mappedDrive.Value?.Dispose(); } [Theory] @@ -1377,18 +1380,19 @@ private void DriveEnumeratingWildcardFailsAndReturns(string directoryPart, strin } } - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] [WindowsOnlyTheory] - [InlineData(@"z:\**")] - [InlineData(@"z:\\**")] - [InlineData(@"z:\\\\\\\\**")] - [InlineData(@"z:\**\*.cs")] + [InlineData(@"%DRIVE%:\**")] + [InlineData(@"%DRIVE%:\\**")] + [InlineData(@"%DRIVE%:\\\\\\\\**")] + [InlineData(@"%DRIVE%:\**\*.cs")] public void DriveEnumeratingWildcardIsLoggedOnWindows(string driveEnumeratingWildcard) { using (var env = TestEnvironment.Create()) { try { + driveEnumeratingWildcard = DummyMappedDriveUtils.UpdatePathToMappedDrive(driveEnumeratingWildcard, _mappedDrive.Value.MappedDriveLetter); + // Set env var to log on drive enumerating wildcard detection Helpers.ResetStateForDriveEnumeratingWildcardTests(env, "0"); diff --git a/src/Tasks.UnitTests/CreateItem_Tests.cs b/src/Tasks.UnitTests/CreateItem_Tests.cs index 69f481a1cf7..de09dcbc85e 100644 --- a/src/Tasks.UnitTests/CreateItem_Tests.cs +++ b/src/Tasks.UnitTests/CreateItem_Tests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; using System.IO; using Microsoft.Build.Definition; @@ -9,6 +10,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Shared; using Microsoft.Build.Tasks; +using Microsoft.Build.UnitTests.Shared; using Microsoft.Build.Utilities; using Shouldly; using Xunit; @@ -19,7 +21,7 @@ namespace Microsoft.Build.UnitTests { - public sealed class CreateItem_Tests + public sealed class CreateItem_Tests : IDisposable { internal const string CreateItemWithInclude = @" @@ -32,6 +34,12 @@ public sealed class CreateItem_Tests "; private readonly ITestOutputHelper _testOutput; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); + + public void Dispose() + { + _mappedDrive.Value?.Dispose(); + } public CreateItem_Tests(ITestOutputHelper output) { @@ -146,7 +154,7 @@ public void CaseDoesntMatter() } /// - /// Using the CreateItem task to expand wildcards, and then try accessing the RecursiveDir + /// Using the CreateItem task to expand wildcards, and then try accessing the RecursiveDir /// metadata to force batching. /// [Fact] @@ -313,20 +321,20 @@ public void WildcardDriveEnumerationTaskItemLogsError(string itemSpec) /// /// Logs warning when encountering wildcard drive enumeration during task item creation on Windows platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] [WindowsOnlyTheory] - [InlineData(@"z:\**")] - [InlineData(@"z:\**\*.log")] - [InlineData(@"z:\\\\**\*.log")] + [InlineData(@"%DRIVE%:\**")] + [InlineData(@"%DRIVE%:\**\*.log")] + [InlineData(@"%DRIVE%:\\\\**\*.log")] public void LogWindowsWarningUponCreateItemExecution(string itemSpec) { + itemSpec = DummyMappedDriveUtils.UpdatePathToMappedDrive(itemSpec, _mappedDrive.Value.MappedDriveLetter); VerifyDriveEnumerationWarningLoggedUponCreateItemExecution(itemSpec); } /// /// Logs warning when encountering wildcard drive enumeration during task item creation on Unix platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] + [ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")] [UnixOnlyTheory] [InlineData(@"\**")] [InlineData(@"\**\*.log")] @@ -391,21 +399,21 @@ public void ThrowExceptionUponItemCreationWithDriveEnumeration(string content, s /// /// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Windows platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] [WindowsOnlyTheory] [InlineData( CreateItemWithInclude, - @"z:\**")] + @"%DRIVE%:\**")] [InlineData( CreateItemWithInclude, - @"z:\**\*.txt")] + @"%DRIVE%:\**\*.txt")] [InlineData( CreateItemWithInclude, - @"z:$(empty)\**\*.cs")] + @"%DRIVE%:$(empty)\**\*.cs")] public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content, string include) { + include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.Value.MappedDriveLetter); content = string.Format(content, include); Helpers.CleanContentsAndBuildTargetWithDriveEnumeratingWildcard( content, @@ -418,7 +426,7 @@ public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content /// /// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Unix platform. /// - [ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")] + [ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")] [UnixOnlyTheory] [InlineData( CreateItemWithInclude, diff --git a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj index a69b7fa2ea3..30c76c3b851 100644 --- a/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj +++ b/src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj @@ -58,6 +58,9 @@ + + + Shared\LongPathSupportDisabledFactAttribute.cs diff --git a/src/UnitTests.Shared/DummyMappedDriveUtils.cs b/src/UnitTests.Shared/DummyMappedDriveUtils.cs new file mode 100644 index 00000000000..c2c28c8f0e5 --- /dev/null +++ b/src/UnitTests.Shared/DummyMappedDriveUtils.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable +using System; +using Microsoft.Build.Framework; +using Microsoft.Build.UnitTests.Shared; + +namespace Microsoft.Build.UnitTests.Shared; + +internal static class DummyMappedDriveUtils +{ + public static string UpdatePathToMappedDrive(string path, char driveLetter) + { + const string drivePlaceholder = "%DRIVE%"; + // if this seems to be rooted path - replace with the dummy mount + if (!string.IsNullOrEmpty(path) && path.StartsWith(drivePlaceholder)) + { + path = driveLetter + path.Substring(drivePlaceholder.Length); + } + return path; + } + + public static Lazy GetLazyDummyMappedDrive() => new Lazy(() => + { + return NativeMethods.IsWindows ? new DummyMappedDrive() : default; + }); +}