//
// Properties.cs
//
-// Author:
+// Authors:
// Marek Sieradzki (marek.sieradzki@gmail.com)
+// Marek Safar (marek.safar@gmail.com)
//
// (C) 2006 Marek Sieradzki
//
namespace MonoTests.Microsoft.Build.BuildEngine.Various {
[TestFixture]
public class Properties {
- [Test]
- public void TestProperties ()
+
+ Project proj;
+
+ [SetUp]
+ public void Setup ()
{
Engine engine = new Engine (Consts.BinPath);
- Project proj = engine.CreateNewProject ();
+ proj = engine.CreateNewProject ();
+ }
+ [Test]
+ public void PropertyReference ()
+ {
string documentString = @"
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<Config>debug</Config>
<ExpProp>$(Config)-$(Config)</ExpProp>
+ <ExpProp2> $(Config) $(Config) </ExpProp2>
+ <InvProp1>$(Config-$(Config)</InvProp1>
</PropertyGroup>
</Project>
";
Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
+ Assert.AreEqual (" debug debug ", proj.GetEvaluatedProperty ("ExpProp2"), "A4");
+ Assert.AreEqual ("$(Config-$(Config)", proj.GetEvaluatedProperty ("InvProp1"), "A5");
+ }
+
+ [Test]
+ [Category ("NotDotNet")]
+ public void PropertyReference2 ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
+ <PropertyGroup>
+ <A>A</A>
+ <B>B</B>
+ </PropertyGroup>
+
+ <Target Name='Main' >
+ <StringTestTask Array='$(A)$(B)'>
+ <Output TaskParameter='Array' ItemName='Out' />
+ </StringTestTask>
+ </Target>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ proj.Build ("Main");
+ Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("Out").Count, "A1");
+ Assert.AreEqual ("AB", proj.GetEvaluatedItemsByName ("Out") [0].Include, "A2");
+ }
+
+ [Test]
+ public void StringInstanceProperties ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Config>debug</Config>
+ <NullValue>null</NullValue>
+ <TargetValue> </TargetValue>
+ <Prop1>$(Config.Substring(0,3)) </Prop1>
+ <Prop2>$(Config.Length )</Prop2>
+ <Prop3>$(Config.StartsWith ('DE', System.StringComparison.OrdinalIgnoreCase))</Prop3>
+ <Prop4>$(NullValue.StartsWith ('Te', StringComparison.OrdinalIgnoreCase))</Prop4>
+ <Prop5>$(TargetValue.Trim('\\'))</Prop5>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual ("deb ", proj.GetEvaluatedProperty ("Prop1"), "#1");
+ Assert.AreEqual ("5", proj.GetEvaluatedProperty ("Prop2"), "#2");
+ Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop3"), "#3");
+ Assert.AreEqual ("False", proj.GetEvaluatedProperty ("Prop4"), "#4");
+ Assert.AreEqual ("", proj.GetEvaluatedProperty ("Prop5"), "#5");
+ }
+
+ [Test]
+ public void AllowedFrameworkMembers ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Prop1>$([System.Byte]::MaxValue)</Prop1>
+ <Prop2>$([System.math]::Abs (-4.2) )</Prop2>
+ <Prop3>$([System.DateTime]::Today )</Prop3>
+ <Prop4>$([System.Char]::GetNumericValue('3'))</Prop4>
+ <Prop5>$([System.String]::Compare (Null, nUll))</Prop5>
+ <Prop6>$([System.Environment]::GetLogicalDrives ( ))</Prop6>
+ <Prop7>$([System.String]::Concat (`,`, `n`, `,`))</Prop7>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual ("255", proj.GetEvaluatedProperty ("Prop1"), "#1");
+ Assert.AreEqual ("4.2", proj.GetEvaluatedProperty ("Prop2"), "#2");
+ Assert.AreEqual (DateTime.Today.ToString (), proj.GetEvaluatedProperty ("Prop3"), "#3");
+ Assert.AreEqual ("3", proj.GetEvaluatedProperty ("Prop4"), "#4");
+ Assert.AreEqual ("0", proj.GetEvaluatedProperty ("Prop5"), "#5");
+ Assert.AreEqual (string.Join (";", Environment.GetLogicalDrives ()), proj.GetEvaluatedProperty ("Prop6"), "#6");
+ Assert.AreEqual (",n,", proj.GetEvaluatedProperty ("Prop7"), "#7");
+ }
+
+ [Test]
+ public void InstanceMethodOnStaticProperty ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Prop1>$([System.DateTime]::Now.ToString(""yyyy.MM.dd""))</Prop1>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual (DateTime.Now.ToString ("yyyy.MM.dd"), proj.GetEvaluatedProperty ("Prop1"), "#1");
+ }
+
+ [Test]
+ public void InstanceMemberOnStaticProperty ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Prop1>$([System.DateTime]::Now.Year)</Prop1>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual (DateTime.Now.Year.ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
+ }
+
+ [Test]
+ public void InstanceMembersOnStaticMethod ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <Prop1>$([System.String]::Concat('a', 'bb', 'c').Length.GetHashCode ())</Prop1>
+
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual (4.GetHashCode ().ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
+ }
+
+ [Test]
+ public void MSBuildPropertyFunctions ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <NumberOne>0.6</NumberOne>
+ <NumberTwo>6</NumberTwo>
+ <Prop1>$([MSBuild]::Add($(NumberOne), $(NumberTwo)))</Prop1>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual ("6.6", proj.GetEvaluatedProperty ("Prop1"), "#1");
+ }
+
+ [Test]
+ public void Constructor ()
+ {
+ string documentString = @"
+ <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+ <PropertyGroup>
+ <NumberOne>0.6</NumberOne>
+ <NumberTwo>6</NumberTwo>
+ <Prop1>$([System.String]::new('value').EndsWith ('ue'))</Prop1>
+ </PropertyGroup>
+ </Project>
+ ";
+
+ proj.LoadXml (documentString);
+ Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop1"), "#1");
}
}
}