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

bug / no code coverage #32

Merged
merged 6 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions repros/30_Empty_CodeCoverage/ConsoleApp/App.cs
Original file line number Diff line number Diff line change
@@ -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<IStringLocalizer<Resource1>>();
message = localize["Hello {World}", "Earth"];
}

public string SayHello()
{
Console.WriteLine(message);
return message;
}
}
40 changes: 40 additions & 0 deletions repros/30_Empty_CodeCoverage/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="TypealizR" Version="0.5.1"> <!-- pinned, as this version introduced issue #30 - empty code-coverage when coverlet runs on project which refrences the nuget-package -->
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Update="Resource1.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource1.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<PropertyGroup>
<!-- Update the property to include all EmbeddedResource files -->
<AdditionalFileItemNames>$(AdditionalFileItemNames);EmbeddedResource</AdditionalFileItemNames>
</PropertyGroup>

</Project>
15 changes: 15 additions & 0 deletions repros/30_Empty_CodeCoverage/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
72 changes: 72 additions & 0 deletions repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions repros/30_Empty_CodeCoverage/ConsoleApp/Resource1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Hello {World}" xml:space="preserve">
<value>Hello {0}</value>
</data>
</root>
21 changes: 21 additions & 0 deletions repros/30_Empty_CodeCoverage/XUnit.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions repros/30_Empty_CodeCoverage/XUnit.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
33 changes: 33 additions & 0 deletions repros/30_Empty_CodeCoverage/XUnit.Tests/XUnit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
<CoverletOutputFormat>lcov,opencover</CoverletOutputFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ConsoleApp\ConsoleApp.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions repros/Repros.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ClassModel(TypeModel target, IEnumerable<MethodModel> methods, IEnumerabl
);
}

public string FileName => $"IStringLocalizerExtensions_{target.FullName}";
public string FileName => $"IStringLocalizerExtensions_{target.FullName}.g.cs";

public string Body => $@"
// <auto-generated/>
Expand Down