Skip to content

Commit

Permalink
fix bad test compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed Feb 8, 2023
1 parent ee904e7 commit 9ea12d4
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 100 deletions.
4 changes: 3 additions & 1 deletion samples/extensions/src/ExampleClass.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace MyExample
{
public class ExampleClass
Expand All @@ -6,7 +8,7 @@ public class ExampleClass

public string MyField;

public string Myroperty { get; set; }
public string MyProperty { get; set; }

public ExampleClass()
{
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main(string[] foo) { }
"""),
};

public static bool CheckDiagnostics(this Compilation compilation)
public static void CheckDiagnostics(this Compilation compilation, List<Diagnostic> errors)
{
var errorCount = 0;

Expand All @@ -47,14 +47,13 @@ public static bool CheckDiagnostics(this Compilation compilation)
if (diagnostic.Severity is DiagnosticSeverity.Error)
{
Logger.LogError(diagnostic.ToString());
errors.Add(diagnostic);

if (++errorCount >= 20)
break;
}
}

return errorCount > 0;

static bool IsKnownError(Diagnostic diagnostic)
{
// Ignore these VB errors on non-Windows platform:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task ExtractMetadataAsync()
}
}

var hasCompilationError = false;
var compilationErrors = new List<Diagnostic>();
var assemblySymbols = new List<IAssemblySymbol>();

if (_files.TryGetValue(FileType.Solution, out var solutionFiles))
Expand Down Expand Up @@ -138,21 +138,21 @@ public async Task ExtractMetadataAsync()

Logger.LogInfo($"Compiling project {project.FilePath}");
var compilation = await project.GetCompilationAsync();
hasCompilationError |= compilation.CheckDiagnostics();
compilation.CheckDiagnostics(compilationErrors);
assemblySymbols.Add(compilation.Assembly);
}

if (_files.TryGetValue(FileType.CSSourceCode, out var csFiles))
{
var compilation = CompilationHelper.CreateCompilationFromCSharpFiles(csFiles.Select(f => f.NormalizedPath));
hasCompilationError |= compilation.CheckDiagnostics();
compilation.CheckDiagnostics(compilationErrors);
assemblySymbols.Add(compilation.Assembly);
}

if (_files.TryGetValue(FileType.VBSourceCode, out var vbFiles))
{
var compilation = CompilationHelper.CreateCompilationFromVBFiles(vbFiles.Select(f => f.NormalizedPath));
hasCompilationError |= compilation.CheckDiagnostics();
compilation.CheckDiagnostics(compilationErrors);
assemblySymbols.Add(compilation.Assembly);
}

Expand All @@ -162,14 +162,14 @@ public async Task ExtractMetadataAsync()
{
Logger.LogInfo($"Loading assembly {assemblyFile.NormalizedPath}");
var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly(assemblyFile.NormalizedPath, _references);
hasCompilationError |= compilation.CheckDiagnostics();
compilation.CheckDiagnostics(compilationErrors);
assemblySymbols.Add(assembly);
}
}

if (hasCompilationError)
if (compilationErrors.Count > 0)
{
throw new DocfxException("Abort .NET API generation due to compilation errors");
throw new DocfxException($"Abort .NET API generation due to compilation errors:\n\n{string.Join('\n', compilationErrors)}");
}

if (assemblySymbols.Count <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"id": ".ctor",
"path": "src/ExampleClass.cs",
"startLine": 10.0,
"startLine": 12.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -131,7 +131,7 @@
"summary": "",
"platform": null,
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass__ctor.md&value=---%0Auid%3A%20MyExample.ExampleClass.%23ctor%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L11",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L13",
"remarks": null,
"conceptual": "",
"implements": null,
Expand Down Expand Up @@ -187,7 +187,7 @@
},
"id": ".ctor",
"path": "src/ExampleClass.cs",
"startLine": 10.0,
"startLine": 12.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -353,7 +353,7 @@
"_shared": {}
},
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass__ctor_.md&value=---%0Auid%3A%20MyExample.ExampleClass.%23ctor*%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L11",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L13",
"summary": "",
"remarks": null,
"conceptual": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"id": "MyEvent",
"path": "src/ExampleClass.cs",
"startLine": 4.0,
"startLine": 6.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -126,8 +126,8 @@
],
"return": {
"type": {
"uid": "Action{System.String}",
"definition": "Action`1",
"uid": "System.Action{System.String}",
"definition": "System.Action`1",
"name": [
{
"lang": "csharp",
Expand All @@ -151,21 +151,21 @@
"fullName": [
{
"lang": "csharp",
"value": "Action<string>"
"value": "System.Action<string>"
},
{
"lang": "vb",
"value": "Action(Of String)"
"value": "System.Action(Of String)"
}
],
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"Action`1\" text=\"Action\"/>&lt;<xref uid=\"System.String\" text=\"string\"/>&gt;"
"value": "<xref uid=\"System.Action`1\" text=\"Action\"/>&lt;<xref uid=\"System.String\" text=\"string\"/>&gt;"
},
{
"lang": "vb",
"value": "<xref uid=\"Action`1\" text=\"Action\"/>(Of <xref uid=\"System.String\" text=\"String\"/>)"
"value": "<xref uid=\"System.Action`1\" text=\"Action\"/>(Of <xref uid=\"System.String\" text=\"String\"/>)"
}
]
}
Expand Down Expand Up @@ -283,7 +283,7 @@
"_shared": {}
},
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass_MyEvent.md&value=---%0Auid%3A%20MyExample.ExampleClass.MyEvent%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L5",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L7",
"summary": "",
"remarks": null,
"conceptual": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"id": "MyField",
"path": "src/ExampleClass.cs",
"startLine": 6.0,
"startLine": 8.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -282,7 +282,7 @@
"_shared": {}
},
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass_MyField.md&value=---%0Auid%3A%20MyExample.ExampleClass.MyField%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L7",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L9",
"summary": "",
"remarks": null,
"conceptual": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
"id": "MyMethod",
"path": "src/ExampleClass.cs",
"startLine": 15.0,
"startLine": 17.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -176,7 +176,7 @@
"summary": "",
"platform": null,
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass_MyMethod.md&value=---%0Auid%3A%20MyExample.ExampleClass.MyMethod%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L16",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L18",
"remarks": null,
"conceptual": "",
"implements": null,
Expand Down Expand Up @@ -232,7 +232,7 @@
},
"id": "MyMethod",
"path": "src/ExampleClass.cs",
"startLine": 15.0,
"startLine": 17.0,
"endLine": 0.0,
"isExternal": false
},
Expand Down Expand Up @@ -398,7 +398,7 @@
"_shared": {}
},
"docurl": "/~https://github.com/dotnet/docfx/new/main/apiSpec/new?filename=MyExample_ExampleClass_MyMethod_.md&value=---%0Auid%3A%20MyExample.ExampleClass.MyMethod*%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L16",
"sourceurl": "/~https://github.com/dotnet/docfx/blob/main/samples/extensions/src/ExampleClass.cs/#L18",
"summary": "",
"remarks": null,
"conceptual": "",
Expand Down
Loading

0 comments on commit 9ea12d4

Please sign in to comment.