2009-05-18 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / Build.cs
1 //
2 // Build.cs: Various build tests.
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2005 Marek Sieradzki
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.Collections;
30 using System.Xml;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Utilities;
34 using NUnit.Framework;
35
36 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
37         [TestFixture]
38         public class Build {
39                 [Test]
40                 public void TestBuild1 ()
41                 {
42                         Engine engine;
43                         Project project;
44
45                         string documentString = @"
46                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
47                                         <Target Name='1' DependsOnTargets='2'>
48                                         </Target>
49                                         <Target Name='2' DependsOnTargets='1'>
50                                         </Target>
51                                 </Project>
52                         ";
53
54                         engine = new Engine (Consts.BinPath);
55                         project = engine.CreateNewProject ();
56                         project.LoadXml (documentString);
57
58                         Assert.IsFalse (project.Build ("1"), "A1");
59                 }
60
61                 [Test]
62                 public void TestBuild2 ()
63                 {
64                         Engine engine;
65                         Project project;
66
67                         string documentString = @"
68                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
69                                         <Target Name='1' DependsOnTargets='2'>
70                                         </Target>
71                                 </Project>
72                         ";
73
74                         engine = new Engine (Consts.BinPath);
75                         project = engine.CreateNewProject ();
76                         project.LoadXml (documentString);
77
78                         Assert.IsFalse (project.Build ("1"));
79                 }
80
81                 [Test]
82                 public void TestBuild3 ()
83                 {
84                         Engine engine;
85                         Project project;
86
87                         string documentString = @"
88                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
89                                         <Target Name='A'>
90                                                 <Error Text='text' />
91                                                 <OnError ExecuteTargets='B' />
92                                         </Target>
93                                         <Target Name='B'>
94                                                 <CreateProperty Value='B'>
95                                                         <Output TaskParameter='Value' PropertyName='B'/>
96                                                 </CreateProperty>
97                                         </Target>
98                                 </Project>
99                         ";
100
101                         engine = new Engine (Consts.BinPath);
102                         project = engine.CreateNewProject ();
103                         project.LoadXml (documentString);
104
105                         Assert.IsFalse (project.Build ("A"), "A1");
106                         Assert.IsNotNull (project.EvaluatedProperties ["B"], "A2");
107                 }
108
109                 [Test]
110                 public void TestBuild4 ()
111                 {
112                         Engine engine;
113                         Project project;
114
115                         string documentString = @"
116                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
117                                         <Target Name='A'>
118                                                 <Error ContinueOnError='true' Text='text' />
119                                                 <CreateProperty Value='A'>
120                                                         <Output TaskParameter='Value' PropertyName='A'/>
121                                                 </CreateProperty>
122                                                 <OnError ExecuteTargets='B' />
123                                         </Target>
124                                         <Target Name='B'>
125                                                 <CreateProperty Value='B'>
126                                                         <Output TaskParameter='Value' PropertyName='B'/>
127                                                 </CreateProperty>
128                                         </Target>
129                                 </Project>
130                         ";
131
132                         engine = new Engine (Consts.BinPath);
133                         project = engine.CreateNewProject ();
134                         project.LoadXml (documentString);
135
136                         Assert.IsTrue (project.Build ("A"), "A1");
137                         Assert.IsNotNull (project.EvaluatedProperties ["A"], "A2");
138                         Assert.IsNull (project.EvaluatedProperties ["B"], "A3");
139                 }
140         }
141 }