Skip to content

Commit 014e279

Browse files
committed
fix bug
1 parent 70faced commit 014e279

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

.github/workflows/dotnet.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ env:
44
DOTNET_NOLOGO: true
55
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
66
BUILD_PATH: '${{github.workspace}}/artifacts'
7+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
78

89
on:
910
push:
@@ -42,6 +43,13 @@ jobs:
4243
- name: Run Test
4344
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings
4445

46+
- name: Report Coverage
47+
if: success()
48+
uses: coverallsapp/github-action@v2
49+
with:
50+
file: "${{github.workspace}}/test/*/TestResults/*/coverage.info"
51+
format: lcov
52+
4553
- name: Create Packages
4654
if: success() && github.event_name != 'pull_request'
4755
run: dotnet pack --configuration Release --include-symbols --include-source --no-build --no-restore --output "${{env.BUILD_PATH}}"

src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.Versioning;
44

55
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.CSharp;
67
using Microsoft.CodeAnalysis.CSharp.Syntax;
78

89
namespace AssemblyMetadata.Generators;
@@ -83,7 +84,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex
8384
name = name.Substring(0, name.Length - 9);
8485

8586
var argument = attribute.ConstructorArguments.FirstOrDefault();
86-
var value = argument.Value?.ToString() ?? string.Empty;
87+
var value = argument.ToCSharpString() ?? string.Empty;
8788

8889
if (string.IsNullOrWhiteSpace(value))
8990
continue;
@@ -97,7 +98,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex
9798
var key = nameArgument.Value?.ToString() ?? string.Empty;
9899

99100
var valueArgument = attribute.ConstructorArguments[1];
100-
var value = valueArgument.Value?.ToString() ?? string.Empty;
101+
var value = valueArgument.ToCSharpString() ?? string.Empty;
101102

102103
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
103104
continue;

src/AssemblyMetadata.Generators/AssemblyMetadataWriter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ public static string Generate(EquatableArray<AssemblyConstant> constants)
4444
foreach (var constant in constants)
4545
{
4646
var name = SafeName(constant.Name);
47-
var value = SafeValue(constant.Value);
4847

4948
codeBuilder
5049
.Append("public const string ")
5150
.Append(name)
52-
.Append(" = \"")
53-
.Append(value)
54-
.AppendLine("\";")
51+
.Append(" = ")
52+
.Append(constant.Value)
53+
.AppendLine(";")
5554
.AppendLine();
5655
}
5756

@@ -67,14 +66,6 @@ public static string SafeName(string name)
6766
return ToPropertyName(name.AsSpan());
6867
}
6968

70-
public static string SafeValue(string value)
71-
{
72-
return value
73-
.Replace("\\", "\\\\")
74-
.Replace("\"", "\\\"")
75-
.Replace(Environment.NewLine, "\\r\\n");
76-
}
77-
7869
public static string ToPropertyName(ReadOnlySpan<char> span)
7970
{
8071
if (span.IsEmpty)

test/AssemblyMetadata.Generators.Tests/PropertyNameTests.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,4 @@ public void PropertyName(string input, string expected)
1616
var actual = AssemblyMetadataWriter.ToPropertyName(input);
1717
Assert.Equal(expected, actual);
1818
}
19-
20-
[Theory]
21-
[InlineData("Name\\Test", "Name\\\\Test")]
22-
[InlineData("Name\"Test\"", "Name\\\"Test\\\"")]
23-
public void SafeValue(string input, string expected)
24-
{
25-
var actual = AssemblyMetadataWriter.SafeValue(input);
26-
Assert.Equal(expected, actual);
27-
}
2819
}

test/AssemblyMetadata.Generators.Tests/Snapshots/GeneratorTests.GenerateAssemblyMetadataGeneratorsTests.verified.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ internal static partial class ThisAssembly
1010

1111
public const string HardKey = "HardValue";
1212

13+
public const string VerifyTargetFrameworks = "";
14+
1315
public const string VerifyProjectDirectory = "D:\\Projects\\GitHub\\AssemblyMetadata.Generators\\test\\AssemblyMetadata.Generators.Tests\\";
1416

1517
public const string VerifySolutionDirectory = "D:\\Projects\\GitHub\\AssemblyMetadata.Generators\\";

0 commit comments

Comments
 (0)