Skip to content

Conversation

@jrdodds
Copy link
Contributor

@jrdodds jrdodds commented Mar 13, 2023

Fixes #8516

Context

Setting an OutputDirectory where the directory does not exist, and setting an OutputFile would fail.

(Setting an OutputDirectory where the directory does not exist, and not providing an OutputFile value would succeed because FileUtilities.GetTemporaryFile calls Directory.CreateDirectory.)

Changes Made

WriteCodeFragment_Tests.cs

  • Added new unit tests:
    • CombineFileDirectoryAndDirectoryDoesNotExist (pairs with CombineFileDirectory)
    • ToDirectoryAndDirectoryDoesNotExist (pairs with ToDirectory)
  • Added overload of CreateTask

WriteCodeFragment.cs

  • Changed task to call FileUtilities.EnsureDirectoryExists.

Testing

Added unit tests first and confirmed failure.

Ran all unit tests on Windows 11 and macOS 12 (Monterey).

Notes

Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

/// Bad file path
/// </summary>
[Fact]
[WindowsOnlyFact(additionalMessage: "No invalid characters on Unix.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this test work on Unix before?

Copy link
Contributor Author

@jrdodds jrdodds Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked before because the path didn't exist. Now that we ensure that the path is created, the test fails because there is not an MSB3713 error as the test expects. 😀

Copy link
Contributor

@Forgind Forgind Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like 3713 is a very generic error for any failure after our initial validation. Makes sense, thanks!

@jrdodds
Copy link
Contributor Author

jrdodds commented Mar 13, 2023

Off-topic except that I saw the problem while working on this issue:
The unit test Microsoft.Build.UnitTests.Construction.SolutionProjectGenerator_Tests.BuildProjectWithMultipleTargetsInParallel is sometimes failing on macOS, but it is not consistent. The failure is at line 262 in the following snippet:

var output = RunnerUtilities.ExecMSBuild(solutionFile.Path + " /m /t:Clean;Build;Custom", out bool success);
success.ShouldBeTrue();

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Mar 14, 2023
@JaynieBai JaynieBai merged commit 60ea2f7 into dotnet:main Mar 15, 2023
@jrdodds jrdodds deleted the WriteCodeFragment branch March 15, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: WriteCodeFragment creates relevant directory structure

4 participants