-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving TestOutputHelperExtensions and DebugHelper to Lombiq.Tests
- Loading branch information
1 parent
7ccf190
commit b965337
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Lombiq.Tests.Helpers; | ||
|
||
namespace Xunit.Abstractions; | ||
|
||
public static class TestOutputHelperExtensions | ||
{ | ||
public static void WriteLineTimestampedAndDebug(this ITestOutputHelper testOutputHelper, string format, params object[] args) | ||
{ | ||
testOutputHelper.WriteLineTimestamped(format, args); | ||
DebugHelper.WriteLineTimestamped(format, args); | ||
} | ||
|
||
public static void WriteLineTimestamped(this ITestOutputHelper testOutputHelper, string format, params object[] args) | ||
{ | ||
// Preventing "FormatException : Input string was not in a correct format." exceptions if the message contains | ||
// characters used in string formatting but it shouldn't actually be formatted. | ||
if (args == null || args.Length == 0) testOutputHelper.WriteLine(DebugHelper.PrefixWithTimestamp(format)); | ||
else testOutputHelper.WriteLine(DebugHelper.PrefixWithTimestamp(format), args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Lombiq.Tests.Helpers; | ||
|
||
public static class DebugHelper | ||
{ | ||
public static void WriteLineTimestamped(string format, params object[] args) | ||
{ | ||
// Preventing "FormatException : Input string was not in a correct format." exceptions if the message contains | ||
// characters used in string formatting but it shouldn't actually be formatted. | ||
if (args == null || args.Length == 0) Debug.WriteLine(PrefixWithTimestamp(format)); | ||
else Debug.WriteLine(PrefixWithTimestamp(format), args); | ||
} | ||
|
||
// Note that this uses UTC, while Atata's log uses the local time zone: | ||
// https://github.com/atata-framework/atata/issues/483. | ||
public static string PrefixWithTimestamp(string message) => | ||
$"{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffff", CultureInfo.InvariantCulture)} - {message}"; | ||
} |