diff --git a/.gitignore b/.gitignore index ae9b0faf..8cdbd7b0 100644 --- a/.gitignore +++ b/.gitignore @@ -348,4 +348,6 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ -/src/TypealizR.SourceGenerators.Tests/coverage.info + +**/coverage.info +**/coverage.opencover.xml diff --git a/repros/30_Empty_CodeCoverage/ConsoleApp/App.cs b/repros/30_Empty_CodeCoverage/ConsoleApp/App.cs new file mode 100644 index 00000000..e409223f --- /dev/null +++ b/repros/30_Empty_CodeCoverage/ConsoleApp/App.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; + +namespace ConsoleApp; +internal class App +{ + private readonly string message; + public App(IServiceProvider servceProvider) + { + var localize = servceProvider.GetRequiredService>(); + message = localize["Hello {World}", "Earth"]; + } + + public string SayHello() + { + Console.WriteLine(message); + return message; + } +} diff --git a/repros/30_Empty_CodeCoverage/ConsoleApp/ConsoleApp.csproj b/repros/30_Empty_CodeCoverage/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 00000000..29b16f95 --- /dev/null +++ b/repros/30_Empty_CodeCoverage/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,40 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + True + True + Resource1.resx + + + + + + ResXFileCodeGenerator + Resource1.Designer.cs + + + + + + $(AdditionalFileItemNames);EmbeddedResource + + + diff --git a/repros/30_Empty_CodeCoverage/ConsoleApp/Program.cs b/repros/30_Empty_CodeCoverage/ConsoleApp/Program.cs new file mode 100644 index 00000000..1219d23d --- /dev/null +++ b/repros/30_Empty_CodeCoverage/ConsoleApp/Program.cs @@ -0,0 +1,15 @@ +// See https://aka.ms/new-console-template for more information +using System.Runtime.CompilerServices; +using ConsoleApp; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; +[assembly:InternalsVisibleTo("XUnit.Tests")] + +var services = new ServiceCollection(); +services.AddLocalization(); +services.AddLogging(); +var provider = services.BuildServiceProvider(); + +var app = new App(provider); + +app.SayHello(); \ No newline at end of file diff --git a/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.Designer.cs b/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.Designer.cs new file mode 100644 index 00000000..d7e9f98d --- /dev/null +++ b/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ConsoleApp { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource1 { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource1() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConsoleApp.Resource1", typeof(Resource1).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Hello {0}. + /// + internal static string Hello__World_ { + get { + return ResourceManager.GetString("Hello {World}", resourceCulture); + } + } + } +} diff --git a/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.resx b/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.resx new file mode 100644 index 00000000..0fd37811 --- /dev/null +++ b/repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello {0} + + \ No newline at end of file diff --git a/repros/30_Empty_CodeCoverage/XUnit.Tests/UnitTest1.cs b/repros/30_Empty_CodeCoverage/XUnit.Tests/UnitTest1.cs new file mode 100644 index 00000000..b5593222 --- /dev/null +++ b/repros/30_Empty_CodeCoverage/XUnit.Tests/UnitTest1.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace XUnit.Tests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + var services = new ServiceCollection(); + services.AddLocalization(); + services.AddLogging(); + + var provider = services.BuildServiceProvider(); + + var app = new ConsoleApp.App(provider); + var message = app.SayHello(); + + Assert.Equal("Hello Earth", message); + } +} \ No newline at end of file diff --git a/repros/30_Empty_CodeCoverage/XUnit.Tests/Usings.cs b/repros/30_Empty_CodeCoverage/XUnit.Tests/Usings.cs new file mode 100644 index 00000000..8c927eb7 --- /dev/null +++ b/repros/30_Empty_CodeCoverage/XUnit.Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/repros/30_Empty_CodeCoverage/XUnit.Tests/XUnit.Tests.csproj b/repros/30_Empty_CodeCoverage/XUnit.Tests/XUnit.Tests.csproj new file mode 100644 index 00000000..fda32fd1 --- /dev/null +++ b/repros/30_Empty_CodeCoverage/XUnit.Tests/XUnit.Tests.csproj @@ -0,0 +1,33 @@ + + + + net6.0 + enable + enable + false + + + + true + GeneratedCodeAttribute + lcov,opencover + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/repros/Repros.sln b/repros/Repros.sln new file mode 100644 index 00000000..6f43add8 --- /dev/null +++ b/repros/Repros.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33110.190 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "30_Empty_CodeCoverage\ConsoleApp\ConsoleApp.csproj", "{EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "30_No_CodeCoverage", "30_No_CodeCoverage", "{B30671FE-9E1D-47C3-859D-1174684E8EA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnit.Tests", "30_Empty_CodeCoverage\XUnit.Tests\XUnit.Tests.csproj", "{37394218-3792-4C44-A733-178E7CE62218}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C}.Release|Any CPU.Build.0 = Release|Any CPU + {37394218-3792-4C44-A733-178E7CE62218}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37394218-3792-4C44-A733-178E7CE62218}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37394218-3792-4C44-A733-178E7CE62218}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37394218-3792-4C44-A733-178E7CE62218}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EC5E9BC9-1C57-47A4-A3F3-F6F4BD271E2C} = {B30671FE-9E1D-47C3-859D-1174684E8EA8} + {37394218-3792-4C44-A733-178E7CE62218} = {B30671FE-9E1D-47C3-859D-1174684E8EA8} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {14265E13-26BD-4EE2-B7B3-C58B7D392FC7} + EndGlobalSection +EndGlobal diff --git a/src/TypealizR.SourceGenerators/StringLocalizer/ClassModel.cs b/src/TypealizR.SourceGenerators/StringLocalizer/ClassModel.cs index 667822f9..f8c341bf 100644 --- a/src/TypealizR.SourceGenerators/StringLocalizer/ClassModel.cs +++ b/src/TypealizR.SourceGenerators/StringLocalizer/ClassModel.cs @@ -30,7 +30,7 @@ public ClassModel(TypeModel target, IEnumerable methods, IEnumerabl ); } - public string FileName => $"IStringLocalizerExtensions_{target.FullName}"; + public string FileName => $"IStringLocalizerExtensions_{target.FullName}.g.cs"; public string Body => $@" //