Here is testcase covering all possible scenarios which comes to my mind. If
you see anything more those few let me know, I'll add it!

Martin
 

> -----Original Message-----
> From: Gert Driesen [mailto:[EMAIL PROTECTED] 
> Sent: Monday, June 13, 2005 10:11 PM
> To: 'Martin Aliger'; [email protected]
> Subject: RE: [nant-dev] RE: [ nant-Bugs-1210046 ] Fileset 
> fails when nested in an if block. - 0.85 RC2
> 
> Martin,
> 
> Can you also create unit tests for this change (covering both 
> success and failure scenario's) ? 
> 
> Thanks !
> 
> Gert
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of 
> > Martin Aliger
> > Sent: maandag 13 juni 2005 17:59
> > To: [email protected]
> > Subject: [nant-dev] RE: [ nant-Bugs-1210046 ] Fileset fails when 
> > nested in an if block. - 0.85 RC2
> > 
> > It seems I cannot add attachment on SF tracker. Silly.
> > 
> > Regards,
> > Martin
> > 
> > > Category: Core
> > > Group: 0.85
> > > Status: Open
> > > Resolution: None
> > > Priority: 5
> > > Submitted By: Hinrichs (thinrichs)
> > > Assigned to: Nobody/Anonymous (nobody)
> > > Summary: Fileset fails when nested in an if block. - 0.85 RC2
> > > 
> > > Initial Comment:
> > > I am running into an error which states "Unknown task <fileset>"  
> > > when I try to nest a fileset in an if block.  Of course, fileset 
> > > isnt a task.  It's a type, according to the NAnt documentation.
> > > The following code fails (this is not my actual code that is 
> > > failing, but does characterize the bug)
> > > 
> > > <fileset id="Files">
> > >       <include name="**">
> > > </fileset>
> > > <if test="{case=='SpecialCase'}>
> > >     <fileset id="Files">
> > >           <include name="**"/>
> > >           <exclude name="/specialCase/example.txt">
> > >      </fileset>
> > > </if>
> > > 
> > > code such as that above works fine, until case equals 
> 'SpecialCase'.  
> > > Interestingly the following also fails (but fails right away).
> > > 
> > > It still fails on the line in the commented out if block.
> > > <fileset id="Files">
> > >       <include name="**">
> > > </fileset>
> > > <! -- <if test="{case=='SpecialCase'}> -->
> > >     <fileset id="Files">
> > >           <include name="**"/>
> > >           <exclude name="/specialCase/example.txt">
> > >      </fileset>
> > > <!-- </if> -->
> > > 
> > > 
> > 
> ----------------------------------------------------------------------
> > > 
> > > Comment By: Martin Aliger (maliger)
> > > Date: 2005-06-13 17:55
> > > 
> > > Message:
> > > Logged In: YES
> > > user_id=655297
> > > 
> > > its by design in current sources. I just completed patch to allow 
> > > type definitions in nested blocks. Your second example is valid 
> > > though and it works for me (after correcting xml inline 
> elements). 
> > > Could you check it again and if still wrong explain it further?
> > 
> 
> 
// NAnt - A .NET build tool
// Copyright (C) 2001-2002 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Martin Aliger ([EMAIL PROTECTED])

using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Globalization;

using NUnit.Framework;

using NAnt.Core;
using NAnt.Core.Types;
using NAnt.Core.Attributes;

namespace Tests.NAnt.Core
{

        [TestFixture]
        public class TaskContainerTest : BuildTestBase 
        {
                #region Private Static Fields

                private const string _format1 = @"<?xml version='1.0' ?>
           <project name='testing' default='test'>
                <target name='test'>
                                        <if test='{0}'>
                                                <fileset id='foo'>
                                                        <include name='bar'/>
                                                </fileset>
                                        </if>
                </target>
            </project>";
                private const string _format2 = @"<?xml version='1.0' ?>
           <project name='testing' default='test'>
                <target name='test'>
                                        <fileset id='foo'>
                                                <include name='abc'/>
                                        </fileset>
                                        <if test='{0}'>
                                                <fileset id='foo'>
                                                        <include name='bar'/>
                                                </fileset>
                                        </if>
                </target>
            </project>";
                private const string _format3 = @"<?xml version='1.0' ?>
           <project name='testing' default='test'>
                <target name='test'>
                                        <if test='{0}'>
                                                <foo/>
                                        </if>
                </target>
            </project>";

                #endregion Private Static Fields

                #region Public Instance Methods
        
                [Test]
                public void Test_IfFilesetDefine1() 
                {
                        string buildxml = FormatBuildFile(_format1,"${1==1}");
                        Project project = CreateFilebasedProject(buildxml, 
Level.Info);
                        string result = ExecuteProject(project);
                        DataTypeBase foo = project.DataTypeReferences["foo"];
                        Assert.IsNotNull(foo);
                        Assert.IsTrue(foo is FileSet);
                        
                        FileSet fs = (FileSet)foo;
                        Assert.AreEqual(1,fs.Includes.Count);
                        Assert.AreEqual("bar",fs.Includes[0]);
                }

                [Test]
                public void Test_IfFilesetDefine2() 
                {
                        string buildxml = FormatBuildFile(_format1,"${1==2}");
                        Project project = CreateFilebasedProject(buildxml, 
Level.Info);
                        string result = ExecuteProject(project);
                        DataTypeBase foo = project.DataTypeReferences["foo"];
                        Assert.IsNull(foo);
                }

                [Test]
                public void Test_IfFilesetRedefine1() 
                {
                        string buildxml = FormatBuildFile(_format2,"${1==1}");
                        Project project = CreateFilebasedProject(buildxml, 
Level.Info);
                        string result = ExecuteProject(project);
                        DataTypeBase foo = project.DataTypeReferences["foo"];
                        Assert.IsNotNull(foo);
                        Assert.IsTrue(foo is FileSet);
                        
                        FileSet fs = (FileSet)foo;
                        Assert.AreEqual(1,fs.Includes.Count);
                        Assert.AreEqual("bar",fs.Includes[0]);
                }

                [Test]
                public void Test_IfFilesetRedefine2() 
                {
                        string buildxml = FormatBuildFile(_format2,"${1==2}");
                        Project project = CreateFilebasedProject(buildxml, 
Level.Info);
                        string result = ExecuteProject(project);
                        DataTypeBase foo = project.DataTypeReferences["foo"];
                        Assert.IsNotNull(foo);
                        Assert.IsTrue(foo is FileSet);
                        
                        FileSet fs = (FileSet)foo;
                        Assert.AreEqual(1,fs.Includes.Count);
                        Assert.AreEqual("abc",fs.Includes[0]);
                }

                [Test]
                public void Test_IfUnknownNode1() 
                {
                        string buildxml = FormatBuildFile(_format3,"${1==2}");
                        RunBuild(buildxml);
                }

                [Test]
                public void Test_IfUnknownNode2() 
                {
                        string buildxml = FormatBuildFile(_format3,"${1==1}");
                        TestBuildException ex=null;
                        try
                        {
                                RunBuild(buildxml);
                        }
                        catch(TestBuildException e)
                        {
                                ex=e;
                        }
                        Assert.IsNotNull(ex);
                        Assert.IsTrue(ex.InnerException is BuildException);
                        BuildException be = (BuildException)ex.InnerException;
                        Assert.AreEqual(5,be.Location.LineNumber);
                        Assert.IsTrue(be.RawMessage.IndexOf("foo")>=0);
                }                                                               
                          

                #endregion Public Instance Methods

                #region Protected Instance Methods

                [SetUp]
                protected override void SetUp() 
                {
                        base.SetUp();
                }

                #endregion Protected Instance Methods

                #region Private Instance Methods

                private string FormatBuildFile(string fmt,params object[] pars) 
                {
                        return string.Format(CultureInfo.InvariantCulture, fmt, 
pars);
                }

                #endregion Private Instance Methods
        }

}

Reply via email to