Skip to content

Commit

Permalink
Enable Windows Disabled Drive Enumeration Tests (#9266)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JaynieBai authored Oct 10, 2023
1 parent 4ec8852 commit 02017ac
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 75 deletions.
46 changes: 11 additions & 35 deletions src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ProjectItem_Tests : IDisposable
";

protected readonly TestEnvironment _env;
private DummyMappedDrive _mappedDrive = null;
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();

public ProjectItem_Tests()
{
Expand All @@ -67,7 +67,7 @@ public ProjectItem_Tests()
public void Dispose()
{
_env.Dispose();
_mappedDrive?.Dispose();
_mappedDrive.Value?.Dispose();
}

/// <summary>
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -968,7 +944,7 @@ private static void CreateProjectInstanceFromFileWithDriveEnumeratingWildcard(Te
{
try
{
// Reset state
// Reset state
Helpers.ResetStateForDriveEnumeratingWildcardTests(env, throwException ? "1" : "0");

if (throwException)
Expand Down Expand Up @@ -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");
}
}
}
27 changes: 16 additions & 11 deletions src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,12 +25,19 @@ namespace Microsoft.Build.UnitTests.OM.Instance
/// <summary>
/// Tests for ProjectItemInstance public members
/// </summary>
public class ProjectItemInstance_Tests
public class ProjectItemInstance_Tests : IDisposable
{
/// <summary>
/// The number of built-in metadata for items.
/// </summary>
public const int BuiltInMetadataCount = 15;
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();


public void Dispose()
{
_mappedDrive.Value?.Dispose();
}

internal const string TargetItemWithInclude = @"
<Project>
Expand Down Expand Up @@ -999,33 +1007,30 @@ public void ThrowExceptionUponBuildingProjectWithDriveEnumeration(string content
/// <summary>
/// Log warning for drive enumerating wildcards that exist in projects on Windows platform.
/// </summary>
[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);
Expand All @@ -1040,7 +1045,7 @@ public void LogWindowsWarningUponBuildingProjectWithDriveEnumeration(string cont
/// <summary>
/// Log warning for drive enumerating wildcards that exist in projects on Unix platform.
/// </summary>
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
[ActiveIssue("https://github.com/dotnet/msbuild/issues/8373")]
[UnixOnlyTheory]
[InlineData(
TargetWithDefinedPropertyAndItemWithInclude,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs" />
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs"/>
<None Include="..\Shared\UnitTests\App.config">
<Link>App.config</Link>
<SubType>Designer</SubType>
Expand Down
24 changes: 12 additions & 12 deletions src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyName>Microsoft.Build.Engine.UnitTests</AssemblyName>

<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_ENGINE_UNITTESTS</DefineConstants>

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

Expand All @@ -21,16 +21,14 @@
<PackageReference Include="Shouldly" />
<PackageReference Include="System.Net.Http" />
<PackageReference Include="Microsoft.CodeAnalysis.Build.Tasks" />
<PackageReference Include="NuGet.Frameworks" >
<PackageReference Include="NuGet.Frameworks">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<ProjectReference Include="..\Build\Microsoft.Build.csproj" />
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" />
<ProjectReference Include="..\MSBuild\MSBuild.csproj" />
<ProjectReference Include="..\MSBuildTaskHost\MSBuildTaskHost.csproj"
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(MonoBuild)' != 'true'"
Aliases="MSBuildTaskHost" />
<ProjectReference Include="..\MSBuildTaskHost\MSBuildTaskHost.csproj" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(MonoBuild)' != 'true'" Aliases="MSBuildTaskHost" />
<ProjectReference Include="..\Tasks\Microsoft.Build.Tasks.csproj" />
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj" />
<ProjectReference Include="..\Xunit.NetCore.Extensions\Xunit.NetCore.Extensions.csproj" />
Expand All @@ -48,8 +46,7 @@
<SetTargetFramework Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">TargetFramework=$(LatestDotNetCoreForMSBuild)</SetTargetFramework>
</ProjectReference>

<Reference Include="System.IO.Compression"
Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' " />
<Reference Include="System.IO.Compression" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' " />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -85,6 +82,9 @@
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs" />
<Compile Include="..\Shared\UnitTests\StreamHelpers.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -144,14 +144,14 @@
<!-- In TypeLoader, the following logic is used for loading assemblies on .NET Core:
- 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
- otherwise, the assembly from the user specified path is loaded, if it exists.
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
target puts them in subfolders of the test output folder instead.
target puts them in subfolders of the test output folder instead.
-->

<Error Condition="'@(PortableTaskResolvedProjectReferencePath)' == ''" Text="Couldn't find PortableTaskResolvedProjectReferencePath item for PortableTask" />
<Error Condition="'@(TaskWithDependencyResolvedProjectReferencePath)' == ''" Text="Couldn't find TaskWithDependencyResolvedProjectReferencePath item for TaskWithDependency" />

<PropertyGroup>
<PortableTaskOutputPath>@(PortableTaskResolvedProjectReferencePath->'%(RootDir)%(Directory)')</PortableTaskOutputPath>
<TaskWithDependencyOutputPath>@(TaskWithDependencyResolvedProjectReferencePath->'%(RootDir)%(Directory)')</TaskWithDependencyOutputPath>
Expand All @@ -163,15 +163,15 @@
<TaskWithDependencyContentContent Include="$(TaskWithDependencyOutputPath)*.*" />
<Content Include="@(TaskWithDependencyContentContent)" Link="TaskWithDependency\%(TaskWithDependencyContentContent.Filename)%(TaskWithDependencyContentContent.Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Target>

<ItemDefinitionGroup>
<Content>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemDefinitionGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
Expand Down
14 changes: 9 additions & 5 deletions src/Shared/UnitTests/FileMatcher_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@ namespace Microsoft.Build.UnitTests
public class FileMatcherTest : IDisposable
{
private readonly TestEnvironment _env;
private Lazy<DummyMappedDrive> _mappedDrive = DummyMappedDriveUtils.GetLazyDummyMappedDrive();

public FileMatcherTest(ITestOutputHelper output)
{
Expand All @@ -31,6 +33,7 @@ public FileMatcherTest(ITestOutputHelper output)
public void Dispose()
{
_env.Dispose();
_mappedDrive.Value?.Dispose();
}

[Theory]
Expand Down Expand Up @@ -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");

Expand Down
Loading

0 comments on commit 02017ac

Please sign in to comment.