From 06b5bff9eb6de084d1552d773d2768b15aa72150 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 26 Sep 2023 11:07:41 +0800 Subject: [PATCH 1/7] Enable Disabled Drive Enumartion Tests --- .../Definition/ProjectItem_Tests.cs | 36 ++++------------- ...Microsoft.Build.Engine.OM.UnitTests.csproj | 1 + src/UnitTests.Shared/DummyMappedDriveUtils.cs | 39 +++++++++++++++++++ 3 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 src/UnitTests.Shared/DummyMappedDriveUtils.cs diff --git a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs index da4e8adc444..8a33ff373f7 100644 --- a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs +++ b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs @@ -804,8 +804,9 @@ public void ProjectGetterResultsInDriveEnumerationException(string unevaluatedIn [InlineData(@"%DRIVE%:\**\*.cs")] public void ProjectGetterResultsInWindowsDriveEnumerationWarning(string unevaluatedInclude) { - var mappedDrive = GetDummyMappedDrive(); - unevaluatedInclude = UpdatePathToMappedDrive(unevaluatedInclude, mappedDrive.MappedDriveLetter); + var mappedDriveUtils = new DummyMappedDriveUtils(_mappedDrive); + var mappedDrive = mappedDriveUtils.GetDummyMappedDrive(); + unevaluatedInclude = mappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, mappedDrive.MappedDriveLetter); ProjectGetterResultsInDriveEnumerationWarning(unevaluatedInclude); } @@ -898,35 +899,14 @@ 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); + var mappedDriveUtils = new DummyMappedDriveUtils(_mappedDrive); + _mappedDrive = mappedDriveUtils.GetDummyMappedDrive(); + placeHolder = mappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.MappedDriveLetter); + excludePlaceHolder = mappedDriveUtils.UpdatePathToMappedDrive(excludePlaceHolder, _mappedDrive.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 +948,7 @@ private static void CreateProjectInstanceFromFileWithDriveEnumeratingWildcard(Te { try { - // Reset state + // Reset state Helpers.ResetStateForDriveEnumeratingWildcardTests(env, throwException ? "1" : "0"); if (throwException) 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/UnitTests.Shared/DummyMappedDriveUtils.cs b/src/UnitTests.Shared/DummyMappedDriveUtils.cs new file mode 100644 index 00000000000..5189ed28a96 --- /dev/null +++ b/src/UnitTests.Shared/DummyMappedDriveUtils.cs @@ -0,0 +1,39 @@ +// 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; + +public class DummyMappedDriveUtils +{ + private DummyMappedDrive _mappedDrive; + + public DummyMappedDriveUtils(DummyMappedDrive mappedDrive) + { + _mappedDrive = mappedDrive; + } + + public DummyMappedDrive GetDummyMappedDrive() + { + if (NativeMethods.IsWindows) + { + _mappedDrive ??= new DummyMappedDrive(); + } + + return _mappedDrive; + } + public 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; + } +} From 9eeeaad611ddc66be341d3f22fc0c55221a1bd31 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 26 Sep 2023 17:33:31 +0800 Subject: [PATCH 2/7] Enable More cases --- .../Definition/ProjectItem_Tests.cs | 22 ++++++------- .../Instance/ProjectItemInstance_Tests.cs | 23 +++++++++---- .../Microsoft.Build.Engine.UnitTests.csproj | 24 +++++++------- src/Shared/UnitTests/FileMatcher_Tests.cs | 15 ++++++--- src/Tasks.UnitTests/CreateItem_Tests.cs | 32 ++++++++++++------- .../Microsoft.Build.Tasks.UnitTests.csproj | 3 ++ src/UnitTests.Shared/DummyMappedDriveUtils.cs | 17 +++------- 7 files changed, 76 insertions(+), 60 deletions(-) diff --git a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs index 8a33ff373f7..f25964ee46b 100644 --- a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs +++ b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs @@ -804,9 +804,8 @@ public void ProjectGetterResultsInDriveEnumerationException(string unevaluatedIn [InlineData(@"%DRIVE%:\**\*.cs")] public void ProjectGetterResultsInWindowsDriveEnumerationWarning(string unevaluatedInclude) { - var mappedDriveUtils = new DummyMappedDriveUtils(_mappedDrive); - var mappedDrive = mappedDriveUtils.GetDummyMappedDrive(); - unevaluatedInclude = mappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, mappedDrive.MappedDriveLetter); + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + unevaluatedInclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.MappedDriveLetter); ProjectGetterResultsInDriveEnumerationWarning(unevaluatedInclude); } @@ -899,10 +898,9 @@ public void ThrowExceptionUponProjectInstanceCreationFromDriveEnumeratingContent @"%DRIVE%:\$(Microsoft_WindowsAzure_EngSys)**")] public void LogWindowsWarningUponProjectInstanceCreationFromDriveEnumeratingContent(string content, string placeHolder, string excludePlaceHolder = null) { - var mappedDriveUtils = new DummyMappedDriveUtils(_mappedDrive); - _mappedDrive = mappedDriveUtils.GetDummyMappedDrive(); - placeHolder = mappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.MappedDriveLetter); - excludePlaceHolder = mappedDriveUtils.UpdatePathToMappedDrive(excludePlaceHolder, _mappedDrive.MappedDriveLetter); + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + placeHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.MappedDriveLetter); + excludePlaceHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(excludePlaceHolder, _mappedDrive.MappedDriveLetter); content = string.Format(content, placeHolder, excludePlaceHolder); CleanContentsAndCreateProjectInstanceFromFileWithDriveEnumeratingWildcard(content, false); } @@ -3762,10 +3760,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..f369bdcf7b2 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,18 @@ 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 DummyMappedDrive _mappedDrive = null; + + public void Dispose() + { + _mappedDrive?.Dispose(); + } internal const string TargetItemWithInclude = @" @@ -999,33 +1006,36 @@ 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)\**\*")] + @"%DRIVE%:$(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) { + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.MappedDriveLetter); + exclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(exclude, _mappedDrive.MappedDriveLetter); + propertyValue = DummyMappedDriveUtils.UpdatePathToMappedDrive(propertyValue, _mappedDrive.MappedDriveLetter); content = (string.IsNullOrEmpty(property) && string.IsNullOrEmpty(propertyValue)) ? string.Format(content, include, exclude) : string.Format(content, property, propertyValue, include); @@ -1040,7 +1050,6 @@ 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")] [UnixOnlyTheory] [InlineData( TargetWithDefinedPropertyAndItemWithInclude, 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..6cd03095002 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 DummyMappedDrive _mappedDrive = null; public FileMatcherTest(ITestOutputHelper output) { @@ -31,6 +33,7 @@ public FileMatcherTest(ITestOutputHelper output) public void Dispose() { _env.Dispose(); + _mappedDrive?.Dispose(); } [Theory] @@ -1377,18 +1380,20 @@ 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 { + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + driveEnumeratingWildcard = DummyMappedDriveUtils.UpdatePathToMappedDrive(driveEnumeratingWildcard, _mappedDrive.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..640de5d7e97 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 DummyMappedDrive _mappedDrive = null; + + public void Dispose() + { + _mappedDrive?.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) { + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + itemSpec = DummyMappedDriveUtils.UpdatePathToMappedDrive(itemSpec, _mappedDrive.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")] [UnixOnlyTheory] [InlineData(@"\**")] [InlineData(@"\**\*.log")] @@ -391,21 +399,22 @@ 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) { + _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); + include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.MappedDriveLetter); content = string.Format(content, include); Helpers.CleanContentsAndBuildTargetWithDriveEnumeratingWildcard( content, @@ -418,7 +427,6 @@ 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")] [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 index 5189ed28a96..95e518743ec 100644 --- a/src/UnitTests.Shared/DummyMappedDriveUtils.cs +++ b/src/UnitTests.Shared/DummyMappedDriveUtils.cs @@ -8,25 +8,18 @@ namespace Microsoft.Build.UnitTests.Shared; -public class DummyMappedDriveUtils +public static class DummyMappedDriveUtils { - private DummyMappedDrive _mappedDrive; - - public DummyMappedDriveUtils(DummyMappedDrive mappedDrive) - { - _mappedDrive = mappedDrive; - } - - public DummyMappedDrive GetDummyMappedDrive() + public static DummyMappedDrive GetDummyMappedDrive(DummyMappedDrive mappedDrive) { if (NativeMethods.IsWindows) { - _mappedDrive ??= new DummyMappedDrive(); + mappedDrive ??= new DummyMappedDrive(); } - return _mappedDrive; + return mappedDrive; } - public string UpdatePathToMappedDrive(string path, char driveLetter) + public static string UpdatePathToMappedDrive(string path, char driveLetter) { const string drivePlaceholder = "%DRIVE%"; // if this seems to be rooted path - replace with the dummy mount From db1f16fdbb928c32771bd9e542fe0c8bc1e47cf1 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Tue, 26 Sep 2023 18:43:24 +0800 Subject: [PATCH 3/7] Remove the test data without warning --- src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs index f369bdcf7b2..6adb0cea0bb 100644 --- a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs +++ b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs @@ -1012,11 +1012,6 @@ public void ThrowExceptionUponBuildingProjectWithDriveEnumeration(string content @"%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", - @"%DRIVE%:$(Microsoft_WindowsAzure_EngSys)\**\*")] - [InlineData( TargetWithDefinedPropertyAndItemWithInclude, @"$(Microsoft_WindowsAzure_EngSys)**", From 7129b63bf3b159fa8a428857cf161c1584e11e7c Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Wed, 27 Sep 2023 10:51:39 +0800 Subject: [PATCH 4/7] Disable ProjectItemInstance_Tests.cs unix since long time run --- src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs index 6adb0cea0bb..4f11e13700c 100644 --- a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs +++ b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs @@ -1045,6 +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")] [UnixOnlyTheory] [InlineData( TargetWithDefinedPropertyAndItemWithInclude, From ff98901d7822b41c8808313409697ebedf004348 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Wed, 27 Sep 2023 12:36:16 +0800 Subject: [PATCH 5/7] Associate the unixt long time run test with issue8373 --- src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs | 2 +- src/Tasks.UnitTests/CreateItem_Tests.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs index 4f11e13700c..c493980e55e 100644 --- a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs +++ b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs @@ -1045,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/Tasks.UnitTests/CreateItem_Tests.cs b/src/Tasks.UnitTests/CreateItem_Tests.cs index 640de5d7e97..ae76cdde716 100644 --- a/src/Tasks.UnitTests/CreateItem_Tests.cs +++ b/src/Tasks.UnitTests/CreateItem_Tests.cs @@ -427,6 +427,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/8373")] [UnixOnlyTheory] [InlineData( CreateItemWithInclude, From 4cf143b460b71686aaa978f5e2bf35d7208b7c58 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Wed, 27 Sep 2023 13:44:42 +0800 Subject: [PATCH 6/7] Associate the unixt long time run test with issue8373 --- src/Tasks.UnitTests/CreateItem_Tests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tasks.UnitTests/CreateItem_Tests.cs b/src/Tasks.UnitTests/CreateItem_Tests.cs index ae76cdde716..72445450acf 100644 --- a/src/Tasks.UnitTests/CreateItem_Tests.cs +++ b/src/Tasks.UnitTests/CreateItem_Tests.cs @@ -335,6 +335,7 @@ public void LogWindowsWarningUponCreateItemExecution(string itemSpec) /// /// Logs warning when encountering wildcard drive enumeration during task item creation on Unix platform. /// + [ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")] [UnixOnlyTheory] [InlineData(@"\**")] [InlineData(@"\**\*.log")] From c6d8652253cdcaa423ce59c0e93888e8a5ef9209 Mon Sep 17 00:00:00 2001 From: Jenny Bai Date: Sun, 8 Oct 2023 17:52:29 +0800 Subject: [PATCH 7/7] Resovle the confusion of the ownership --- .../Definition/ProjectItem_Tests.cs | 12 +++++------- .../Instance/ProjectItemInstance_Tests.cs | 12 ++++++------ src/Shared/UnitTests/FileMatcher_Tests.cs | 7 +++---- src/Tasks.UnitTests/CreateItem_Tests.cs | 10 ++++------ src/UnitTests.Shared/DummyMappedDriveUtils.cs | 16 ++++++---------- 5 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs b/src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs index f25964ee46b..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) { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - unevaluatedInclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.MappedDriveLetter); + unevaluatedInclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.Value.MappedDriveLetter); ProjectGetterResultsInDriveEnumerationWarning(unevaluatedInclude); } @@ -898,9 +897,8 @@ public void ThrowExceptionUponProjectInstanceCreationFromDriveEnumeratingContent @"%DRIVE%:\$(Microsoft_WindowsAzure_EngSys)**")] public void LogWindowsWarningUponProjectInstanceCreationFromDriveEnumeratingContent(string content, string placeHolder, string excludePlaceHolder = null) { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - placeHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.MappedDriveLetter); - excludePlaceHolder = DummyMappedDriveUtils.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); } diff --git a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs index c493980e55e..44a917968a2 100644 --- a/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs +++ b/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs @@ -31,11 +31,12 @@ public class ProjectItemInstance_Tests : IDisposable /// The number of built-in metadata for items. /// public const int BuiltInMetadataCount = 15; - private DummyMappedDrive _mappedDrive = null; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); + public void Dispose() { - _mappedDrive?.Dispose(); + _mappedDrive.Value?.Dispose(); } internal const string TargetItemWithInclude = @" @@ -1027,10 +1028,9 @@ public void ThrowExceptionUponBuildingProjectWithDriveEnumeration(string content @"%DRIVE%:")] public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string content, string include, string exclude = null, string property = null, string propertyValue = null) { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.MappedDriveLetter); - exclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(exclude, _mappedDrive.MappedDriveLetter); - propertyValue = DummyMappedDriveUtils.UpdatePathToMappedDrive(propertyValue, _mappedDrive.MappedDriveLetter); + 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); diff --git a/src/Shared/UnitTests/FileMatcher_Tests.cs b/src/Shared/UnitTests/FileMatcher_Tests.cs index 6cd03095002..5e5c6aca707 100644 --- a/src/Shared/UnitTests/FileMatcher_Tests.cs +++ b/src/Shared/UnitTests/FileMatcher_Tests.cs @@ -23,7 +23,7 @@ namespace Microsoft.Build.UnitTests public class FileMatcherTest : IDisposable { private readonly TestEnvironment _env; - private DummyMappedDrive _mappedDrive = null; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); public FileMatcherTest(ITestOutputHelper output) { @@ -33,7 +33,7 @@ public FileMatcherTest(ITestOutputHelper output) public void Dispose() { _env.Dispose(); - _mappedDrive?.Dispose(); + _mappedDrive.Value?.Dispose(); } [Theory] @@ -1391,8 +1391,7 @@ public void DriveEnumeratingWildcardIsLoggedOnWindows(string driveEnumeratingWil { try { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - driveEnumeratingWildcard = DummyMappedDriveUtils.UpdatePathToMappedDrive(driveEnumeratingWildcard, _mappedDrive.MappedDriveLetter); + 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 72445450acf..de09dcbc85e 100644 --- a/src/Tasks.UnitTests/CreateItem_Tests.cs +++ b/src/Tasks.UnitTests/CreateItem_Tests.cs @@ -34,11 +34,11 @@ public sealed class CreateItem_Tests : IDisposable "; private readonly ITestOutputHelper _testOutput; - private DummyMappedDrive _mappedDrive = null; + private Lazy _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive(); public void Dispose() { - _mappedDrive?.Dispose(); + _mappedDrive.Value?.Dispose(); } public CreateItem_Tests(ITestOutputHelper output) @@ -327,8 +327,7 @@ public void WildcardDriveEnumerationTaskItemLogsError(string itemSpec) [InlineData(@"%DRIVE%:\\\\**\*.log")] public void LogWindowsWarningUponCreateItemExecution(string itemSpec) { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - itemSpec = DummyMappedDriveUtils.UpdatePathToMappedDrive(itemSpec, _mappedDrive.MappedDriveLetter); + itemSpec = DummyMappedDriveUtils.UpdatePathToMappedDrive(itemSpec, _mappedDrive.Value.MappedDriveLetter); VerifyDriveEnumerationWarningLoggedUponCreateItemExecution(itemSpec); } @@ -414,8 +413,7 @@ public void ThrowExceptionUponItemCreationWithDriveEnumeration(string content, s @"%DRIVE%:$(empty)\**\*.cs")] public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content, string include) { - _mappedDrive = DummyMappedDriveUtils.GetDummyMappedDrive(_mappedDrive); - include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.MappedDriveLetter); + include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.Value.MappedDriveLetter); content = string.Format(content, include); Helpers.CleanContentsAndBuildTargetWithDriveEnumeratingWildcard( content, diff --git a/src/UnitTests.Shared/DummyMappedDriveUtils.cs b/src/UnitTests.Shared/DummyMappedDriveUtils.cs index 95e518743ec..c2c28c8f0e5 100644 --- a/src/UnitTests.Shared/DummyMappedDriveUtils.cs +++ b/src/UnitTests.Shared/DummyMappedDriveUtils.cs @@ -8,17 +8,8 @@ namespace Microsoft.Build.UnitTests.Shared; -public static class DummyMappedDriveUtils +internal static class DummyMappedDriveUtils { - public static DummyMappedDrive GetDummyMappedDrive(DummyMappedDrive mappedDrive) - { - if (NativeMethods.IsWindows) - { - mappedDrive ??= new DummyMappedDrive(); - } - - return mappedDrive; - } public static string UpdatePathToMappedDrive(string path, char driveLetter) { const string drivePlaceholder = "%DRIVE%"; @@ -29,4 +20,9 @@ public static string UpdatePathToMappedDrive(string path, char driveLetter) } return path; } + + public static Lazy GetLazyDummyMappedDrive() => new Lazy(() => + { + return NativeMethods.IsWindows ? new DummyMappedDrive() : default; + }); }