public void DefaultDebuggerCanUseStaticallyControlledWriters() { var writer = new MockWriter(); try { PrintLineDebugger.Default.Value.Log("outOfContext1"); // This pattern is useful when debugging msbuild under VS / CLI, not individual tests under CI // The writer would be set at the start of each central and out of proc node, and the ID could be used to pick which file to dump the logs in (per process, per class emitting the log, etc) PrintLineDebugger.SetWriter(writer.Writer()); PrintLineDebugger.Default.Value.Log("inner"); } finally { PrintLineDebugger.UnsetWriter(); } PrintLineDebugger.Default.Value.Log("outOfContext2"); writer.Logs.ShouldNotBeEmpty(); writer.Logs[0].ShouldEndWith("inner"); writer.Logs.Count.ShouldBe(1); AssertContextInfo(writer.Logs); }
public void CannotUnsetWriterWhenNoWriterIsSet() { PrintLineDebugger.SetWriter(new MockWriter().Writer()); PrintLineDebugger.UnsetWriter(); using (var env = TestEnvironment.Create()) { env.SetEnvironmentVariable("MSBUILDDONOTLAUNCHDEBUGGER", "1"); Should.Throw <Exception>( () => { PrintLineDebugger.UnsetWriter(); }); } PrintLineDebugger.SetWriter(new MockWriter().Writer()); PrintLineDebugger.UnsetWriter(); }