Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Windows Disabled Drive Enumeration Tests #9266

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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