mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00

Analyzer package needs all the dependencies to be private assets, and it's output pushed to teh analyzers/dotnet/cs folder. We don't want anything in the lib folder, so it also disables the auto build output and warnings that there are no files for the target framework in the lib folder
71 lines
1.7 KiB
C#
71 lines
1.7 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.Testing;
|
|
using Spectre.Console.Analyzer;
|
|
using Xunit;
|
|
using AnalyzerVerify =
|
|
Spectre.Console.Tests.CodeAnalyzers.SpectreAnalyzerVerifier<
|
|
Spectre.Console.Analyzer.UseSpectreInsteadOfSystemConsoleAnalyzer>;
|
|
|
|
namespace Spectre.Console.Tests.CodeAnalyzers.Analyzers
|
|
{
|
|
public class UseSpectreInsteadOfSystemConsoleAnalyzerTests
|
|
{
|
|
private static readonly DiagnosticResult _expectedDiagnostics = new(
|
|
Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id,
|
|
DiagnosticSeverity.Warning);
|
|
|
|
[Fact]
|
|
public async void Non_configured_SystemConsole_methods_report_no_warnings()
|
|
{
|
|
const string Source = @"
|
|
using System;
|
|
|
|
class TestClass {
|
|
void TestMethod()
|
|
{
|
|
var s = Console.ReadLine();
|
|
}
|
|
}";
|
|
|
|
await AnalyzerVerify
|
|
.VerifyAnalyzerAsync(Source)
|
|
.ConfigureAwait(false);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Console_Write_Has_Warning()
|
|
{
|
|
const string Source = @"
|
|
using System;
|
|
|
|
class TestClass {
|
|
void TestMethod()
|
|
{
|
|
Console.Write(""Hello, World"");
|
|
}
|
|
}";
|
|
|
|
await AnalyzerVerify
|
|
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9))
|
|
.ConfigureAwait(false);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Console_WriteLine_Has_Warning()
|
|
{
|
|
const string Source = @"
|
|
using System;
|
|
|
|
class TestClass
|
|
{
|
|
void TestMethod() {
|
|
Console.WriteLine(""Hello, World"");
|
|
}
|
|
}";
|
|
|
|
await AnalyzerVerify
|
|
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9))
|
|
.ConfigureAwait(false);
|
|
}
|
|
}
|
|
} |