2013年2月10日日曜日

[Ant]CppUnit テスト

以下のような build.xml を準備する
<?xml version="1.0"?>
<project name="CppUnit" basedir="." default="all">
  <taskdef resource="cpptasks.tasks"/>
  <property name="build.dir" value="build"/>
  <property name="dist.dir" value="dist"/>
  <property name="src.dir" value="src"/>
  <target name="init">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${dist.dir}"/>
  </target>
  <target name="clean">
    <delete dir="${build.dir}"/>
    <mkdir dir="${build.dir}"/>
    <delete dir="${dist.dir}"/>
    <mkdir dir="${dist.dir}"/>
  </target>
  <target name="compile" depends="init">
    <cc outtype="executable"
        subsystem="console"
        outfile="${dist.dir}/test"
        objdir="${build.dir}"
        debug="true">
      <compiler name="g++">
        <fileset dir="${src.dir}" includes="*.cpp"/>
      </compiler>
      <linker name="gcc" libtool="true">
        <libset libs="cppunit,stdc++"/>
      </linker>
    </cc>
  </target>
  <target name="test" depends="compile">
    <exec executable="${dist.dir}/test.exe">
      <arg value=""/>
    </exec>
  </target>
  <target name="all" depends="init,clean,compile"/>
</project>
ant, ant test を実行すると CppUnit のテスト用に作成した test.exe が実行され結果が表示される。
>ant test
Buildfile: build.xml
init:
compile:
[cc] Starting dependency analysis for 3 files.
[cc] 3 files are up to date.
[cc] 0 files to be recompiled from dependency analysis.
[cc] 0 total files to be compiled.
[cc] Starting link
test:
[exec] This is Counter test
[exec] CounterTest::test_init : OK
[exec] CounterTest::test_incr : OK
[exec] CounterTest::test_clear : assertion
[exec] CounterTest.cpp:34:Assertion
[exec] Test name: CounterTest::test_clear
[exec] equality assertion failed
[exec] - Expected: 1
[exec] - Actual : 0
[exec]
[exec] Failures !!!
[exec] Run: 3 Failure total: 1 Failures: 1 Errors: 0
[exec] Result: 1
BUILD SUCCESSFUL
Total time: 0 seconds

0 件のコメント:

コメントを投稿