Skip to content

Commit e4cb483

Browse files
JaynieBaiMichalPavlik
authored andcommitted
Enable Windows Disabled Drive Enumeration Tests (#9266)
Fixes #7330 (plus one subtask of #8329) Changes Made Based on Add ability to create temp mapped drive for integration tests #8366 fixes to enable other Drive enumeration integration tests with a dummy folder in windows Remove one test data https://github.com/dotnet/msbuild/blob/fecef0fdffe59ba8b0251701a23be48bbd552726/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs#L1010-L1012C45 since there is no warning when inlude is not null and exclude with enumerating wildcards. The related logical code is msbuild/src/Build/Utilities/EngineFileUtilities.cs Line 339 in fecef0f private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec) . There is no condition satisfied. Associate unix Enumeration Tests long time run with issue Unix drive enumeration imports not expanded? #8373
1 parent 7098c57 commit e4cb483

File tree

8 files changed

+97
-69
lines changed

8 files changed

+97
-69
lines changed

src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ProjectItem_Tests : IDisposable
5757
";
5858

5959
protected readonly TestEnvironment _env;
60-
private DummyMappedDrive _mappedDrive = null;
60+
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();
6161

6262
public ProjectItem_Tests()
6363
{
@@ -67,7 +67,7 @@ public ProjectItem_Tests()
6767
public void Dispose()
6868
{
6969
_env.Dispose();
70-
_mappedDrive?.Dispose();
70+
_mappedDrive.Value?.Dispose();
7171
}
7272

7373
/// <summary>
@@ -804,8 +804,7 @@ public void ProjectGetterResultsInDriveEnumerationException(string unevaluatedIn
804804
[InlineData(@"%DRIVE%:\**\*.cs")]
805805
public void ProjectGetterResultsInWindowsDriveEnumerationWarning(string unevaluatedInclude)
806806
{
807-
var mappedDrive = GetDummyMappedDrive();
808-
unevaluatedInclude = UpdatePathToMappedDrive(unevaluatedInclude, mappedDrive.MappedDriveLetter);
807+
unevaluatedInclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.Value.MappedDriveLetter);
809808
ProjectGetterResultsInDriveEnumerationWarning(unevaluatedInclude);
810809
}
811810

@@ -898,35 +897,12 @@ public void ThrowExceptionUponProjectInstanceCreationFromDriveEnumeratingContent
898897
@"%DRIVE%:\$(Microsoft_WindowsAzure_EngSys)**")]
899898
public void LogWindowsWarningUponProjectInstanceCreationFromDriveEnumeratingContent(string content, string placeHolder, string excludePlaceHolder = null)
900899
{
901-
var mappedDrive = GetDummyMappedDrive();
902-
placeHolder = UpdatePathToMappedDrive(placeHolder, mappedDrive.MappedDriveLetter);
903-
excludePlaceHolder = UpdatePathToMappedDrive(excludePlaceHolder, mappedDrive.MappedDriveLetter);
900+
placeHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(placeHolder, _mappedDrive.Value.MappedDriveLetter);
901+
excludePlaceHolder = DummyMappedDriveUtils.UpdatePathToMappedDrive(excludePlaceHolder, _mappedDrive.Value.MappedDriveLetter);
904902
content = string.Format(content, placeHolder, excludePlaceHolder);
905903
CleanContentsAndCreateProjectInstanceFromFileWithDriveEnumeratingWildcard(content, false);
906904
}
907905

908-
private DummyMappedDrive GetDummyMappedDrive()
909-
{
910-
if (NativeMethods.IsWindows)
911-
{
912-
// let's create the mapped drive only once it's needed by any test, then let's reuse;
913-
_mappedDrive ??= new DummyMappedDrive();
914-
}
915-
916-
return _mappedDrive;
917-
}
918-
919-
private static string UpdatePathToMappedDrive(string path, char driveLetter)
920-
{
921-
const string drivePlaceholder = "%DRIVE%";
922-
// if this seems to be rooted path - replace with the dummy mount
923-
if (!string.IsNullOrEmpty(path) && path.StartsWith(drivePlaceholder))
924-
{
925-
path = driveLetter + path.Substring(drivePlaceholder.Length);
926-
}
927-
return path;
928-
}
929-
930906
[UnixOnlyTheory]
931907
[ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")]
932908
[InlineData(
@@ -968,7 +944,7 @@ private static void CreateProjectInstanceFromFileWithDriveEnumeratingWildcard(Te
968944
{
969945
try
970946
{
971-
// Reset state
947+
// Reset state
972948
Helpers.ResetStateForDriveEnumeratingWildcardTests(env, throwException ? "1" : "0");
973949

974950
if (throwException)
@@ -3782,10 +3758,10 @@ public void FileNameMetadataEvaluationShouldNotDependsFromPlatformSpecificSlashe
37823758

37833759
public class ProjectItemWithOptimizations_Tests : ProjectItem_Tests
37843760
{
3785-
public ProjectItemWithOptimizations_Tests()
3786-
{
3787-
// Make sure we always use the dictionary-based Remove logic.
3788-
_env.SetEnvironmentVariable("MSBUILDDICTIONARYBASEDITEMREMOVETHRESHOLD", "0");
3789-
}
3761+
public ProjectItemWithOptimizations_Tests()
3762+
{
3763+
// Make sure we always use the dictionary-based Remove logic.
3764+
_env.SetEnvironmentVariable("MSBUILDDICTIONARYBASEDITEMREMOVETHRESHOLD", "0");
3765+
}
37903766
}
37913767
}

src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.Build.Execution;
1313
using Microsoft.Build.Framework;
1414
using Microsoft.Build.Shared;
15+
using Microsoft.Build.UnitTests.Shared;
1516
using Shouldly;
1617
using Xunit;
1718
using Xunit.NetCore.Extensions;
@@ -24,12 +25,19 @@ namespace Microsoft.Build.UnitTests.OM.Instance
2425
/// <summary>
2526
/// Tests for ProjectItemInstance public members
2627
/// </summary>
27-
public class ProjectItemInstance_Tests
28+
public class ProjectItemInstance_Tests : IDisposable
2829
{
2930
/// <summary>
3031
/// The number of built-in metadata for items.
3132
/// </summary>
3233
public const int BuiltInMetadataCount = 15;
34+
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();
35+
36+
37+
public void Dispose()
38+
{
39+
_mappedDrive.Value?.Dispose();
40+
}
3341

3442
internal const string TargetItemWithInclude = @"
3543
<Project>
@@ -999,33 +1007,30 @@ public void ThrowExceptionUponBuildingProjectWithDriveEnumeration(string content
9991007
/// <summary>
10001008
/// Log warning for drive enumerating wildcards that exist in projects on Windows platform.
10011009
/// </summary>
1002-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
10031010
[WindowsOnlyTheory]
10041011
[InlineData(
10051012
TargetItemWithIncludeAndExclude,
1006-
@"z:$(Microsoft_WindowsAzure_EngSys)\**\*",
1013+
@"%DRIVE%:$(Microsoft_WindowsAzure_EngSys)\**\*",
10071014
@"$(Microsoft_WindowsAzure_EngSys)\*.pdb;$(Microsoft_WindowsAzure_EngSys)\Microsoft.WindowsAzure.Storage.dll;$(Microsoft_WindowsAzure_EngSys)\Certificates\**\*")]
10081015

1009-
[InlineData(
1010-
TargetItemWithIncludeAndExclude,
1011-
@"$(Microsoft_WindowsAzure_EngSys)\*.pdb",
1012-
@"z:$(Microsoft_WindowsAzure_EngSys)\**\*")]
1013-
10141016
[InlineData(
10151017
TargetWithDefinedPropertyAndItemWithInclude,
10161018
@"$(Microsoft_WindowsAzure_EngSys)**",
10171019
null,
10181020
"Microsoft_WindowsAzure_EngSys",
1019-
@"z:\")]
1021+
@"%DRIVE%:\")]
10201022

10211023
[InlineData(
10221024
TargetWithDefinedPropertyAndItemWithInclude,
10231025
@"$(Microsoft_WindowsAzure_EngSys)\**\*",
10241026
null,
10251027
"Microsoft_WindowsAzure_EngSys",
1026-
@"z:")]
1028+
@"%DRIVE%:")]
10271029
public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string content, string include, string exclude = null, string property = null, string propertyValue = null)
10281030
{
1031+
include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.Value.MappedDriveLetter);
1032+
exclude = DummyMappedDriveUtils.UpdatePathToMappedDrive(exclude, _mappedDrive.Value.MappedDriveLetter);
1033+
propertyValue = DummyMappedDriveUtils.UpdatePathToMappedDrive(propertyValue, _mappedDrive.Value.MappedDriveLetter);
10291034
content = (string.IsNullOrEmpty(property) && string.IsNullOrEmpty(propertyValue)) ?
10301035
string.Format(content, include, exclude) :
10311036
string.Format(content, property, propertyValue, include);
@@ -1040,7 +1045,7 @@ public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string cont
10401045
/// <summary>
10411046
/// Log warning for drive enumerating wildcards that exist in projects on Unix platform.
10421047
/// </summary>
1043-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
1048+
[ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")]
10441049
[UnixOnlyTheory]
10451050
[InlineData(
10461051
TargetWithDefinedPropertyAndItemWithInclude,

src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs" />
8282
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
8383
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
84+
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs"/>
8485
<None Include="..\Shared\UnitTests\App.config">
8586
<Link>App.config</Link>
8687
<SubType>Designer</SubType>

src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AssemblyName>Microsoft.Build.Engine.UnitTests</AssemblyName>
88

99
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_ENGINE_UNITTESTS</DefineConstants>
10-
10+
1111
<!-- Define a constant so we can skip tests that require MSBuildTaskHost -->
1212
<DefineConstants Condition="'$(MSBuildRuntimeType)' == 'Core' or '$(MonoBuild)' == 'true'">$(DefineConstants);NO_MSBUILDTASKHOST</DefineConstants>
1313

@@ -82,6 +82,9 @@
8282
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs">
8383
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
8484
</Compile>
85+
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
86+
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
87+
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs" />
8588
<Compile Include="..\Shared\UnitTests\StreamHelpers.cs">
8689
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
8790
</Compile>
@@ -141,14 +144,14 @@
141144
<!-- In TypeLoader, the following logic is used for loading assemblies on .NET Core:
142145
- if the simple name of the assembly exists in the same folder as msbuild.exe, then that assembly gets loaded, indifferent of the user specified path
143146
- otherwise, the assembly from the user specified path is loaded, if it exists.
144-
147+
145148
So the custom tasks we are testing can't be in test output folder, because on .NET Core that would affect the loading behavior. So this
146-
target puts them in subfolders of the test output folder instead.
149+
target puts them in subfolders of the test output folder instead.
147150
-->
148151

149152
<Error Condition="'@(PortableTaskResolvedProjectReferencePath)' == ''" Text="Couldn't find PortableTaskResolvedProjectReferencePath item for PortableTask" />
150153
<Error Condition="'@(TaskWithDependencyResolvedProjectReferencePath)' == ''" Text="Couldn't find TaskWithDependencyResolvedProjectReferencePath item for TaskWithDependency" />
151-
154+
152155
<PropertyGroup>
153156
<PortableTaskOutputPath>@(PortableTaskResolvedProjectReferencePath->'%(RootDir)%(Directory)')</PortableTaskOutputPath>
154157
<TaskWithDependencyOutputPath>@(TaskWithDependencyResolvedProjectReferencePath->'%(RootDir)%(Directory)')</TaskWithDependencyOutputPath>
@@ -160,15 +163,15 @@
160163
<TaskWithDependencyContentContent Include="$(TaskWithDependencyOutputPath)*.*" />
161164
<Content Include="@(TaskWithDependencyContentContent)" Link="TaskWithDependency\%(TaskWithDependencyContentContent.Filename)%(TaskWithDependencyContentContent.Extension)" CopyToOutputDirectory="PreserveNewest" />
162165
</ItemGroup>
163-
166+
164167
</Target>
165168

166169
<ItemDefinitionGroup>
167170
<Content>
168171
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
169172
</Content>
170173
</ItemDefinitionGroup>
171-
174+
172175
<ItemGroup>
173176
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
174177
</ItemGroup>

src/Shared/UnitTests/FileMatcher_Tests.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Build.Framework;
1111
using Microsoft.Build.Shared;
1212
using Microsoft.Build.Shared.FileSystem;
13+
using Microsoft.Build.UnitTests.Shared;
1314
using Shouldly;
1415
using Xunit;
1516
using Xunit.Abstractions;
@@ -22,6 +23,7 @@ namespace Microsoft.Build.UnitTests
2223
public class FileMatcherTest : IDisposable
2324
{
2425
private readonly TestEnvironment _env;
26+
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();
2527

2628
public FileMatcherTest(ITestOutputHelper output)
2729
{
@@ -31,6 +33,7 @@ public FileMatcherTest(ITestOutputHelper output)
3133
public void Dispose()
3234
{
3335
_env.Dispose();
36+
_mappedDrive.Value?.Dispose();
3437
}
3538

3639
[Theory]
@@ -1377,18 +1380,19 @@ private void DriveEnumeratingWildcardFailsAndReturns(string directoryPart, strin
13771380
}
13781381
}
13791382

1380-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
13811383
[WindowsOnlyTheory]
1382-
[InlineData(@"z:\**")]
1383-
[InlineData(@"z:\\**")]
1384-
[InlineData(@"z:\\\\\\\\**")]
1385-
[InlineData(@"z:\**\*.cs")]
1384+
[InlineData(@"%DRIVE%:\**")]
1385+
[InlineData(@"%DRIVE%:\\**")]
1386+
[InlineData(@"%DRIVE%:\\\\\\\\**")]
1387+
[InlineData(@"%DRIVE%:\**\*.cs")]
13861388
public void DriveEnumeratingWildcardIsLoggedOnWindows(string driveEnumeratingWildcard)
13871389
{
13881390
using (var env = TestEnvironment.Create())
13891391
{
13901392
try
13911393
{
1394+
driveEnumeratingWildcard = DummyMappedDriveUtils.UpdatePathToMappedDrive(driveEnumeratingWildcard, _mappedDrive.Value.MappedDriveLetter);
1395+
13921396
// Set env var to log on drive enumerating wildcard detection
13931397
Helpers.ResetStateForDriveEnumeratingWildcardTests(env, "0");
13941398

src/Tasks.UnitTests/CreateItem_Tests.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67
using Microsoft.Build.Definition;
@@ -9,6 +10,7 @@
910
using Microsoft.Build.Framework;
1011
using Microsoft.Build.Shared;
1112
using Microsoft.Build.Tasks;
13+
using Microsoft.Build.UnitTests.Shared;
1214
using Microsoft.Build.Utilities;
1315
using Shouldly;
1416
using Xunit;
@@ -19,7 +21,7 @@
1921

2022
namespace Microsoft.Build.UnitTests
2123
{
22-
public sealed class CreateItem_Tests
24+
public sealed class CreateItem_Tests : IDisposable
2325
{
2426
internal const string CreateItemWithInclude = @"
2527
<Project>
@@ -32,6 +34,12 @@ public sealed class CreateItem_Tests
3234
";
3335

3436
private readonly ITestOutputHelper _testOutput;
37+
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();
38+
39+
public void Dispose()
40+
{
41+
_mappedDrive.Value?.Dispose();
42+
}
3543

3644
public CreateItem_Tests(ITestOutputHelper output)
3745
{
@@ -146,7 +154,7 @@ public void CaseDoesntMatter()
146154
}
147155

148156
/// <summary>
149-
/// Using the CreateItem task to expand wildcards, and then try accessing the RecursiveDir
157+
/// Using the CreateItem task to expand wildcards, and then try accessing the RecursiveDir
150158
/// metadata to force batching.
151159
/// </summary>
152160
[Fact]
@@ -313,20 +321,20 @@ public void WildcardDriveEnumerationTaskItemLogsError(string itemSpec)
313321
/// <summary>
314322
/// Logs warning when encountering wildcard drive enumeration during task item creation on Windows platform.
315323
/// </summary>
316-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
317324
[WindowsOnlyTheory]
318-
[InlineData(@"z:\**")]
319-
[InlineData(@"z:\**\*.log")]
320-
[InlineData(@"z:\\\\**\*.log")]
325+
[InlineData(@"%DRIVE%:\**")]
326+
[InlineData(@"%DRIVE%:\**\*.log")]
327+
[InlineData(@"%DRIVE%:\\\\**\*.log")]
321328
public void LogWindowsWarningUponCreateItemExecution(string itemSpec)
322329
{
330+
itemSpec = DummyMappedDriveUtils.UpdatePathToMappedDrive(itemSpec, _mappedDrive.Value.MappedDriveLetter);
323331
VerifyDriveEnumerationWarningLoggedUponCreateItemExecution(itemSpec);
324332
}
325333

326334
/// <summary>
327335
/// Logs warning when encountering wildcard drive enumeration during task item creation on Unix platform.
328336
/// </summary>
329-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
337+
[ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")]
330338
[UnixOnlyTheory]
331339
[InlineData(@"\**")]
332340
[InlineData(@"\**\*.log")]
@@ -391,21 +399,21 @@ public void ThrowExceptionUponItemCreationWithDriveEnumeration(string content, s
391399
/// <summary>
392400
/// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Windows platform.
393401
/// </summary>
394-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
395402
[WindowsOnlyTheory]
396403
[InlineData(
397404
CreateItemWithInclude,
398-
@"z:\**")]
405+
@"%DRIVE%:\**")]
399406

400407
[InlineData(
401408
CreateItemWithInclude,
402-
@"z:\**\*.txt")]
409+
@"%DRIVE%:\**\*.txt")]
403410

404411
[InlineData(
405412
CreateItemWithInclude,
406-
@"z:$(empty)\**\*.cs")]
413+
@"%DRIVE%:$(empty)\**\*.cs")]
407414
public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content, string include)
408415
{
416+
include = DummyMappedDriveUtils.UpdatePathToMappedDrive(include, _mappedDrive.Value.MappedDriveLetter);
409417
content = string.Format(content, include);
410418
Helpers.CleanContentsAndBuildTargetWithDriveEnumeratingWildcard(
411419
content,
@@ -418,7 +426,7 @@ public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content
418426
/// <summary>
419427
/// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Unix platform.
420428
/// </summary>
421-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
429+
[ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")]
422430
[UnixOnlyTheory]
423431
[InlineData(
424432
CreateItemWithInclude,

src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<Compile Include="..\Shared\ProcessExtensions.cs" />
5959
<Compile Include="..\UnitTests.Shared\EnvironmentProvider.cs" />
6060
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs" />
61+
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
62+
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
63+
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs" />
6164
<Compile Include="..\Shared\UnitTests\LongPathSupportDisabledFactAttribute.cs">
6265
<Link>Shared\LongPathSupportDisabledFactAttribute.cs</Link>
6366
</Compile>

0 commit comments

Comments
 (0)