开发者

Nant xmlpeek issue

开发者 https://www.devze.com 2023-03-14 01:36 出处:网络
I\'m currently trying to parse a coverage file from PartCover using a nant task. The problem is that the structure requires a bit of counting. To do this i\'m looking at the example posted at http://w

I'm currently trying to parse a coverage file from PartCover using a nant task. The problem is that the structure requires a bit of counting. To do this i'm looking at the example posted at http://www.russellallen.info/post/Automating-Test-Coverage-with-PartCover-NUnit-and-Nant.aspx , step 4 to be exact.

I've written my script like this :

<!-- Generate the report and put it on TeamCity -->
  <target name="PartCoverReport">
    <!-- Read out the amount of lines covered and divide it by the number of hits, more than 90 is passed. -->
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method/pt/@len)" property="Test.NumLines1" failonerror="false"/>
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method[count(pt)=0]/@bodysize)" property="Test.NumLines2" failonerror="false"/>
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method/pt[@visit>0]/@len)" property="Test.LinesCovered" failonerror="false"/>
    <property name="Test.ActualCoverage" value="${double::parse(Test.LinesCovered) / (double::parse(Test.NumLines1) + double::parse(Test.NumLines2)}" />
    <fail if="${double::parse(Test.ActualCoverage) &lt; double::parse(Test.MinimumCoverage)}" message="The solution currently has ${double::parse(Test.ActualCoverage) * 100}% coverage, less than the required 90%" />

    <!-- Check if we need to include the querycount -->
    <if test="${Tes开发者_JS百科ts.CountQueries == 'yes'}">
      <readregistry property="TotalQueryCount" key="Software\Tenforce\TestStatistics\TotalQueryCount" hive="LocalMachine" />
      <echo message="##teamcity[buildStatisticValue key='totalQueryCount' value='${TotalQueryCount}']" />
      <readregistry property="AverageQueryCountPerTestRounded" key="Software\Tenforce\TestStatistics\AverageQueryCountPerTestRounded" hive="LocalMachine" />
      <echo message="##teamcity[buildStatisticValue key='averageQueryCountPerTest' value='${math::round(AverageQueryCountPerTestRounded)}']" />
      <readregistry property="AverageQueryCountPerTest" key="Software\Tenforce\TestStatistics\AverageQueryCountPerTest" hive="LocalMachine" />
      <echo message="##teamcity[buildStatus text='{build.status.text}, coverage: ${CoveragePercent}%, queries: ${TotalQueryCount}-${AverageQueryCountPerTest}']" />
    </if>

    <!-- If no query count is needed, then just display the output -->
    <if test="${Tests.CountQueries != 'yes'}">
      <echo message="##teamcity[buildStatus text='{build.status.text}, coverage: ${Test.ActualCoverage}%']" />
    </if>
  </target>

However when i'm looking at the teamcity output, it says that the Xpath is invalid:

[10:46:55]: NAnt output:
[10:46:55]: [exec] Target WorkingSetSize: 115511296
[10:46:55]: [exec] Total 0 bytes
[10:46:55]: PartCoverReport:
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method/pt/@len)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(371,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method/pt/@len)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method[count(pt)=0]/@bodysize)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(372,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method[count(pt)=0]/@bodysize)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method/pt[@visit>0]/@len)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(373,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method/pt[@visit>0]/@len)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: BUILD FAILED - 3 non-fatal error(s), 24 warning(s)

Is it possible what I'm trying to do with the xml-peek operations?


I haven't had a look at the script yet but first of all make sure you have at least NAnt version 0.91-alpha1 (May 29, 2010) installed. Release notes state, they have improvements for count() with xmlpeek in this version.


I've written my own C# plugin for Nant that allows me to use any kind of Xpath in an expression now.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号