(file) Return to tests.oml CVS log (file) (dir) Up to [pingdynasty] / o-lib / tests

File: [pingdynasty] / o-lib / tests / tests.oml (download)
Revision: 1.4, Mon Oct 25 18:36:27 2004 UTC (5 years, 10 months ago) by mars
Branch: MAIN
CVS Tags: version-1-1-7, version-1-1-6, version-1-1-5, version-1-1-4, version-1-1-3, version-1-1-2, version-1-1-1, version-1-1-0, HEAD
Changes since 1.3: +1 -1 lines
tidied up templates

<o:do xmlns:o="http://www.o-xml.org/lang/">

  <o:type name="Test">
    <o:variable name="name"/> <!-- name of test -->
    <o:variable name="input"/> <!-- test input vector -->
    <o:variable name="result"/> <!-- expected test result -->

    <o:variable name="type"/> <!-- information about the test -->
    <o:variable name="function"/>
    <o:variable name="procedure"/>

    <o:function name="Test">
      <o:param name="name"/>
      <o:param name="input"/>
      <o:param name="result"/>
      <o:do/>
    </o:function>

    <o:function name="name">
      <o:do>
        <o:return select="$name"/>
      </o:do>
    </o:function>

    <o:function name="function">
      <o:param name="function" type="String"/>
      <o:do/>
    </o:function>

    <o:function name="type">
      <o:param name="type" type="String"/>
      <o:do/>
    </o:function>

    <o:function name="procedure">
      <o:param name="procedure" type="String"/>
      <o:do/>
    </o:function>

    <o:function name="details">
    <!-- returns some contextual test information details 
         (name, which function/type/procedure it was defined in etc) -->
      <o:do>
        <name><o:eval select="$name"/></name>
        <o:if test="$function">
          <function><o:eval select="$function"/></function>
        </o:if>
        <o:if test="$type">
          <type><o:eval select="$type"/></type>
        </o:if>
        <o:if test="$procedure">
          <procedure><o:eval select="$procedure"/></procedure>
        </o:if>
      </o:do>
    </o:function>

    <o:function name="input">
      <o:do>
        <o:return select="$input"/>
      </o:do>
    </o:function>

    <o:function name="result">
      <o:do>
        <o:return select="$result"/>
      </o:do>
    </o:function>

      <!-- run this test by calling the test template function with our input -->
      <!-- and comparing the return value with the expected result -->
      <!-- tbd - template methods not functional... -->
    <o:function name="run">
      <o:do>
	<o:log msg="run: {$this.type()}"/>
        <o:set ret="$this.test($input)"/>
        <o:if test="$result and not($ret = $result)">
          <o:throw select="TestError($ret, $result)"/>
        </o:if>
      </o:do>
    </o:function>
  </o:type>

  <o:type name="TestError">
    <o:parent name="Exception"/>

    <o:variable name="actual"/>
    <o:variable name="expected"/>

    <o:function name="TestError">
      <o:param name="actual"/>
      <o:param name="expected"/>
      <o:do/>
    </o:function>

    <o:function name="actual">
      <o:do>
        <o:return select="$actual"/>
      </o:do>
    </o:function>

    <o:function name="expected">
      <o:do>
        <o:return select="$expected"/>
      </o:do>
    </o:function>

  </o:type>
  
  <o:type name="TestHandler">
    <o:variable name="test"/>
    <o:variable name="report"/>

    <o:function name="TestHandler">
      <o:param name="test" type="Test"/>
      <o:param name="report"/>
      <o:do/>
    </o:function>

    <o:function name="handle">
      <o:param name="exc" type="Exception"/>
      <o:do>
        <o:log level="warning" msg="test failed: {$test.name()}"/>
        <o:log level="debug" msg="exception: {$exc.message()}"/>
        <o:variable name="error">
          <error>
            <exception><o:eval select="$exc.message()"/></exception>
          </error>
        </o:variable>
        <o:do select="$report.append($error)"/>
      </o:do>
    </o:function>

    <o:function name="handle">
      <o:param name="exc" type="SystemError"/>
      <o:do>
        <o:log level="warning" msg="test failed: {$test.name()}"/>
        <o:log level="debug" msg="system error: {$exc.message()}"/>
        <o:variable name="error">
          <error>
            <exception><o:eval select="$exc.message()"/></exception>
          </error>
        </o:variable>
        <o:do select="$report.append($error)"/>
      </o:do>
    </o:function>

    <o:function name="handle">
      <o:param name="exc" type="AssertionError"/>
      <o:do>
        <o:log level="warning" msg="test failed: {$test.name()}"/>
        <o:log level="debug" msg="assertion: {$exc.message()}"/>
        <o:log level="debug" msg="expression: {$exc.expression()}"/>
        <o:variable name="error">
          <error>
            <assertion>
              <message><o:eval select="$exc.message()"/></message>
              <expression><o:eval select="$exc.expression()"/></expression>
            </assertion>
          </error>
        </o:variable>
        <o:do select="$report.append($error)"/>
      </o:do>
    </o:function>

    <o:function name="handle">
      <o:param name="exc" type="TestError"/>
      <o:do>
        <o:log level="warning" msg="test failed: {$test.name()}"/>
	<o:log level="warning" msg="expected: {$exc.expected()}"/>
	<o:log level="debug" msg="got: {$exc.actual()}"/>
        <o:variable name="error">
          <error xmlns:java="http://www.o-xml.com/java/">
            <return><o:eval select="java:serialize($exc.actual())"/></return>
            <expected><o:eval select="java:serialize($exc.expected())"/></expected>
          </error>
        </o:variable>
        <o:do select="$report.append($error)"/>
      </o:do>
    </o:function>
  </o:type>
  
  <o:type name="TestSuite">

    <o:variable name="results" type="List" select="List()"/>

    <o:function name="test">
      <!-- run a single test -->
      <o:param name="test" type="Test"/>
      <o:do>
        <o:set report="Element('test')"/>
        <o:do select="$report.append($test.details())"/>

        <o:catch handler="TestHandler($test, $report)">
          <o:eval select="$test.run()"/>
          <o:do select="$report.append(Element('passed'))"/>
        </o:catch>

        <o:do select="$results.add($report)"/>
        <!-- tbd add execution time -->
        <!-- tbd repeat if wanted -->
      </o:do>
    </o:function>

    <o:function name="report">
      <o:do>
        <o:return select="$results.nodes()"/>
      </o:do>
    </o:function>

  </o:type>

</o:do>

Email CVS Admin
Powered by
ViewCVS 0.9.3