Search code examples
.netnantvstest

nant - concatenate specific file names into a single string


I am trying to get all file names passing a certain filter to get into a single variable seperated by space.

this works:

<foreach item="File" property="filename">
        <in>
            <items>
                <include name="bin\*Test.dll" />
                <include name="bin\*Tests.dll" />
            </items>
        </in>
        <do>
            <echo>Executing serverSideTests</echo>
            <tstamp />
            <exec basedir="${devenv.dir}" program="VSTest.Console.exe" commandline='"${filename}" /TestCaseFilter:"TestCategory!=Debugging|TestCategory!=Upgrade"' failonerror="true" />
            <tstamp />
        </do>
    </foreach>

I want to run this:

VSTest.Console.exe file1 file2 ...

Why i want to do the above is, in conjunction with the above I will use runsettings to parallelize different sets of the tests above.

How do I concatenate the file names into a single space delimited string?


Solution

  • figured it out myself, turns out, its pretty easy if not intuitive:

    <property name="testAssemblies" value=""></property>
    
    <target name="test">
        <call target="clientSideTests" />
        <foreach item="File" property="filename">
            <in>
                <items>
                    <include name="bin\*Test.dll" />
                    <include name="bin\*Tests.dll" />
                </items>
            </in>
            <do>
                <property name="testAssemblies" value='${testAssemblies} "${filename}"'></property>
            </do>
        </foreach>
        <echo>Executing serverSideTests for ${testAssemblies}</echo>
        <tstamp />
        <exec program="${devenv.test}\VSTest.Console.exe" commandline='${testAssemblies} /TestCaseFilter:"TestCategory!=Debugging|TestCategory!=Upgrade" /Settings:"vstest.runsettings"' failonerror="true" />
        <tstamp />