Skip to content

Commit

Permalink
fix: stopping : being at the start of all log messages (MirageNet#606
Browse files Browse the repository at this point in the history
)

* fix: stopping `: ` being at the start of all log messages

* tests for extension methods
  • Loading branch information
James-Frowen committed Feb 18, 2021
1 parent dbf5784 commit 8efe7ce
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/LogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static class ILoggerExtensions
{
public static void LogError(this ILogger logger, object message)
{
logger.LogError(null, message);
logger.Log(LogType.Error, message);
}

public static void LogWarning(this ILogger logger, object message)
{
logger.LogWarning(null, message);
logger.Log(LogType.Warning, message);
}

public static bool LogEnabled(this ILogger logger) => logger.IsLogTypeAllowed(LogType.Log);
Expand Down
57 changes: 54 additions & 3 deletions Assets/Tests/Editor/LogFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NSubstitute;
using NSubstitute;
using NUnit.Framework;
using UnityEngine;

Expand Down Expand Up @@ -43,8 +43,59 @@ public void LogDebugFull()

ILogHandler mockHandler = Substitute.For<ILogHandler>();
logger.logHandler = mockHandler;
logger.Log("This message be logged");
mockHandler.Received().LogFormat(LogType.Log, null, "{0}", "This message be logged");
const string msg = "This message be logged";
logger.Log(msg);
mockHandler.Received().LogFormat(LogType.Log, null, "{0}", msg);
}

[Test]
public void LogWarningIgnore()
{
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
logger.filterLogType = LogType.Error;

ILogHandler mockHandler = Substitute.For<ILogHandler>();
logger.logHandler = mockHandler;
logger.LogWarning("This message should not be logged");
mockHandler.DidNotReceiveWithAnyArgs().LogFormat(default, null, null);
}

[Test]
public void LogWarningFull()
{
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
logger.filterLogType = LogType.Warning;

ILogHandler mockHandler = Substitute.For<ILogHandler>();
logger.logHandler = mockHandler;
const string msg = "This message be logged";
logger.LogWarning(msg);
mockHandler.Received().LogFormat(LogType.Warning, null, "{0}", msg);
}

[Test]
public void LogErrorIgnore()
{
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
logger.filterLogType = LogType.Exception;

ILogHandler mockHandler = Substitute.For<ILogHandler>();
logger.logHandler = mockHandler;
logger.LogError("This message should not be logged");
mockHandler.DidNotReceiveWithAnyArgs().LogFormat(default, null, null);
}

[Test]
public void LogErrorFull()
{
ILogger logger = LogFactory.GetLogger<LogFactoryTests>();
logger.filterLogType = LogType.Error;

ILogHandler mockHandler = Substitute.For<ILogHandler>();
logger.logHandler = mockHandler;
const string msg = "This message be logged";
logger.LogError(msg);
mockHandler.Received().LogFormat(LogType.Error, null, "{0}", msg);
}
}
}

0 comments on commit 8efe7ce

Please sign in to comment.