Ensure MakeRelative() works even when basePath doesn't end in slash
[mono-project.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / PredefinedPropertyFunctionsTest.cs
blob1a4e4317421d460b5a13cc638b1514cddf5db232
1 //
2 // PredefinedPropertyFunctionsTest.cs
3 //
4 // Authors:
5 // Alexander Köplinger (alex.koeplinger@outlook.com)
6 //
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.
26 using System;
27 using Microsoft.Build.BuildEngine;
28 using NUnit.Framework;
30 namespace MonoTests.Microsoft.Build.BuildEngine {
31 [TestFixture]
32 public class PredefinedPropertyFunctionsTest {
34 [Test]
35 public void TestMakeRelative ()
37 string documentString = @"
38 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
39 <PropertyGroup>
40 <Path1>c:\users\</Path1>
41 <Path2>c:\users\username\</Path2>
42 <Path3>/home/user/</Path3>
43 <Path4>/home/user/username/</Path4>
44 <Path5>/home/user/</Path5>
45 <Path6>/tmp/test/file</Path6>
46 <Path7>/home/user/</Path7>
47 <Path8>/home/user/username/path with spaces + special? chars (1)/</Path8>
48 <Path9>c:\users</Path9>
49 <Path10>c:\users\username\test\</Path10>
50 <Path11>/home/user</Path11>
51 <Path12>/home/user/username/test/</Path12>
52 <MakeRelative1>$([MSBuild]::MakeRelative($(Path1), $(Path2)))</MakeRelative1>
53 <MakeRelative2>$([MSBuild]::MakeRelative($(Path2), $(Path1)))</MakeRelative2>
54 <MakeRelative3>$([MSBuild]::MakeRelative($(Path3), $(Path4)))</MakeRelative3>
55 <MakeRelative4>$([MSBuild]::MakeRelative($(Path4), $(Path3)))</MakeRelative4>
56 <MakeRelative5>$([MSBuild]::MakeRelative($(Path5), $(Path6)))</MakeRelative5>
57 <MakeRelative6>$([MSBuild]::MakeRelative($(Path7), $(Path8)))</MakeRelative6>
58 <MakeRelative7>$([MSBuild]::MakeRelative($(Path9), $(Path10)))</MakeRelative7>
59 <MakeRelative8>$([MSBuild]::MakeRelative($(Path11), $(Path12)))</MakeRelative8>
60 </PropertyGroup>
61 </Project>
64 var engine = new Engine (Consts.BinPath);
65 var project = engine.CreateNewProject ();
66 project.LoadXml (documentString);
68 Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative1"].FinalValue, "#1");
69 Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative2"].FinalValue, "#2");
70 Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative3"].FinalValue, "#3");
71 Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative4"].FinalValue, "#4");
72 Assert.AreEqual (@"..\..\tmp\test\file", project.EvaluatedProperties ["MakeRelative5"].FinalValue, "#5");
73 Assert.AreEqual (@"username\path with spaces + special? chars (1)\", project.EvaluatedProperties ["MakeRelative6"].FinalValue, "#6");
74 Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative7"].FinalValue, "#7");
75 Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative8"].FinalValue, "#8");