Skip to content

Commit

Permalink
Merge pull request #308 from kindermannhubert/MainMethod_Version_Show…
Browse files Browse the repository at this point in the history
…sVersion-flakiness

Fix (hopefully) of MainMethod_Version_ShowsVersion flakiness.
  • Loading branch information
kindermannhubert authored Sep 28, 2023
2 parents 9b1f059 + 537a228 commit 0b64daf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CSharpRepl.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public async Task MainMethod_CannotParse_DoesNotThrow()
/// </summary>
public sealed class OutputCollector : IDisposable
{
private static readonly Semaphore semaphore = new(1, 1);

private readonly TextWriter normalStandardOutput;
private readonly TextWriter normalStandardError;
private readonly StringWriter fakeConsoleOutput;
private readonly StringWriter fakeConsoleError;
private static readonly Semaphore semaphore = new(1, 1);

private OutputCollector()
{
Expand Down
46 changes: 27 additions & 19 deletions CSharpRepl.Tests/TraceLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,38 @@ public class TraceLoggerTests
[Fact]
public void Create_ThenLog_WritesToFile()
{
var path = Path.GetTempFileName();
var logger = TraceLogger.Create(path);

logger.Log("Hello World, I'm a hopeful and optimistic REPL.");
logger.Log(() => "Arrgghh an error");

var loggedLines = File.ReadAllLines(path);
Assert.Contains("Trace session starting", loggedLines[0]);
Assert.Contains("Hello World, I'm a hopeful and optimistic REPL.", loggedLines[1]);
Assert.Contains("Arrgghh an error", loggedLines[2]);
//TraceLogger writes to console and we need to eliminate collision between threads (https://github.com/waf/CSharpRepl/issues/307).
using (OutputCollector.Capture(out _))
{
var path = Path.GetTempFileName();
var logger = TraceLogger.Create(path);

logger.Log("Hello World, I'm a hopeful and optimistic REPL.");
logger.Log(() => "Arrgghh an error");

var loggedLines = File.ReadAllLines(path);
Assert.Contains("Trace session starting", loggedLines[0]);
Assert.Contains("Hello World, I'm a hopeful and optimistic REPL.", loggedLines[1]);
Assert.Contains("Arrgghh an error", loggedLines[2]);
}
}

[Fact]
public void LogPaths_GivenPaths_GroupsByPrefix()
{
var path = Path.GetTempFileName();
var logger = TraceLogger.Create(path);

logger.LogPaths("Some Files", () => new[] { @"/Foo/Bar.txt", @"/Foo/Baz.txt" });

var loggedLines = File.ReadAllLines(path);
Assert.Contains("Trace session starting", loggedLines[0]);
Assert.Contains(@"Some Files: ", loggedLines[1]);
Assert.EndsWith(@"[""Bar.txt"", ""Baz.txt""]", loggedLines[1]);
//TraceLogger writes to console and we need to eliminate collision between threads (https://github.com/waf/CSharpRepl/issues/307).
using (OutputCollector.Capture(out _))
{
var path = Path.GetTempFileName();
var logger = TraceLogger.Create(path);

logger.LogPaths("Some Files", () => new[] { @"/Foo/Bar.txt", @"/Foo/Baz.txt" });

var loggedLines = File.ReadAllLines(path);
Assert.Contains("Trace session starting", loggedLines[0]);
Assert.Contains(@"Some Files: ", loggedLines[1]);
Assert.EndsWith(@"[""Bar.txt"", ""Baz.txt""]", loggedLines[1]);
}
}
}

Expand Down

0 comments on commit 0b64daf

Please sign in to comment.