Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Enable More cases
  • Loading branch information
JaynieBai committed Sep 26, 2023
commit 9eeeaad611ddc66be341d3f22fc0c55221a1bd31
22 changes: 10 additions & 12 deletions src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
}
}
23 changes: 16 additions & 7 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,18 @@ 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 DummyMappedDrive _mappedDrive = null;

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

internal const string TargetItemWithInclude = @"
<Project>
Expand Down Expand Up @@ -999,33 +1006,36 @@ 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)\**\*")]
@"%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);
Expand All @@ -1040,7 +1050,6 @@ 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")]
[UnixOnlyTheory]
[InlineData(
TargetWithDefinedPropertyAndItemWithInclude,
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
15 changes: 10 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 DummyMappedDrive _mappedDrive = null;

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

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

Expand Down
32 changes: 20 additions & 12 deletions src/Tasks.UnitTests/CreateItem_Tests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -19,7 +21,7 @@

namespace Microsoft.Build.UnitTests
{
public sealed class CreateItem_Tests
public sealed class CreateItem_Tests : IDisposable
{
internal const string CreateItemWithInclude = @"
<Project>
Expand All @@ -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)
{
Expand Down Expand Up @@ -146,7 +154,7 @@ public void CaseDoesntMatter()
}

/// <summary>
/// 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.
/// </summary>
[Fact]
Expand Down Expand Up @@ -313,20 +321,20 @@ public void WildcardDriveEnumerationTaskItemLogsError(string itemSpec)
/// <summary>
/// Logs warning when encountering wildcard drive enumeration during task item creation on Windows platform.
/// </summary>
[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);
}

/// <summary>
/// Logs warning when encountering wildcard drive enumeration during task item creation on Unix platform.
/// </summary>
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
[UnixOnlyTheory]
[InlineData(@"\**")]
[InlineData(@"\**\*.log")]
Expand Down Expand Up @@ -391,21 +399,22 @@ public void ThrowExceptionUponItemCreationWithDriveEnumeration(string content, s
/// <summary>
/// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Windows platform.
/// </summary>
[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,
Expand All @@ -418,7 +427,6 @@ public void LogWindowsWarningUponItemCreationWithDriveEnumeration(string content
/// <summary>
/// Logs warning when encountering wildcard drive enumeration during CreateItem task execution on Unix platform.
/// </summary>
[ActiveIssue("https://github.com/dotnet/msbuild/issues/7330")]
[UnixOnlyTheory]
[InlineData(
CreateItemWithInclude,
Expand Down
3 changes: 3 additions & 0 deletions src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<Compile Include="..\Shared\ProcessExtensions.cs" />
<Compile Include="..\UnitTests.Shared\EnvironmentProvider.cs" />
<Compile Include="..\UnitTests.Shared\RunnerUtilities.cs" />
<Compile Include="..\UnitTests.Shared\DriveMapping.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDrive.cs" />
<Compile Include="..\UnitTests.Shared\DummyMappedDriveUtils.cs" />
<Compile Include="..\Shared\UnitTests\LongPathSupportDisabledFactAttribute.cs">
<Link>Shared\LongPathSupportDisabledFactAttribute.cs</Link>
</Compile>
Expand Down
Loading