Exemplo n.º 1
0
        public void TestEnvironmentBasedPrintLineDebuggerShouldWork()
        {
            var writer = new MockWriter();

            // loggers should not log anything if there's no static writer set
            // this is useful to enable logging just for the duration of one test
            PrintLineDebugger.Default.Value.Log("outOfContext1");

            // This pattern is useful when debugging individual tests under CI.
            // The TestEnvironment the writer, so the logs will only be collected during the test
            // Caveat: One cannot use writers instantiated in the test in out of proc nodes. Either turn multiproc off, or set the writer in each node, probably in OutOfProcNode.Run
            using (var env = TestEnvironment.Create())
            {
                env.CreatePrintLineDebugger(writer.Writer());

                PrintLineDebugger.Default.Value.Log("inner");
            }

            PrintLineDebugger.Default.Value.Log("outOfContext2");

            writer.Logs.ShouldNotBeEmpty();
            writer.Logs[0].ShouldEndWith("inner");
            writer.Logs.Count.ShouldBe(1);

            AssertContextInfo(writer.Logs);
        }
Exemplo n.º 2
0
        // This is one way to use the debugger without a TestEnvironment
        public void DefaultDebuggerShouldUseOuterDebuggerWriter()
        {
            var writer = new MockWriter();

            PrintLineDebugger.Default.Value.Log("outOfContext1");

            using (var logger = PrintLineDebugger.Create(writer.Writer()))
            {
                logger.Log("outer1");

                // this is what you'd litter throughout the codebase to gather random logs
                PrintLineDebugger.Default.Value.Log("inner");
                logger.Log("outer2");
            }

            PrintLineDebugger.Default.Value.Log("outOfContext2");

            writer.Logs.ShouldNotBeEmpty();
            writer.Logs[0].ShouldEndWith("outer1");
            writer.Logs[1].ShouldEndWith("inner");
            writer.Logs[2].ShouldEndWith("outer2");
            writer.Logs.Count.ShouldBe(3);

            AssertContextInfo(writer.Logs);
        }
Exemplo n.º 3
0
        public void CompositeWriterCanWriteToMultipleWriters()
        {
            var writer1 = new MockWriter();
            var writer2 = new MockWriter();

            var compositeWriter = new PrintLineDebuggerWriters.CompositeWriter(
                new []
            {
                writer1.Writer(),
                writer2.Writer()
            });

            using (var logger = PrintLineDebugger.Create(compositeWriter.Writer))
            {
                logger.Log("Hello World");
            }

            writer1.Logs.ShouldNotBeEmpty();
            writer1.Logs.First().ShouldEndWith("Hello World");
            writer1.Logs.ShouldHaveSingleItem();

            AssertContextInfo(writer1.Logs);

            writer1.Logs.ShouldBe(writer2.Logs, Case.Sensitive);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void DebuggerCanPrependAnId()
        {
            var writer = new MockWriter();

            using (var logger = PrintLineDebugger.Create(writer.Writer(), "foo"))
            {
                logger.Log("Hello World");
            }

            writer.Logs.ShouldNotBeEmpty();
            writer.Logs.First().ShouldEndWith("Hello World");
            writer.Logs.ShouldHaveSingleItem();

            AssertContextInfo(writer.Logs, "foo");
        }