ongoing task database implementation.
[mono.git] / mcs / class / Microsoft.Build / Test / Microsoft.Build.Execution / BuildSubmissionTest.cs
1 //
2 // BuildSubmissionTest.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 using System;
29 using System.IO;
30 using System.Linq;
31 using System.Xml;
32 using Microsoft.Build.Construction;
33 using Microsoft.Build.Evaluation;
34 using Microsoft.Build.Execution;
35 using NUnit.Framework;
36 using Microsoft.Build.Logging;
37 using Microsoft.Build.Framework;
38 using System.Collections.Generic;
39
40 namespace MonoTests.Microsoft.Build.Execution
41 {
42         [TestFixture]
43         public class BuildSubmissionTest
44         {
45                 [Test]
46                 public void ResultBeforeExecute ()
47                 {
48                         string empty_project_xml = "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
49                         var path = "file://localhost/foo.xml";
50                         var xml = XmlReader.Create (new StringReader (empty_project_xml), null, path);
51                         var root = ProjectRootElement.Create (xml);
52                         var proj = new ProjectInstance (root);
53                         var bm = new BuildManager ();
54                         bm.BeginBuild (new BuildParameters ());
55                         var sub = bm.PendBuildRequest (new BuildRequestData (proj, new string [0]));
56                         Assert.IsNull (sub.BuildResult, "#1");
57                 }
58                 
59                 // This checks if the build output for each task is written to the loggers and not directly thrown as a Project loader error.
60                 [Test]
61                 public void TaskOutputsToLoggers ()
62                 {
63             string project_xml = @"<Project DefaultTargets='Foo;Bar' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
64   <Import Project='$(MSBuildToolsPath)\Microsoft.Common.targets' />
65   <Target Name='Foo'>
66     <ItemGroup>
67       <Foo Condition='$(X)' Include='foo.txt' />
68     </ItemGroup>
69   </Target>
70 </Project>";
71             var xml = XmlReader.Create (new StringReader (project_xml));
72             var root = ProjectRootElement.Create (xml);
73             var proj = new ProjectInstance (root);
74                         var sw = new StringWriter ();
75                         Assert.IsFalse (proj.Build (new ILogger [] {new ConsoleLogger (default (LoggerVerbosity), msg => sw.Write (msg), null, null)}), "#1");
76                         Assert.IsTrue (sw.ToString ().Contains ("$(X)"), "#2");
77                 }
78                 
79                 [Test]
80                 [Category ("NotWorking")]
81                 public void EndBuildWaitsForSubmissionCompletion ()
82                 {
83                         string project_xml = @"<Project DefaultTargets='Wait1Sec' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
84   <Target Name='Wait1Sec'>
85     <Exec Command='ping 10.1.1.1 -n 1 -w 1' />
86   </Target>
87 </Project>";
88                         var xml = XmlReader.Create (new StringReader (project_xml));
89                         var root = ProjectRootElement.Create (xml);
90                         var proj = new ProjectInstance (root);
91                         var bm = new BuildManager ();
92                         bm.BeginBuild (new BuildParameters ());
93                         DateTime waitDone = DateTime.MinValue;
94                         DateTime beforeExec = DateTime.Now;
95                         var sub = bm.PendBuildRequest (new BuildRequestData (proj, new string [] { "Wait5Sec" }));
96                         sub.ExecuteAsync (delegate { waitDone = DateTime.Now; }, null);
97                         bm.EndBuild ();
98                         Assert.IsTrue (sub.BuildResult.OverallResult == BuildResultCode.Success, "#1");
99                         DateTime endBuildDone = DateTime.Now;
100                         Assert.IsTrue (endBuildDone - beforeExec >= TimeSpan.FromSeconds (1), "#2");
101                         Assert.IsTrue (endBuildDone > waitDone, "#3");
102                 }
103         }
104 }
105