Skip to content

Commit

Permalink
refactor: roll back unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa committed Nov 30, 2024
1 parent 188ba33 commit ddee333
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 54 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/install_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
# Don't cancel other runners if one fails.
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
# Also try windows-2019?
os: [ macos-latest, ubuntu-latest, windows-2019 ]
defaults:
run:
# Use bash shells on all platforms.
Expand All @@ -45,15 +46,14 @@ jobs:
run: |
# Use tool to install Godot. Last line of output is the path to the
# symlink that always points to the active version of Godot.
dotnet run --no-build -- godot install 3.5.3
dotnet run -- godot install 3.5.3
- name: 🤖 Check Godot Location
working-directory: GodotEnv
run: |
# Get path to the symlink that always points to the active version of
# Godot.
dotnet run --no-build -- godot env path > godot_path.txt
GODOT_SYMLINK=$(<godot_path.txt)
GODOT_SYMLINK="$(dotnet run -- godot env path)"
echo "🕵️‍♂️ Godot symlink path: $GODOT_SYMLINK"
Expand Down Expand Up @@ -131,15 +131,14 @@ jobs:
run: |
# Use tool to install Godot. Last line of output is the path to the
# symlink that always points to the active version of Godot.
dotnet run --no-build -- godot install ${{ matrix.version }}
dotnet run -- godot install ${{ matrix.version }}
- name: 🤖 Check Godot Location
working-directory: GodotEnv
run: |
# Get path to the symlink that always points to the active version of
# Godot.
dotnet run --no-build -- godot env path > godot_path.txt
GODOT_SYMLINK=$(<godot_path.txt)
GODOT_SYMLINK="$(dotnet run -- godot env path)"
echo "🕵️‍♂️ Godot symlink path: $GODOT_SYMLINK"
Expand All @@ -151,7 +150,7 @@ jobs:
- name: 🌴 Set GODOT System Environment Variable
working-directory: GodotEnv
run: |
dotnet run --no-build -- godot env setup
dotnet run -- godot env setup
- name: 🧪 Verify GODOT System Environment Variable
working-directory: GodotEnv
Expand Down
18 changes: 9 additions & 9 deletions GodotEnv.Tests/src/common/utilities/LogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Chickensoft.GodotEnv.Tests;

public sealed class LogTest : IDisposable {

private readonly OutputTestFakeInMemoryConsole _console = new();
private readonly OutputTestFakeInMemoryConsole _console = new ();

public void Dispose() => _console.Dispose();

[Fact]
public void Prints() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Print("Hello, world!");

Expand All @@ -26,7 +26,7 @@ public void Prints() {

[Fact]
public void PrintsInfo() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Info("Hello, world!");

Expand All @@ -35,7 +35,7 @@ public void PrintsInfo() {

[Fact]
public void PrintsWarning() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Warn("Hello, world!");

Expand All @@ -44,7 +44,7 @@ public void PrintsWarning() {

[Fact]
public void PrintsErr() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Err("Hello, world!");

Expand All @@ -53,7 +53,7 @@ public void PrintsErr() {

[Fact]
public void PrintsSuccess() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Success("Hello, world!");

Expand All @@ -68,7 +68,7 @@ public void GetsColorNames() {

[Fact]
public void OutputsCorrectStyleChanges() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Print("A");
log.Print("");
Expand Down Expand Up @@ -106,7 +106,7 @@ public void OutputsCorrectStyleChanges() {

[Fact]
public void OutputsNull() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Print(null);
log.Info(null);
Expand All @@ -120,7 +120,7 @@ public void OutputsNull() {

[Fact]
public void OutputsObject() {
Log log = new(_console) { TestEnvironment = true };
Log log = new(_console);

log.Print(new { Hello = "world" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class AddonsCommandTest {
public async Task Executes() {
var context = new Mock<IExecutionContext>();
var console = new FakeInMemoryConsole();
// Use real log to test colors in output
var log = new Log(console) { TestEnvironment = true };
var log = new Log(console); // Use real log to test colors in output

context.Setup(context => context.CreateLog(console)).Returns(log);

Expand Down
43 changes: 8 additions & 35 deletions GodotEnv/src/common/utilities/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ILog {
/// <param name="message">Error message.</param>
void Err(object? message);
/// <summary>Print an error message to the console in place.</summary>
/// <param name="message">Error message.</param>m>
/// <param name="message">Error message.</param>
void ErrInPlace(object? message);
/// <summary>Print a message to the console.</summary>
/// <param name="message">Message.</param>
Expand Down Expand Up @@ -74,7 +74,6 @@ private record Style(

public IConsole Console { get; }

public bool TestEnvironment { get; init; }
private ConsoleWriter OutputConsole => Console.Output;
private readonly StringBuilder _sb = new();
private readonly ConsoleColor _defaultFgColor;
Expand All @@ -86,20 +85,12 @@ private record Style(
// running an environment without an actual console. Redirected environments
// cause errors when manipulating the cursor on Windows.
public bool IsInRedirectedEnv =>
!TestEnvironment && (
Console.IsOutputRedirected ||
Console.IsErrorRedirected ||
Environment.GetEnvironmentVariable("CI") != null
);
Console.IsOutputRedirected || Console.IsErrorRedirected;

public Log(IConsole console) {
Console = console;


if (IsInRedirectedEnv) {
System.Console.Clear();
}
else {
if (!IsInRedirectedEnv) {
console.ResetColor();
}

Expand Down Expand Up @@ -152,23 +143,16 @@ public void ClearLastLine() {
}

public void Output(
object? message,
Action<IConsole> consoleStyle,
bool inPlace = false,
bool addExtraLine = true
object? message, Action<IConsole> consoleStyle, bool inPlace = false, bool addExtraLine = true
) {
if (inPlace && IsInRedirectedEnv) {
// Don't print in-place messages in a redirected environment, like
// GitHub actions.
return;
}
lock (Console) {
if (!IsInRedirectedEnv) {
// Set the new foreground and background colors.
// Don't want to do this in redirected environments
// (like GitHub action shells)
consoleStyle(Console);
}
// Set the new foreground and background colors.
consoleStyle(Console);

if (
(message is string str && str != "") ||
Expand All @@ -189,23 +173,12 @@ message is not string and not null
OutputConsole.Write(message);
}
else {
if (IsInRedirectedEnv) {
System.Console.WriteLine(message);
}
else {
OutputConsole.WriteLine(message);
}
OutputConsole.WriteLine(message);
}
_sb.AppendLine(message?.ToString());

if (addExtraLine) {
if (IsInRedirectedEnv) {
System.Console.WriteLine();
}
else {
OutputConsole.WriteLine();
}

OutputConsole.WriteLine();
_sb.AppendLine();
}

Expand Down

0 comments on commit ddee333

Please sign in to comment.