You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Mikael Petterson (KI/EAB)" <mi...@ericsson.com> on 2005/11/21 17:45:37 UTC

trying to grep in file for a certain string

Hi,

I am trying to check if a file called TestSummary.txt does NOT contains the string "Number of failures = 0".
If it does not contain "Number of failures = 0" then I need to set a property called test.status.failed.
When I try to test the ant script below I get:

 <fileset> type doesn't support the nested "condition" element.

What am I doing wrong?

cheers,

//mikael

<?xml version="1.0" encoding="UTF-8"?>
<project name="changeme" default="all" basedir=".">

    <target name="regression_status">
      
       <property name="msg" value="Number of failures = 0"/>
       <property name="reg.test.file" value="TestSummary.txt"/>
       <echo message="Checking File ${reg.test.file}"/>
       <echo message="For string ${msg}"/>
       <!-- Set reg test failed -->
        <fileset file="${res_file}" includes="*.txt">
       <condition property="test.status.failed">
        <not>
        <contains text="${msg}" casesensitive="no"/> 
       </not>
       </condition>
       </fileset>
      
       <fail if="test.status.failed" message="Regression tests failed!"/>


    </target>
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: trying to grep in file for a certain string

Posted by Dominique Devienne <dd...@gmail.com>.
> I am trying to check if a file called TestSummary.txt does NOT contains the string "Number of failures = 0".
> If it does not contain "Number of failures = 0" then I need to set a property called test.status.failed.
> When I try to test the ant script below I get:

<fileset> indeed doesn't support nested conditions, but selectors instead.

Use <loadfile> to put the file (or part of it as I do below) into a
property, and then simply test it with an <equals> condition to set
another property in a <condition>.

        <loadfile property="@{property}" failonerror="false" srcfile="@{file}">
          <filterchain>
            <!-- Consider only the last 10 lines of the file, -->
            <tailfilter />
            <!-- looking for a integer then a user-defined pattern, -->
            <linecontainsregexp>
              <regexp pattern="^\d+ @{pattern}" />
            </linecontainsregexp>
            <!-- and keep only the integer from these (unique) lines, -->
            <tokenfilter>
              <replaceregex pattern="(\d+) @{pattern}.*" replace="\1" />
            </tokenfilter>
            <!-- concatenating these lines (should be only one). -->
            <striplinebreaks/>
          </filterchain>
        </loadfile>
        <property name="@{property}" value="@{default}" />

PS: This code was part of a macrodef. Ignore the @{foo} syntax.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: trying to grep in file for a certain string

Posted by Ninju Bohra <ni...@yahoo.com>.
Not quite sure what is wrong with your path... but if you are only setting the
property to contol the <fail> task you can nest a condition with the <fail>
task and avoid the property.

Building on the <loadfile> task to read the file you can do the following:

<loadfile property="test.results" srcFile="${reg.test.file}"/>
<fail message="Regression tests failed!">
   <contains string="${test.results}" substring="${msg}"/>
</fail>

Short and sweet,

Ninju
--- "Mikael Petterson (KI/EAB)" <mi...@ericsson.com> wrote:

> Hi,
> 
> I am trying to check if a file called TestSummary.txt does NOT contains the
> string "Number of failures = 0".
> If it does not contain "Number of failures = 0" then I need to set a property
> called test.status.failed.
> When I try to test the ant script below I get:
> 
>  <fileset> type doesn't support the nested "condition" element.
> 
> What am I doing wrong?
> 
> cheers,
> 
> //mikael
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="changeme" default="all" basedir=".">
> 
>     <target name="regression_status">
>       
>        <property name="msg" value="Number of failures = 0"/>
>        <property name="reg.test.file" value="TestSummary.txt"/>
>        <echo message="Checking File ${reg.test.file}"/>
>        <echo message="For string ${msg}"/>
>        <!-- Set reg test failed -->
>         <fileset file="${res_file}" includes="*.txt">
>        <condition property="test.status.failed">
>         <not>
>         <contains text="${msg}" casesensitive="no"/> 
>        </not>
>        </condition>
>        </fileset>
>       
>        <fail if="test.status.failed" message="Regression tests failed!"/>
> 
> 
>     </target>
> </project>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 






		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org