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

* Add support for C# 12 * Run all tests on all major .NET SDKs * Only build on Ubuntu * Do not build docs for pull requests * Add Cédric Luthi, and Frank Ray to authors * Drop netstandard2.0 for ImageSharp plugin
60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
namespace Spectre.Console.Analyzer.Tests.Unit.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 SpectreAnalyzerVerifier<UseSpectreInsteadOfSystemConsoleAnalyzer>
|
|
.VerifyAnalyzerAsync(Source);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Console_Write_Has_Warning()
|
|
{
|
|
const string Source = @"
|
|
using System;
|
|
|
|
class TestClass {
|
|
void TestMethod()
|
|
{
|
|
Console.Write(""Hello, World"");
|
|
}
|
|
}";
|
|
|
|
await SpectreAnalyzerVerifier<UseSpectreInsteadOfSystemConsoleAnalyzer>
|
|
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9));
|
|
}
|
|
|
|
[Fact]
|
|
public async void Console_WriteLine_Has_Warning()
|
|
{
|
|
const string Source = @"
|
|
using System;
|
|
|
|
class TestClass
|
|
{
|
|
void TestMethod() {
|
|
Console.WriteLine(""Hello, World"");
|
|
}
|
|
}";
|
|
|
|
await SpectreAnalyzerVerifier<UseSpectreInsteadOfSystemConsoleAnalyzer>
|
|
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9));
|
|
}
|
|
}
|