2 // PredefinedPropertyFunctionsTest.cs
5 // Alexander Köplinger (alex.koeplinger@outlook.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using Microsoft.Build.BuildEngine;
29 using NUnit.Framework;
31 namespace MonoTests.Microsoft.Build.BuildEngine {
33 public class PredefinedPropertyFunctionsTest {
36 public void TestMakeRelative ()
38 string documentString = @"
39 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
41 <Path1>c:\users\</Path1>
42 <Path2>c:\users\username\</Path2>
43 <Path3>/home/user/</Path3>
44 <Path4>/home/user/username/</Path4>
45 <Path5>/home/user/</Path5>
46 <Path6>/tmp/test/file</Path6>
47 <Path7>/home/user/</Path7>
48 <Path8>/home/user/username/path with spaces + special? chars (1)/</Path8>
49 <Path9>c:\users</Path9>
50 <Path10>c:\users\username\test\</Path10>
51 <Path11>/home/user</Path11>
52 <Path12>/home/user/username/test/</Path12>
53 <MakeRelative1>$([MSBuild]::MakeRelative($(Path1), $(Path2)))</MakeRelative1>
54 <MakeRelative2>$([MSBuild]::MakeRelative($(Path2), $(Path1)))</MakeRelative2>
55 <MakeRelative3>$([MSBuild]::MakeRelative($(Path3), $(Path4)))</MakeRelative3>
56 <MakeRelative4>$([MSBuild]::MakeRelative($(Path4), $(Path3)))</MakeRelative4>
57 <MakeRelative5>$([MSBuild]::MakeRelative($(Path5), $(Path6)))</MakeRelative5>
58 <MakeRelative6>$([MSBuild]::MakeRelative($(Path7), $(Path8)))</MakeRelative6>
59 <MakeRelative7>$([MSBuild]::MakeRelative($(Path9), $(Path10)))</MakeRelative7>
60 <MakeRelative8>$([MSBuild]::MakeRelative($(Path11), $(Path12)))</MakeRelative8>
65 if (Path.DirectorySeparatorChar == '\\') {
66 documentString = documentString.Replace ("/home", "c:/home");
67 documentString = documentString.Replace ("/tmp", "c:/tmp");
70 var engine = new Engine (Consts.BinPath);
71 var project = engine.CreateNewProject ();
72 project.LoadXml (documentString);
74 Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative1"].FinalValue, "#1");
75 Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative2"].FinalValue, "#2");
76 Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative3"].FinalValue, "#3");
77 Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative4"].FinalValue, "#4");
78 Assert.AreEqual (@"..\..\tmp\test\file", project.EvaluatedProperties ["MakeRelative5"].FinalValue, "#5");
79 Assert.AreEqual (@"username\path with spaces + special? chars (1)\", project.EvaluatedProperties ["MakeRelative6"].FinalValue, "#6");
80 Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative7"].FinalValue, "#7");
81 Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative8"].FinalValue, "#8");