Skip to content

Commit 02017ac

Browse files
authored
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 4ec8852 commit 02017ac

File tree

8 files changed

+100
-75
lines changed

8 files changed

+100
-75
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: 12 additions & 12 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

@@ -21,16 +21,14 @@
2121
<PackageReference Include="Shouldly" />
2222
<PackageReference Include="System.Net.Http" />
2323
<PackageReference Include="Microsoft.CodeAnalysis.Build.Tasks" />
24-
<PackageReference Include="NuGet.Frameworks" >
24+
<PackageReference Include="NuGet.Frameworks">
2525
<PrivateAssets>all</PrivateAssets>
2626
</PackageReference>
2727

2828
<ProjectReference Include="..\Build\Microsoft.Build.csproj" />
2929
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" />
3030
<ProjectReference Include="..\MSBuild\MSBuild.csproj" />
31-
<ProjectReference Include="..\MSBuildTaskHost\MSBuildTaskHost.csproj"
32-
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(MonoBuild)' != 'true'"
33-
Aliases="MSBuildTaskHost" />
31+
<ProjectReference Include="..\MSBuildTaskHost\MSBuildTaskHost.csproj" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(MonoBuild)' != 'true'" Aliases="MSBuildTaskHost" />
3432
<ProjectReference Include="..\Tasks\Microsoft.Build.Tasks.csproj" />
3533
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj" />
3634
<ProjectReference Include="..\Xunit.NetCore.Extensions\Xunit.NetCore.Extensions.csproj" />
@@ -48,8 +46,7 @@
4846
<SetTargetFramework Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">TargetFramework=$(LatestDotNetCoreForMSBuild)</SetTargetFramework>
4947
</ProjectReference>
5048

51-
<Reference Include="System.IO.Compression"
52-
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' " />
49+
<Reference Include="System.IO.Compression" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' " />
5350
</ItemGroup>
5451

5552
<ItemGroup>
@@ -85,6 +82,9 @@
8582
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs">
8683
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
8784
</Compile>
85+
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
86+
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
87+
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs" />
8888
<Compile Include="..\Shared\UnitTests\StreamHelpers.cs">
8989
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
9090
</Compile>
@@ -144,14 +144,14 @@
144144
<!-- In TypeLoader, the following logic is used for loading assemblies on .NET Core:
145145
- 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
146146
- otherwise, the assembly from the user specified path is loaded, if it exists.
147-
147+
148148
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
149-
target puts them in subfolders of the test output folder instead.
149+
target puts them in subfolders of the test output folder instead.
150150
-->
151151

152152
<Error Condition="'@(PortableTaskResolvedProjectReferencePath)' == ''" Text="Couldn't find PortableTaskResolvedProjectReferencePath item for PortableTask" />
153153
<Error Condition="'@(TaskWithDependencyResolvedProjectReferencePath)' == ''" Text="Couldn't find TaskWithDependencyResolvedProjectReferencePath item for TaskWithDependency" />
154-
154+
155155
<PropertyGroup>
156156
<PortableTaskOutputPath>@(PortableTaskResolvedProjectReferencePath->'%(RootDir)%(Directory)')</PortableTaskOutputPath>
157157
<TaskWithDependencyOutputPath>@(TaskWithDependencyResolvedProjectReferencePath->'%(RootDir)%(Directory)')</TaskWithDependencyOutputPath>
@@ -163,15 +163,15 @@
163163
<TaskWithDependencyContentContent Include="$(TaskWithDependencyOutputPath)*.*" />
164164
<Content Include="@(TaskWithDependencyContentContent)" Link="TaskWithDependency\%(TaskWithDependencyContentContent.Filename)%(TaskWithDependencyContentContent.Extension)" CopyToOutputDirectory="PreserveNewest" />
165165
</ItemGroup>
166-
166+
167167
</Target>
168168

169169
<ItemDefinitionGroup>
170170
<Content>
171171
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
172172
</Content>
173173
</ItemDefinitionGroup>
174-
174+
175175
<ItemGroup>
176176
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
177177
</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

0 commit comments

Comments
 (0)