Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Invalid Console Handle #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/dev-build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Dev build - Windows

on:
push:
branches:
- dev
pull_request:
branches:
- dev

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
dotnet-version: ["7.0.x"]

steps:
- uses: actions/checkout@v2
- name: Setup .NET Code SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Build package sources
run: dotnet build -c Release --no-restore
- name: Build samples
run: dotnet build ./examples/solution.sln
- name: Test
run: dotnet test --no-restore --collect:"XPlat Code Coverage"
- name: Publish code coverage
uses: codecov/codecov-action@v1
with:
files: "**/coverage.cobertura.xml"
flags: unittests
name: vertical-spectreconsolelogger-codecov
3 changes: 3 additions & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- dev
pull_request:
branches:
- dev

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion src/Output/ConsoleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
/// </summary>
protected void ResetLineCore()
{
AnsiConsole.Cursor.Move(CursorDirection.Left, Console.CursorLeft);
if (!Console.IsOutputRedirected)
{
AnsiConsole.Cursor.Move(CursorDirection.Left, Console.CursorLeft);
}

Check warning on line 47 in src/Output/ConsoleWriter.cs

View check run for this annotation

Codecov / codecov/patch

src/Output/ConsoleWriter.cs#L45-L47

Added lines #L45 - L47 were not covered by tests
}
}
}
83 changes: 83 additions & 0 deletions test/Output/ActualConsoleWriterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;

namespace Vertical.SpectreLogger.Tests.Output
{
public class ActualConsoleWriterTests
{
[Fact]
public async Task WriteInBackground()
{
var services = new ServiceCollection()
.AddLogging(builder => builder.AddSpectreConsole(
config =>
{
config.WriteInBackground();
}))
.BuildServiceProvider();

var logger = services.GetRequiredService<ILogger<ActualConsoleWriterTests>>();

logger.LogInformation("Test event successful");

await services.DisposeAsync();
}

[Fact]
public async Task WriteInForeground()
{
var services = new ServiceCollection()
.AddLogging(builder => builder.AddSpectreConsole(
config =>
{
config.WriteInForeground();
}))
.BuildServiceProvider();

var logger = services.GetRequiredService<ILogger<ActualConsoleWriterTests>>();

logger.LogInformation("Test event successful");

await services.DisposeAsync();
}

[Fact]
public async Task WriteErrorInBackground()
{
var services = new ServiceCollection()
.AddLogging(builder => builder.AddSpectreConsole(
config =>
{
config.WriteInBackground();
}))
.BuildServiceProvider();

var logger = services.GetRequiredService<ILogger<ActualConsoleWriterTests>>();

logger.LogError(new ArgumentException(), "Oops");

await services.DisposeAsync();
}

[Fact]
public async Task WriteErrorInForeground()
{
var services = new ServiceCollection()
.AddLogging(builder => builder.AddSpectreConsole(
config =>
{
config.WriteInForeground();
}))
.BuildServiceProvider();

var logger = services.GetRequiredService<ILogger<ActualConsoleWriterTests>>();

logger.LogError(new ArgumentException(), "Oops");

await services.DisposeAsync();
}
}
}
Loading