From 037da3fc014214764ed64ed2cece7392743b385d Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Thu, 26 Jan 2017 11:00:50 -0800 Subject: [PATCH] Finish tests --- .../Program.cs | 19 ++++++++++++++ .../project.json | 20 ++++++++++++++ .../ProjectReader.cs | 15 ++++++++--- .../ProjectMigrator.cs | 25 ++++++++++++++---- .../GivenAProjectMigrator.cs | 26 +++++++++++++++++++ 5 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/Program.cs create mode 100644 TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/project.json diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/Program.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/Program.cs new file mode 100644 index 000000000..d0134277c --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + var thisAssembly = typeof(Program).GetTypeInfo().Assembly; + var resources = from resourceName in thisAssembly.GetManifestResourceNames() + select resourceName; + + var resourceNames = string.Join(",", resources); + Console.WriteLine($"{resources.Count()} Resources Found: {resourceNames}"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/project.json b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/project.json new file mode 100644 index 000000000..0bf0dfa00 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedNamedResourceOption/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "namedResource": [ "My.Alias", "Strings.resx" ], + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs index 2c6e07710..1b20a58af 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs @@ -825,7 +825,14 @@ namespace Microsoft.DotNet.Internal.ProjectModel AddDeprecatedDiagnosticMessage(rawProject, project, "resourceExclude", resourceWarning); AddDeprecatedDiagnosticMessage(rawProject, project, "resourceFiles", resourceWarning); AddDeprecatedDiagnosticMessage(rawProject, project, "resourceBuiltIn", resourceWarning); - AddDeprecatedDiagnosticMessage(rawProject, project, "namedResource", resourceWarning); + // Issue: https://github.com/dotnet/cli/issues/5471 + // This is why we mark it as an error which will fail migration. + AddDeprecatedDiagnosticMessage( + rawProject, + project, + "namedResource", + resourceWarning, + DiagnosticMessageSeverity.Error); var contentWarning = "'publishOptions' to publish or 'copyToOutput' in 'buildOptions' to copy to build output"; AddDeprecatedDiagnosticMessage(rawProject, project, "content", contentWarning); @@ -842,7 +849,8 @@ namespace Microsoft.DotNet.Internal.ProjectModel JObject rawProject, Project project, string option, - string message) + string message, + DiagnosticMessageSeverity severity = DiagnosticMessageSeverity.Warning) { var lineInfo = rawProject.Value(option); if (lineInfo == null) @@ -855,7 +863,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel ErrorCodes.DOTNET1015, $"The '{option}' option is deprecated. Use {message} instead.", project.ProjectFilePath, - DiagnosticMessageSeverity.Warning, + severity, lineInfo.LineNumber, lineInfo.LinePosition)); } @@ -896,7 +904,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel ConvertFromDeprecatedFormat(rawProject, jpath, "exclude", "exclude"); ConvertFromDeprecatedFormat(rawProject, jpath, "resourceExclude", "excludeFiles"); ConvertFromDeprecatedFormat(rawProject, jpath, "resourceFiles", "includeFiles"); - ConvertFromDeprecatedFormat(rawProject, jpath, "namedResource", "mappings"); ConvertFromDeprecatedFormat(rawProject, $"{jpath}.builtIns", "resourceBuiltIn", "include"); } diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs index 7b2a31446..37cc20b50 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs @@ -252,11 +252,26 @@ namespace Microsoft.DotNet.ProjectJsonMigration var diagnostics = defaultProjectContext.ProjectFile.Diagnostics; if (diagnostics.Any()) { - var deprecatedProjectJsonWarnings = string.Join( - Environment.NewLine, - diagnostics.Select(d => FormatDiagnosticMessage(d))); - var warnings = $"{projectDirectory}{Environment.NewLine}{deprecatedProjectJsonWarnings}"; - Reporter.Output.WriteLine(warnings.Yellow()); + var warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning); + if (warnings.Any()) + { + var deprecatedProjectJsonWarnings = string.Join( + Environment.NewLine, + diagnostics.Select(d => FormatDiagnosticMessage(d))); + var warningMessage = $"{projectDirectory}{Environment.NewLine}{deprecatedProjectJsonWarnings}"; + Reporter.Output.WriteLine(warningMessage.Yellow()); + } + + var errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error); + if (errors.Any()) + { + MigrationErrorCodes.MIGRATE1011(String.Format( + "{0}{1}{2}", + projectDirectory, + Environment.NewLine, + string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d))))) + .Throw(); + } } var compilerName = diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs index d1cb75935..e0111f385 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs @@ -6,6 +6,7 @@ using FluentAssertions; using Microsoft.Build.Construction; using Microsoft.DotNet.ProjectJsonMigration.Rules; using Microsoft.DotNet.Internal.ProjectModel; +using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; @@ -38,6 +39,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } } + [Fact] + public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson() + { + var testProjectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedNamedResourceOption") + .CreateInstance() + .WithSourceFiles() + .Root + .FullName; + + var mockProj = ProjectRootElement.Create(); + var testSettings = MigrationSettings.CreateMigrationSettingsTestHook( + testProjectDirectory, + testProjectDirectory, + mockProj); + + var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule()); + var report = projectMigrator.Migrate(testSettings); + + var projectReport = report.ProjectMigrationReports.First(); + var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage(); + errorMessage.Should().Contain("MIGRATE1011::Deprecated Project:"); + errorMessage.Should().Contain("The 'namedResource' option is deprecated. Use 'embed' in 'buildOptions' instead. (line: 3, file:"); + } + [Fact] public void ItHasErrorWhenMigratingANonCsharpApp() {