Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / class / Microsoft.Build / Test / Microsoft.Build.Logging / ConsoleLoggerTest.cs
1 //
2 // ConsoleLoggerTest.cs
3 //
4 // Author:
5 //   Atsushi Enomoto (atsushi@xamarin.com)
6 //
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.IO;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Logging;
33 using NUnit.Framework;
34
35 namespace MonoTests.Microsoft.Build.Logging
36 {
37         [TestFixture]
38         public class ConsoleLoggerTest
39         {
40                 // Unfortunately, the existing code in MS.Build.Engine.dll has slightly different
41                 // format. We'd rather use already complete implementation, just disabled this test.
42                 [Test]
43                 [Category ("NotWorking")]
44                 public void BasicLoggerUsage ()
45                 {
46                         string expected = @"file : cat error code: msg
47
48 file : cat warning code: msg
49
50 __________________________________________________
51
52 Project ""project.txt"" (target target(s)):
53
54
55
56 Build started 2013/01/01 00:00:00.
57
58 Target ""target"" in file ""target.txt"":
59
60   start task
61
62   finished task
63
64 finished target
65
66
67
68 finished project
69
70
71
72 finished build
73
74
75
76 Time Elapsed 00:00:00.01
77
78 ".Replace ("\r\n", "\n");
79                         var sw = new StringWriter();
80                         var e = new ConsoleLogger(LoggerVerbosity.Diagnostic, msg => sw.WriteLine(msg), c => {}, () => {});
81                         e.Verbosity = LoggerVerbosity.Diagnostic;
82                         e.ErrorHandler (null, new BuildErrorEventArgs ("cat", "code", "file", 0, 0, 0, 0, "msg", "help", "sender"));
83                         e.WarningHandler (null, new BuildWarningEventArgs ("cat", "code", "file", 0, 0, 0, 0, "msg", "help", "sender"));
84                         e.ProjectStartedHandler (null, new ProjectStartedEventArgs ("start project", "HELPME", "project.txt", "target", null, null));
85                         e.BuildStartedHandler (null, new BuildStartedEventArgs ("start build", "HELPME", new DateTime (2013, 1, 1)));
86                         e.TargetStartedHandler (null, new TargetStartedEventArgs ("start target", "HELPME", "target", "project.txt", "target.txt"/*, "parent"*/));
87                         e.TaskStartedHandler (null, new TaskStartedEventArgs ("start task", "HELPME", "project.txt", "task.txt", "task"));
88                         e.TaskFinishedHandler (null, new TaskFinishedEventArgs ("finished task", "HELPME", "project.txt", "task.txt", "task", false));
89                         e.TargetFinishedHandler (null, new TargetFinishedEventArgs ("finished target", "HELPME", "target", "project.txt", "target.txt", false));
90                         e.ProjectFinishedHandler (null, new ProjectFinishedEventArgs ("finished project", "HELPME", "project.txt", false));
91                         e.BuildFinishedHandler (null, new BuildFinishedEventArgs ("finished build", "HELPME", false, new DateTime (2013, 1, 1).AddMilliseconds (1)));
92
93                         e.CustomEventHandler(null, new MyCustomBuildEventArgs ());
94                         Assert.AreEqual (expected, sw.ToString ().Replace ("\r\n", "\n"), "#1");
95                 }
96         }
97         
98         class MyCustomBuildEventArgs : CustomBuildEventArgs
99         {
100         }
101 }
102