Skip to content

Commit

Permalink
- normalize paths in test output
Browse files Browse the repository at this point in the history
- only log code in DEBUG (to avoid CI noise)
  • Loading branch information
mgravell committed May 12, 2021
1 parent ecc06eb commit ad9c95c
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 86 deletions.
1 change: 1 addition & 0 deletions Dapper.AOT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
README.md = README.md
version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9A846B95-90CE-4335-9043-48C5B8EA4FB8}"
Expand Down
22 changes: 11 additions & 11 deletions src/Dapper.AOT.Analyzers/CodeAnalysis/CommandGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<MethodDeclarationSyntax>.Enumerator GetEnumerator()
/// <summary>
/// Provide log feedback.
/// </summary>
public event Action<string>? Log;
public event Action<DiagnosticSeverity, string>? Log;

/// <summary>
/// Indicate version in generated code.
Expand Down Expand Up @@ -87,12 +87,12 @@ void ISourceGenerator.Execute(GeneratorExecutionContext context)
var ca = method.GetAttributes().SingleOrDefault(x => IsCommandAttribute(x.AttributeClass));
if (ca is null) continue; // lacking [Command]

Log?.Invoke($"Detected candidate: '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Info, $"Detected candidate: '{method.Name}'");
(candidates ??= new()).Add((GetNamespace(method.ContainingType), GetTypeName(method.ContainingType), method, syntaxNode));
}
catch (Exception ex)
{
Log?.Invoke($"Error processing '{syntaxNode.Identifier}': '{ex.Message}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Error processing '{syntaxNode.Identifier}': '{ex.Message}'");
// TODO: declare a formal diagnostic for this
var err = Diagnostic.Create("DAP001", "Dapper", ex.Message, DiagnosticSeverity.Warning, DiagnosticSeverity.Warning, true, 4, location: syntaxNode.GetLocation());
context.ReportDiagnostic(err);
Expand Down Expand Up @@ -211,7 +211,7 @@ private string Generate(List<(string Namespace, string TypeName, IMethodSymbol M
foreach (var nsGrp in candidates.GroupBy(x => x.Namespace))
{
var materializers = new Dictionary<ITypeSymbol, string>();
Log?.Invoke($"Namespace '{nsGrp.Key}' has {nsGrp.Count()} candidate(s) in {nsGrp.Select(x => x.TypeName).Distinct().Count()} type(s)");
Log?.Invoke(DiagnosticSeverity.Info, $"Namespace '{nsGrp.Key}' has {nsGrp.Count()} candidate(s) in {nsGrp.Select(x => x.TypeName).Distinct().Count()} type(s)");

if (!string.IsNullOrWhiteSpace(nsGrp.Key))
{
Expand Down Expand Up @@ -334,7 +334,7 @@ private bool WriteMethod(IMethodSymbol method, MethodDeclarationSyntax syntax, C
var text = TryGetCommandText(attribs, out var commandType);
if (text is null)
{
Log?.Invoke($"No command-text resolved for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"No command-text resolved for '{method.Name}'");
return false;
}

Expand All @@ -349,7 +349,7 @@ private bool WriteMethod(IMethodSymbol method, MethodDeclarationSyntax syntax, C

if (connection is not null)
{
Log?.Invoke($"Multiple connection accessors found for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Multiple connection accessors found for '{method.Name}'");
return false;
}
connection = p.Name;
Expand All @@ -358,7 +358,7 @@ private bool WriteMethod(IMethodSymbol method, MethodDeclarationSyntax syntax, C
case HandledType.Transaction:
if (transaction is not null)
{
Log?.Invoke($"Multiple transaction accessors found for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Multiple transaction accessors found for '{method.Name}'");
return false;
}
transaction = p.Name;
Expand All @@ -367,7 +367,7 @@ private bool WriteMethod(IMethodSymbol method, MethodDeclarationSyntax syntax, C
case HandledType.CancellationToken:
if (cancellationToken is not null)
{
Log?.Invoke($"Multiple cancellation tokens found for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Multiple cancellation tokens found for '{method.Name}'");
return false;
}
cancellationToken = p.Name;
Expand Down Expand Up @@ -399,7 +399,7 @@ private bool WriteMethod(IMethodSymbol method, MethodDeclarationSyntax syntax, C
// TODO: other APIs here
else
{
Log?.Invoke($"No connection accessors found for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"No connection accessors found for '{method.Name}'");
return false;
}
}
Expand Down Expand Up @@ -601,7 +601,7 @@ bool WriteMethodViaAdoDotNet(IMethodSymbol method, MethodDeclarationSyntax synta
var cmdType = GetMethodReturnType(connectionType, nameof(IDbConnection.CreateCommand));
if (cmdType is null)
{
Log?.Invoke($"Unable to resolve command-type for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Unable to resolve command-type for '{method.Name}'");
return false;
}
var category = CategorizeQuery(method, context);
Expand All @@ -611,7 +611,7 @@ bool WriteMethodViaAdoDotNet(IMethodSymbol method, MethodDeclarationSyntax synta
readerType = GetMethodReturnType(cmdType, nameof(IDbCommand.ExecuteReader));
if (readerType is null)
{
Log?.Invoke($"Unable to resolve reader-type for '{method.Name}'");
Log?.Invoke(DiagnosticSeverity.Error, $"Unable to resolve reader-type for '{method.Name}'");
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Dapper.AOT.Test/GeneratorTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Output(string message)
if (!string.IsNullOrWhiteSpace(message))
{
_log?.WriteLine(message);
diagnosticsTo?.Append("// ").AppendLine(message);
diagnosticsTo?.Append("// ").AppendLine(message.Replace('\\', '/')); // need to normalize paths
}
}
// Create the 'input' compilation that the generator will act on
Expand Down Expand Up @@ -95,7 +95,7 @@ void Output(string message)
if (!string.IsNullOrWhiteSpace(message))
{
_log?.WriteLine(message);
diagnosticsTo?.Append("// ").AppendLine(message);
diagnosticsTo?.Append("// ").AppendLine(message.Replace('\\', '/')); // need to normalize paths
}
}
foreach (var tree in compilation.SyntaxTrees)
Expand Down
12 changes: 6 additions & 6 deletions test/Dapper.AOT.Test/Samples/Async/Parameters.output.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Input code has 1 diagnostics from 'Samples\Async\Parameters.input.cs':
// Samples\Async\Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Samples\Async\Parameters.input.cs':
// Samples\Async\Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\Parameters.output.cs':
// Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\Parameters.output.cs(18,69): error CS0161: 'Test.ReturnViaReturnAsync(DbConnection, Test.FooParams)': not all code paths return a value
// Input code has 1 diagnostics from 'Samples/Async/Parameters.input.cs':
// Samples/Async/Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Samples/Async/Parameters.input.cs':
// Samples/Async/Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/Parameters.output.cs':
// Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/Parameters.output.cs(18,69): error CS0161: 'Test.ReturnViaReturnAsync(DbConnection, Test.FooParams)': not all code paths return a value

#nullable enable
//------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions test/Dapper.AOT.Test/Samples/Async/Parameters.output.netfx.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Input code has 1 diagnostics from 'Samples\Async\Parameters.input.cs':
// Samples\Async\Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Samples\Async\Parameters.input.cs':
// Samples\Async\Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\Parameters.output.netfx.cs':
// Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\Parameters.output.netfx.cs(18,69): error CS0161: 'Test.ReturnViaReturnAsync(DbConnection, Test.FooParams)': not all code paths return a value
// Input code has 1 diagnostics from 'Samples/Async/Parameters.input.cs':
// Samples/Async/Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Samples/Async/Parameters.input.cs':
// Samples/Async/Parameters.input.cs(13,16): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/Parameters.output.netfx.cs':
// Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/Parameters.output.netfx.cs(18,69): error CS0161: 'Test.ReturnViaReturnAsync(DbConnection, Test.FooParams)': not all code paths return a value

#nullable enable
//------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/Dapper.AOT.Test/Samples/Basic.output.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Output code has 2 diagnostics from 'Samples\Basic.input.cs':
// Samples\Basic.input.cs(14,24): error CS8795: Partial method 'Foo.ShouldIgnoreThis_NoAttribute(string)' must have an implementation part because it has accessibility modifiers.
// Samples\Basic.input.cs(48,32): error CS8795: Partial method 'A<TRandom>.B.ShouldAlsoDetectThisInB(string)' must have an implementation part because it has accessibility modifiers.
// Output code has 2 diagnostics from 'Samples/Basic.input.cs':
// Samples/Basic.input.cs(14,24): error CS8795: Partial method 'Foo.ShouldIgnoreThis_NoAttribute(string)' must have an implementation part because it has accessibility modifiers.
// Samples/Basic.input.cs(48,32): error CS8795: Partial method 'A<TRandom>.B.ShouldAlsoDetectThisInB(string)' must have an implementation part because it has accessibility modifiers.

#nullable enable
//------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/Dapper.AOT.Test/Samples/Basic.output.netfx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Output code has 2 diagnostics from 'Samples\Basic.input.cs':
// Samples\Basic.input.cs(14,24): error CS8795: Partial method 'Foo.ShouldIgnoreThis_NoAttribute(string)' must have an implementation part because it has accessibility modifiers.
// Samples\Basic.input.cs(48,32): error CS8795: Partial method 'A<TRandom>.B.ShouldAlsoDetectThisInB(string)' must have an implementation part because it has accessibility modifiers.
// Output code has 2 diagnostics from 'Samples/Basic.input.cs':
// Samples/Basic.input.cs(14,24): error CS8795: Partial method 'Foo.ShouldIgnoreThis_NoAttribute(string)' must have an implementation part because it has accessibility modifiers.
// Samples/Basic.input.cs(48,32): error CS8795: Partial method 'A<TRandom>.B.ShouldAlsoDetectThisInB(string)' must have an implementation part because it has accessibility modifiers.

#nullable enable
//------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/Dapper.AOT.Test/Samples/Commands.output.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Output code has 2 diagnostics from 'Samples\Commands.input.cs':
// Samples\Commands.input.cs(9,32): error CS8795: Partial method 'Test.AdHocCommandText(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Samples\Commands.input.cs(12,32): error CS8795: Partial method 'Test.AdHocStoredProcedure(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Output code has 2 diagnostics from 'Samples/Commands.input.cs':
// Samples/Commands.input.cs(9,32): error CS8795: Partial method 'Test.AdHocCommandText(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Samples/Commands.input.cs(12,32): error CS8795: Partial method 'Test.AdHocStoredProcedure(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.

#nullable enable
//------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/Dapper.AOT.Test/Samples/Commands.output.netfx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Output code has 2 diagnostics from 'Samples\Commands.input.cs':
// Samples\Commands.input.cs(9,32): error CS8795: Partial method 'Test.AdHocCommandText(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Samples\Commands.input.cs(12,32): error CS8795: Partial method 'Test.AdHocStoredProcedure(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Output code has 2 diagnostics from 'Samples/Commands.input.cs':
// Samples/Commands.input.cs(9,32): error CS8795: Partial method 'Test.AdHocCommandText(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.
// Samples/Commands.input.cs(12,32): error CS8795: Partial method 'Test.AdHocStoredProcedure(string, DbConnection, int, string)' must have an implementation part because it has accessibility modifiers.

#nullable enable
//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions test/Dapper.AOT.Test/Samples/CustomOptions.output.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\CustomOptions.output.cs':
// Dapper.AOT.Analyzers\Dapper.CodeAnalysis.CommandGenerator\CustomOptions.output.cs(90,11): error CS1029: #error: 'Unable to resolve constructor for encryption configuration'
// Output code has 1 diagnostics from 'Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/CustomOptions.output.cs':
// Dapper.AOT.Analyzers/Dapper.CodeAnalysis.CommandGenerator/CustomOptions.output.cs(90,11): error CS1029: #error: 'Unable to resolve constructor for encryption configuration'

#nullable enable
//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ad9c95c

Please sign in to comment.