From fe5119fde4e1a689a9196777543c9a4bc3dce54b Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Sat, 23 Jul 2016 13:38:31 -0400 Subject: [PATCH] Piotrp msft/merge2msbuild (#3923) * Add Test for removing readonly flag when copying readonly library assets * change namespace * PR Feedback * Update README.md (#3904) * Update README.md * Responding to PR feedback * Responding to PR feedback --- README.md | 11 +++ ...Tests.cs => GivenCommonCompilerOptions.cs} | 4 +- .../GivenThatICopyLibraryAssets.cs | 68 +++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) rename test/Microsoft.DotNet.Compiler.Common.Tests/{Tests.cs => GivenCommonCompilerOptions.cs} (91%) create mode 100644 test/Microsoft.DotNet.Compiler.Common.Tests/GivenThatICopyLibraryAssets.cs diff --git a/README.md b/README.md index 6cf4f8630..ec99858a2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,17 @@ check out our [Getting started page](http://go.microsoft.com/fwlink/?LinkID=7983 Also, don't forget to check out [the documentation](https://aka.ms/dotnet-cli-docs). +Changes in issue triaging +------------------------- +We are making significant changes to the CLI tooling by supporting MSBuild as the build engine and `csproj` as the project format. You can read ["Changes to project.json" blog post](https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/) for more context. We've realized that this also means that many of the shortcomings of the current tooling will be solved by this move so we've decided to introduce two new labels to indicate that in the issues: + +* `msbuild-mitigated` - this label indicates the issue will be mitigated via move to MSBuild. +* `msbuild-notapplicable` - this label indicates the issue will not be applicable after moving to MSBuild. + +We will close issues that are labelled with one of these labels. Proactive triaging will help us reduce the number of issues and enable us to focus on issues that require fixing independent of the move to msbuild. + +Please feel free to re-open and comment on any issue that you believe was triaged incorrectly. + Found an issue? --------------- You can consult the [known issues page](https://github.com/dotnet/core/blob/master/cli/known-issues.md) to find out the current issues and diff --git a/test/Microsoft.DotNet.Compiler.Common.Tests/Tests.cs b/test/Microsoft.DotNet.Compiler.Common.Tests/GivenCommonCompilerOptions.cs similarity index 91% rename from test/Microsoft.DotNet.Compiler.Common.Tests/Tests.cs rename to test/Microsoft.DotNet.Compiler.Common.Tests/GivenCommonCompilerOptions.cs index b678464b1..6757af610 100644 --- a/test/Microsoft.DotNet.Compiler.Common.Tests/Tests.cs +++ b/test/Microsoft.DotNet.Compiler.Common.Tests/GivenCommonCompilerOptions.cs @@ -5,9 +5,9 @@ using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; -namespace Microsoft.DotNet.Cli.Compiler.Common +namespace Microsoft.DotNet.Cli.Compiler.Common.Tests { - public class Tests : TestBase + public class GivenCommonCompilerOptions : TestBase { [Fact] public void SimpleSerialize() diff --git a/test/Microsoft.DotNet.Compiler.Common.Tests/GivenThatICopyLibraryAssets.cs b/test/Microsoft.DotNet.Compiler.Common.Tests/GivenThatICopyLibraryAssets.cs new file mode 100644 index 000000000..b8421c27b --- /dev/null +++ b/test/Microsoft.DotNet.Compiler.Common.Tests/GivenThatICopyLibraryAssets.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Xunit; +using Microsoft.DotNet.Cli.Compiler.Common; +using Microsoft.DotNet.ProjectModel.Compilation; +using System.IO; +using System; +using System.Linq; +using System.Collections.Generic; + +namespace Microsoft.DotNet.Cli.Compiler.Common.Tests +{ + public class GivenThatICopyLibraryAssets + { + [Fact] + public void LibraryAsset_CopyTo_Clears_Readonly() + { + var libraryAsset = GetMockLibraryAsset(nameof(LibraryAsset_CopyTo_Clears_Readonly)); + MakeFileReadonly(libraryAsset.ResolvedPath); + + IEnumerable assets = new LibraryAsset[] { libraryAsset }; + + var outputDirectory = Path.Combine(AppContext.BaseDirectory,$"{nameof(LibraryAsset_CopyTo_Clears_Readonly)}_out"); + assets.CopyTo(outputDirectory); + + var copiedFile = Directory.EnumerateFiles(outputDirectory, Path.GetFileName(libraryAsset.RelativePath)).First(); + IsFileReadonly(copiedFile).Should().BeFalse(); + } + + [Fact] + public void LibraryAsset_StructuredCopyTo_Clears_Readonly() + { + var libraryAsset = GetMockLibraryAsset(nameof(LibraryAsset_StructuredCopyTo_Clears_Readonly)); + MakeFileReadonly(libraryAsset.ResolvedPath); + + IEnumerable assets = new LibraryAsset[] { libraryAsset }; + + var intermediateDirectory = Path.Combine(AppContext.BaseDirectory,$"{nameof(LibraryAsset_StructuredCopyTo_Clears_Readonly)}_obj"); + var outputDirectory = Path.Combine(AppContext.BaseDirectory,$"{nameof(LibraryAsset_StructuredCopyTo_Clears_Readonly)}_out"); + assets.StructuredCopyTo(outputDirectory, intermediateDirectory); + + var copiedFile = Directory.EnumerateFiles(outputDirectory, Path.GetFileName(libraryAsset.RelativePath)).First(); + IsFileReadonly(copiedFile).Should().BeFalse(); + } + + private void MakeFileReadonly(string file) + { + File.SetAttributes(file, File.GetAttributes(file) | FileAttributes.ReadOnly); + } + + private bool IsFileReadonly(string file) + { + return (File.GetAttributes(file) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; + } + + private LibraryAsset GetMockLibraryAsset(string mockedLibraryAssetName) + { + var mockedLibraryAssetFileName = $"{mockedLibraryAssetName}.dll"; + + var fakeFile = Path.Combine(AppContext.BaseDirectory, mockedLibraryAssetFileName); + File.WriteAllText(fakeFile, mockedLibraryAssetName); + + return new LibraryAsset(mockedLibraryAssetName, mockedLibraryAssetFileName, fakeFile); + } + } +}