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

Allow MSBuild tests to access root of drive #7330

Closed
mruxmohan4 opened this issue Jan 25, 2022 · 0 comments · Fixed by #8366 or #9266
Closed

Allow MSBuild tests to access root of drive #7330

mruxmohan4 opened this issue Jan 25, 2022 · 0 comments · Fixed by #8366 or #9266

Comments

@mruxmohan4
Copy link
Contributor

Issue Description

Allow drive enumerating tests to access the root of a drive inside of Visual Studio. Currently, an UnauthorizedAccessException is thrown (so drive substitution is required for such tests to pass in VS).

Steps to Reproduce

Run subst z: <drive>:\<path> (or preferably, subst z: %TEMP%) on the command line for the below test to pass. This test can be added inside of CreateItem_Tests.cs.

       [Fact]
       public void WildcardDriveEnumerationTaskItemLogsWarning()
       {
           using (var env = TestEnvironment.Create())
           {
               ChangeWaves.ResetStateForTests();
               env.SetEnvironmentVariable("MSBUILDFAILONDRIVEENUMERATINGWILDCARD", "0");
               BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly();

               CreateItem t = new CreateItem();
               MockEngine engine = new MockEngine();

               t.BuildEngine = engine;
               t.Include = new ITaskItem[] { new TaskItem(@"z:\**\*.log") };
               bool succeeded = t.Execute();

               Assert.True(succeeded);
               Assert.Equal(1, engine.Warnings);
               engine.AssertLogContains("results in drive enumeration");

               ChangeWaves.ResetStateForTests();
           }
       }

Expected Behavior

The test case should pass and allow for drive enumeration to occur for MSBuild to properly log a warning when a drive enumerating wildcard is detected.

Actual Behavior

The test case throws an UnauthorizedAccessException and hangs.

Analysis

This occurs for attempts to log a warning in ProjectItem_Tests.cs and ProjectItemInstance_Tests.cs as well.

Versions & Configurations

Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

17.0.0.52104

@mruxmohan4 mruxmohan4 added bug needs-triage Have yet to determine what bucket this goes in. labels Jan 25, 2022
@benvillalobos benvillalobos added Area: Tests and removed needs-triage Have yet to determine what bucket this goes in. labels Jan 27, 2022
@JanKrivanek JanKrivanek self-assigned this Jan 30, 2023
JaynieBai pushed a commit that referenced this issue Feb 8, 2023
Fixes #7330
(plus one subtask of #8329)

Tests only change (no production code affected)

Context
Drive enumeration integration tests need to simulate attempt to enumerate whole drive.
To prevent security and test runtime considerations - a dummy folder is created and mapped to a free letter to be offered to test as a drive for enumeration.

Changes Made
Added utility for mapping drives and mounted to affected unit tests.
JaynieBai added a commit that referenced this issue Oct 10, 2023
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
bulatgrzegorz pushed a commit to bulatgrzegorz/selective-condition-evaluator that referenced this issue Oct 16, 2023
Fixes dotnet#7330
(plus one subtask of dotnet#8329)

Changes Made
Based on Add ability to create temp mapped drive for integration tests dotnet#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? dotnet#8373
MichalPavlik pushed a commit that referenced this issue Oct 17, 2023
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
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment