public void TestMinimalWithError() { for (int i = 1; i <= 2; i++) { EventSource es = new EventSource(); SimulatedConsole sc = new SimulatedConsole(); ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es, i); BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); bse.BuildEventContext = buildEventContext; es.RaiseBuildStartedEvent(null, bse); ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); pse.BuildEventContext = buildEventContext; es.RaiseProjectStartedEvent(null, pse); TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); trse.BuildEventContext = buildEventContext; es.RaiseTargetStartedEvent(null, trse); TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); tase.BuildEventContext = buildEventContext; es.RaiseTaskStartedEvent(null, tase); BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); beea.BuildEventContext = buildEventContext; es.RaiseErrorEvent(null, beea); TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); tafea.BuildEventContext = buildEventContext; es.RaiseTaskFinishedEvent(null, tafea); TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); trfea.BuildEventContext = buildEventContext; es.RaiseTargetFinishedEvent(null, trfea); ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); pfea.BuildEventContext = buildEventContext; es.RaiseProjectFinishedEvent(null, pfea); BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); bfea.BuildEventContext = buildEventContext; es.RaiseBuildFinishedEvent(null, bfea); Console.WriteLine("=="); Console.WriteLine(sc.ToString()); Console.WriteLine("=="); if (i == 1) { Assertion.AssertEquals( "<cyan>" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + ResourceUtilities.FormatResourceString("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + "<reset color><red>file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + "<reset color><cyan>pf" + Environment.NewLine + "<reset color>", sc.ToString()); } else { Assertion.AssertEquals( "<red>file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + "<reset color>", sc.ToString()); } } }
private void RaiseEvents(EventSource source) { source.RaiseBuildStartedEvent(null, buildStarted); source.RaiseProjectStartedEvent(null, projectStarted); source.RaiseTargetStartedEvent(null, targetStarted); source.RaiseTaskStartedEvent(null, taskStarted); source.RaiseMessageEvent(null, lowMessage); source.RaiseMessageEvent(null, normalMessage); source.RaiseMessageEvent(null, highMessage); source.RaiseMessageEvent(null, commandLine); source.RaiseCustomEvent(null, externalStartedEvent); source.RaiseWarningEvent(null, warning); source.RaiseErrorEvent(null, error); source.RaiseTaskFinishedEvent(null, taskFinished); source.RaiseTargetFinishedEvent(null, targetFinished); source.RaiseProjectFinishedEvent(null, projectFinished); source.RaiseBuildFinishedEvent(null, buildFinished); }
public void ErrorColorTestParallel() { EventSource es = new EventSource(); SimulatedConsole sc = new SimulatedConsole(); ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es, 4); BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); beea.BuildEventContext = new BuildEventContext(1, 2, 3, 4); es.RaiseErrorEvent(null, beea); Assertion.AssertEquals( "<red>file.vb(42): VBC error 31415: Some long message" + Environment.NewLine +"<reset color>", sc.ToString()); }
public void ResetConsoleLoggerState_Initialize() { // Create an event source EventSource es = new EventSource(); //Create a simulated console SimulatedConsole sc = new SimulatedConsole(); // error and warning string for 1 error and 1 warning // errorString = 1 Error(s) // warningString = 1 Warning(s) string errorString = ResourceUtilities.FormatResourceString("ErrorCount", 1); string warningString = ResourceUtilities.FormatResourceString("WarningCount", 1); // Create a ConsoleLogger with Normal verbosity ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, sc.SetColor, sc.ResetColor); // Initialize ConsoleLogger L.Initialize(es); // BuildStarted Event es.RaiseBuildStartedEvent(null, new BuildStartedEventArgs("bs", null)); // Introduce a warning BuildWarningEventArgs bwea = new BuildWarningEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); es.RaiseWarningEvent(null, bwea); // Introduce an error BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); es.RaiseErrorEvent(null, beea); // NOTE: We don't call the es.RaiseBuildFinishedEvent(...) here as this // would call ResetConsoleLoggerState and we will fail to detect if Initialize() // is not calling it. // Log so far string actualLog = sc.ToString(); Console.WriteLine("=="); Console.WriteLine(sc.ToString()); Console.WriteLine("=="); // Verify that the log has correct error and warning string Assertion.Assert(actualLog.Contains("<red>")); Assertion.Assert(actualLog.Contains("<yellow>")); // Clear the log obtained so far sc.Clear(); //Initilialize (This should call ResetConsoleLoggerState(...)) L.Initialize(es); // BuildStarted event es.RaiseBuildStartedEvent(null, new BuildStartedEventArgs("bs", null)); // BuildFinished es.RaiseBuildFinishedEvent(null, new BuildFinishedEventArgs("bf", null, true)); // Log so far actualLog = sc.ToString(); Console.WriteLine("=="); Console.WriteLine(sc.ToString()); Console.WriteLine("=="); // Verify that the error and warning from the previous build is not // reported in the subsequent build Assertion.Assert(!actualLog.Contains("<red>")); Assertion.Assert(!actualLog.Contains("<yellow>")); // errorString = 0 Error(s) errorString = ResourceUtilities.FormatResourceString("ErrorCount", 0); // warningString = 0 Warning(s) warningString = ResourceUtilities.FormatResourceString("WarningCount", 0); // Verify that the log has correct error and warning string Assertion.Assert(actualLog.Contains(errorString)); Assertion.Assert(actualLog.Contains(warningString)); }
public void NullEventFieldsParallel() { EventSource es = new EventSource(); SimulatedConsole sc = new SimulatedConsole(); ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es, 2); BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); BuildStartedEventArgs bse = new BuildStartedEventArgs(null, null); bse.BuildEventContext = buildEventContext; ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, null, null, "p", null, null, null, buildEventContext); pse.BuildEventContext = buildEventContext; TargetStartedEventArgs trse = new TargetStartedEventArgs(null, null, "t", null, null); trse.BuildEventContext = buildEventContext; TaskStartedEventArgs tase = new TaskStartedEventArgs(null, null, null, null, "task"); tase.BuildEventContext = buildEventContext; BuildMessageEventArgs bmea = new BuildMessageEventArgs(null, null, null, MessageImportance.High); bmea.BuildEventContext = buildEventContext; BuildWarningEventArgs bwea = new BuildWarningEventArgs(null, null, null, 0, 0, 0, 0, null, null, null); bwea.BuildEventContext = buildEventContext; BuildErrorEventArgs beea = new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0, null, null, null); beea.BuildEventContext = buildEventContext; TaskFinishedEventArgs trfea = new TaskFinishedEventArgs(null, null, null, null, "task", true); trfea.BuildEventContext = buildEventContext; TargetFinishedEventArgs tafea = new TargetFinishedEventArgs(null, null, "t", null, null, true); tafea.BuildEventContext = buildEventContext; ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs(null, null, "p", true); pfea.BuildEventContext = buildEventContext; BuildFinishedEventArgs bfea = new BuildFinishedEventArgs(null, null, true); bfea.BuildEventContext = buildEventContext; MyCustomBuildEventArgs2 mcea = new MyCustomBuildEventArgs2(); mcea.BuildEventContext = buildEventContext; // Not all parameters are null here, but that's fine, we assume the engine will never // fire a ProjectStarted without a project name, etc. es.RaiseBuildStartedEvent(null, bse); es.RaiseProjectStartedEvent(null, pse); es.RaiseTargetStartedEvent(null, trse); es.RaiseTaskStartedEvent(null, tase); es.RaiseMessageEvent(null, bmea); es.RaiseWarningEvent(null, bwea); es.RaiseErrorEvent(null, beea); es.RaiseTaskFinishedEvent(null, trfea); es.RaiseTargetFinishedEvent(null, tafea); es.RaiseProjectFinishedEvent(null, pfea); es.RaiseBuildFinishedEvent(null, bfea); es.RaiseAnyEvent(null, bfea); es.RaiseStatusEvent(null, bfea); es.RaiseCustomEvent(null, mcea); // No exception raised }
public void NullEventFields() { EventSource es = new EventSource(); SimulatedConsole sc = new SimulatedConsole(); ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es); // Not all parameters are null here, but that's fine, we assume the engine will never // fire a ProjectStarted without a project name, etc. es.RaiseBuildStartedEvent(null, new BuildStartedEventArgs(null, null)); es.RaiseProjectStartedEvent(null, new ProjectStartedEventArgs(null, null, "p", null, null, null)); es.RaiseTargetStartedEvent(null, new TargetStartedEventArgs(null, null, "t", null, null)); es.RaiseTaskStartedEvent(null, new TaskStartedEventArgs(null, null, null, null, "task")); es.RaiseMessageEvent(null, new BuildMessageEventArgs(null, null, null, MessageImportance.High)); es.RaiseWarningEvent(null, new BuildWarningEventArgs(null, null, null, 0, 0, 0, 0, null, null, null)); es.RaiseErrorEvent(null, new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0, null, null, null)); es.RaiseTaskFinishedEvent(null, new TaskFinishedEventArgs(null, null, null, null, "task", true)); es.RaiseTargetFinishedEvent(null, new TargetFinishedEventArgs(null, null, "t", null, null, true)); es.RaiseProjectFinishedEvent(null, new ProjectFinishedEventArgs(null, null, "p", true)); es.RaiseBuildFinishedEvent(null, new BuildFinishedEventArgs(null, null, true)); es.RaiseAnyEvent(null, new BuildFinishedEventArgs(null, null, true)); es.RaiseStatusEvent(null, new BuildFinishedEventArgs(null, null, true)); es.RaiseCustomEvent(null, new MyCustomBuildEventArgs2()); // No exception raised }
public void NestedProjectMinimal() { EventSource es = new EventSource(); SimulatedConsole sc = new SimulatedConsole(); ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es, 1); es.RaiseBuildStartedEvent(null, new BuildStartedEventArgs("bs", null)); //Clear time dependant build started message sc.Clear(); es.RaiseProjectStartedEvent(null, new ProjectStartedEventArgs("ps1", null, "fname1", "", null, null)); es.RaiseTargetStartedEvent(null, new TargetStartedEventArgs("ts", null, "trname", "fname", "tfile")); es.RaiseProjectStartedEvent(null, new ProjectStartedEventArgs("ps2", null, "fname2", "", null, null)); Assertion.AssertEquals(string.Empty, sc.ToString()); BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); es.RaiseErrorEvent(null, beea); Assertion.AssertEquals( "<cyan>" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + ResourceUtilities.FormatResourceString("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname1") + Environment.NewLine + Environment.NewLine + "<reset color>" + "<cyan>" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + ResourceUtilities.FormatResourceString("ProjectStartedPrefixForNestedProjectWithDefaultTargets", "fname1", "fname2") + Environment.NewLine + Environment.NewLine + "<reset color>" + "<red>" + "file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + "<reset color>", sc.ToString()); }