Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed May 9, 2024
1 parent 2b7a566 commit 1dec119
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Runtime/Loggers/CompositeLoggerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override ILogger Logger
/// <inheritdoc />
public override void Dispose()
{
_handler.Dispose();
_handler?.Dispose();
}

private class CompositeLogHandler : ILogHandler, IDisposable
Expand Down
18 changes: 12 additions & 6 deletions Tests/Runtime/Loggers/CompositeLoggerSettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ private static Exception CreateExceptionWithStacktrace(string message)
[Test]
public void LogFormat_CompositeMultipleLoggers_OutputBothLoggers()
{
var message = TestContext.CurrentContext.Test.Name;
var logger1 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(logger1);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);

Assert.That(logger1.Logs, Does.Contain(message));
Expand All @@ -42,12 +42,12 @@ public void LogFormat_CompositeMultipleLoggers_OutputBothLoggers()
[Test]
public void LogFormat_LoggersIncludesNull_IgnoreNull()
{
var message = TestContext.CurrentContext.Test.Name;
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(null);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);

Assert.That(logger2.Logs, Does.Contain(message));
Expand All @@ -56,12 +56,12 @@ public void LogFormat_LoggersIncludesNull_IgnoreNull()
[Test]
public void LogFormat_NestingLogger_IgnoreNested()
{
var message = TestContext.CurrentContext.Test.Name;
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(sut); // nesting
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);

Assert.That(logger2.Logs, Does.Contain(message));
Expand All @@ -70,13 +70,13 @@ public void LogFormat_NestingLogger_IgnoreNested()
[Test]
public void LogException_CompositeMultipleLoggers_OutputBothLoggers()
{
var message = TestContext.CurrentContext.Test.Name;
var logger1 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(logger1);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
var exception = CreateExceptionWithStacktrace(message);
sut.Logger.LogException(exception);

Expand All @@ -87,12 +87,12 @@ public void LogException_CompositeMultipleLoggers_OutputBothLoggers()
[Test]
public void LogException_LoggersIncludesNull_IgnoreNull()
{
var message = TestContext.CurrentContext.Test.Name;
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(null);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
var exception = CreateExceptionWithStacktrace(message);
sut.Logger.LogException(exception);

Expand All @@ -102,12 +102,12 @@ public void LogException_LoggersIncludesNull_IgnoreNull()
[Test]
public void LogException_NestingLogger_IgnoreNested()
{
var message = TestContext.CurrentContext.Test.Name;
var logger2 = ScriptableObject.CreateInstance<SpyLoggerSettings>();
var sut = ScriptableObject.CreateInstance<CompositeLoggerSettings>();
sut.loggerSettings.Add(sut); // nesting
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
var exception = CreateExceptionWithStacktrace(message);
sut.Logger.LogException(exception);

Expand All @@ -123,6 +123,8 @@ public void Dispose_CompositeMultipleLoggers_DisposeAllLoggers()
sut.loggerSettings.Add(logger1);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);
sut.Dispose();

Assert.That(logger1.Disposed, Is.True);
Expand All @@ -137,6 +139,8 @@ public void Dispose_LoggersIncludesNull_IgnoreNull()
sut.loggerSettings.Add(null);
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);
sut.Dispose();

Assert.That(logger2.Disposed, Is.True);
Expand All @@ -150,6 +154,8 @@ public void Dispose_NestingLogger_IgnoreNested()
sut.loggerSettings.Add(sut); // nesting
sut.loggerSettings.Add(logger2);

var message = TestContext.CurrentContext.Test.Name;
sut.Logger.Log(message);
sut.Dispose();

Assert.That(logger2.Disposed, Is.True);
Expand Down

0 comments on commit 1dec119

Please sign in to comment.