[xbuild] Clean up test logs.
[mono.git] / mcs / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / FindAppConfigFileTest.cs
1 //
2 // FindAppConfigFileTest.cs
3 //
4 // Author:
5 //   Ankit Jain (jankit@novell.com)
6 //
7 // Copyright 2009 Novell, Inc (http://www.novell.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 #if NET_3_5
29
30 using System;
31 using System.Collections;
32 using Microsoft.Build.BuildEngine;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Tasks;
35 using Microsoft.Build.Utilities;
36 using NUnit.Framework;
37 using System.Text;
38
39 namespace MonoTests.Microsoft.Build.Tasks {
40
41         [TestFixture]
42         public class FindAppConfigFileTest {
43
44                 [Test]
45                 public void TestExecution1 ()
46                 {
47                         CheckOutput (new string [] {"app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List1 Foo.exe.config");
48                 }
49
50                 [Test]
51                 public void TestExecution2 ()
52                 {
53                         CheckOutput (new string [] {"foobar"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
54                 }
55
56                 [Test]
57                 public void TestExecution3 ()
58                 {
59                         CheckOutput (new string [] {"foo\\app.config"}, new string [] {"app.config"}, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
60                 }
61
62                 [Category ("NotWorking")]
63                 [Test]
64                 public void TestExecution4 ()
65                 {
66                         CheckOutput (new string[] { "foo\\app.config" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: foo\\app.config List1 Foo.exe.config");
67                 }
68
69                 [Category ("NotWorking")]
70                 [Test]
71                 public void TestExecution5 ()
72                 {
73                         CheckOutput (new string[] { "foobar" }, new string[] { "bar\\app.config" }, "AppConfigWithTargetPath: bar\\app.config List2 Foo.exe.config");
74                 }
75
76                 [Test]
77                 public void TestExecution6 ()
78                 {
79                         CheckOutput (new string[] { "foobar" }, new string[] { "bar\\foo.config" }, "AppConfigWithTargetPath:   ");
80                 }
81
82                 [Test]
83                 public void TestExecution7 () {
84                         CheckOutput (new string[] { ".\\app.config" }, new string[] { "app.config" }, "AppConfigWithTargetPath: app.config List2 Foo.exe.config");
85                 }
86
87                 void CheckOutput (string[] primary_list, string[] secondary_list, string expected) {
88                         StringBuilder sb = new StringBuilder ();
89
90                         sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + ">");
91                         sb.Append ("\t<ItemGroup>");
92                         if (primary_list != null)
93                                 foreach (string s in primary_list)
94                                         sb.AppendFormat ("\t\t<List1 Include=\"{0}\"><Source>List1</Source></List1>", s);
95
96                         if (secondary_list != null)
97                                 foreach (string s in secondary_list)
98                                         sb.AppendFormat ("\t\t<List2 Include=\"{0}\"><Source>List2</Source></List2>", s);
99                         sb.Append ("\t</ItemGroup>");
100
101                         sb.Append (@"
102                                         <Target Name='1'>
103                                                 <FindAppConfigFile PrimaryList=""@(List1)"" SecondaryList=""@(List2)"" TargetPath=""Foo.exe.config"">
104                                                         <Output TaskParameter=""AppConfigFile"" ItemName=""AppConfigWithTargetPath""/>
105                                                 </FindAppConfigFile>
106
107                                                 <Message Text=""AppConfigWithTargetPath: %(AppConfigWithTargetPath.Identity) %(AppConfigWithTargetPath.Source) %(AppConfigWithTargetPath.TargetPath)""/>
108                                         </Target>
109                                 </Project>");
110
111                         string projectXml = sb.ToString ();
112                         Engine engine = new Engine (Consts.BinPath);
113                         TestMessageLogger testLogger = new TestMessageLogger ();
114                         engine.RegisterLogger (testLogger);
115
116                         Project project = engine.CreateNewProject ();
117                         project.LoadXml (projectXml);
118                         if (!project.Build ("1")) {
119                                 testLogger.DumpMessages ();
120                                 Assert.Fail ("Build failed");
121                         }
122
123                         Assert.AreEqual (1, testLogger.NormalMessageCount, "Expected number of messages");
124                         testLogger.CheckLoggedMessageHead (expected, "A1");
125                 }
126         }
127 }       
128 #endif