* Code coverage with Cobertura
[scilab.git] / scilab / build.qa.incl.xml
1 <project name="common_qa">
2   <!--  Unitary testing + code coverage -->
3   
4   <property name="base.dir" location="../../"/>
5   
6   <!-- JAR names -->
7   <property file="${base.dir}/scilab-lib.properties"/>
8   <property file="${base.dir}/scilab-lib-doc.properties"/>
9   <!-- Configure ANT flags -->
10   <property file="${base.dir}/scilab.properties"/>
11   
12   <!-- Where we can find the test sources -->
13   <property name="test.dir" location="tests/"/>
14   <property name="src.test.dir" location="${test.dir}/java/"/>
15   <property name="report.test.dir" location="${base.dir}/reports/"/>
16   <property name="report.xml.test.dir" location="${report.test.dir}/xml/"/>
17   <property name="report.html.test.dir" location="${report.test.dir}/html/"/>
18   <property name="report.codecoverage.dir" location="${report.test.dir}/codecoverage/"/>
19   <property name="report.codecoverage.html.dir" location="${report.test.dir}/html-codecoverage/"/>
20   
21   <!-- Check style definitions -->
22   <property name="checkstyle.config.file" value="${base.dir}/checkstyle/scilab_checkstyle_convention.xml"/>
23   <property name="checkstyle.stylesheet" value="${thirdparty.dir}/checkstyle/contrib/checkstyle-noframes-sorted.xsl"/>
24   <property name="checkstyle.report.dir" value="${build.dir}/checkstyle"/>
25   <property name="checkstyle.xml.report.file" value="${checkstyle.report.dir}/checkstyle_errors.xml"/>
26   <property name="checkstyle.html.report.file" value="${checkstyle.report.dir}/checkstyle_errors.htm"/>
27   
28   <path id="unittest.classpath">
29     <pathelement location="${junit4.jar}"/>
30   </path>
31   <path id="cobertura_classpath">
32     <pathelement location="${cobertura.jar}"/>
33   </path>
34   
35   <!-- Clean test -->
36   <target name="clean-test" description="Clean test files">
37     <delete dir="${build.test.dir}"/>
38   </target>
39   
40   <target name="existing-tests">
41     <available property="test-present" file="${src.test.dir}"/>
42   </target>
43   
44   <!-- Compile test sources -->
45   <target name="compile-test" description="Build tests" depends="existing-tests, clean-test, jar" if="test-present">
46     <!-- clean the test to make sure it will build properly -->
47     <javac srcdir="${src.test.dir}" destdir="${classes.test.dir}" deprecation="on" debug="${build.debug}" verbose="off" listfiles="on" includeAntRuntime="no" source="6" target="6" encoding="UTF-8">
48       <classpath>
49         <path refid="unittest.classpath"/>
50         <path refid="compile.classpath"/>
51       </classpath>
52     </javac>
53   </target>
54   
55   <taskdef resource="checkstyletask.properties" classpathref="checkstyle.classpath"/>
56   <!-- Checkstyle process -->
57   <target name="checkstyle" depends="checkstyle-init" description="Generates a report of code convention violations.">
58     <checkstyle config="${checkstyle.config.file}" failOnViolation="false">
59       <fileset dir="${src.dir}" includes="**/*.java"/>
60       <!-- Location of cache-file. -->
61       <property key="checkstyle.cache.file" file="${cache.dir}"/>
62       <formatter type="plain"/>
63       <formatter type="xml" toFile="${checkstyle.xml.report.file}"/>
64     </checkstyle>
65     <xslt in="${checkstyle.xml.report.file}" out="${checkstyle.html.report.file}" style="${checkstyle.stylesheet}"/>
66   </target>
67   <!-- Create the build directory -->
68   <target name="checkstyle-init">
69     <mkdir dir="${checkstyle.report.dir}"/>
70   </target>
71   <!-- Delete the build directory -->
72   <target name="checkstyle-clean">
73     <delete dir="${checkstyle.report.dir}"/>
74   </target>
75   
76   
77   <!-- Allows the override of the forkMode by local build.xml -->
78   <condition property="forkModeAlreadySet">
79     <isset property="junit.forkMode" />
80   </condition>
81   
82   <target name="validate">
83     <!-- Empty target to be override by other build.xml -->
84   </target>
85   
86   <taskdef classpathref="cobertura_classpath" resource="tasks.properties" />
87   
88   <target name="instrument">
89     <cobertura-instrument todir="${instrumented.classes.test.dir}" datafile="${report.test.dir}/${library.name}.ser">
90       <fileset dir="${classes.dir}">
91         <include name="**/*.class" />
92       </fileset>
93     </cobertura-instrument>
94   </target>
95   
96   <target name="codecoverage" depends="compile-test, instrument, test">
97     <cobertura-merge>
98       <fileset dir="${report.test.dir}">
99         <include name="*.ser" />
100       </fileset>
101     </cobertura-merge>
102     
103     <cobertura-report format="html" destdir="${report.codecoverage.html.dir}"> 
104       
105       <fileset dir="${library.action_binding.src.dir}">
106         <include name="**/*.java" />
107       </fileset>
108       <fileset dir="${library.commons.src.dir}">
109         <include name="**/*.java" />
110       </fileset>
111       <fileset dir="${library.graph.src.dir}">
112         <include name="**/*.java" />
113       </fileset>
114       <fileset dir="${library.hdf5.src.dir}">
115         <include name="**/*.java" />
116       </fileset>
117       <fileset dir="${library.xcos.src.dir}">
118         <include name="**/*.java" />
119       </fileset>
120       <fileset dir="${library.types.src.dir}">
121         <include name="**/*.java" />
122       </fileset>
123       <fileset dir="${library.javasci.src.dir}">
124         <include name="**/*.java" />
125       </fileset>
126     </cobertura-report>
127     
128   </target>
129   
130   
131   <target name="detectForkMode" unless="forkModeAlreadySet">
132     <property name="junit.forkMode" value="perBatch"/>
133   </target>
134   
135   <target name="test" depends="existing-tests, compile-test, validate, detectForkMode" if="test-present">
136     <mkdir dir="${report.xml.test.dir}" />
137     <mkdir dir="${report.html.test.dir}" />
138     <mkdir dir="${report.codecoverage.dir}/" />
139     <junit fork="yes" forkmode="${junit.forkMode}" failureproperty="junit.failure">
140       <sysproperty key="net.sourceforge.cobertura.datafile"
141                  file="${report.test.dir}/${library.name}.ser" />
142       
143       
144       <classpath location="${instrumented.classes.test.dir}"/>
145       <classpath location="${classes.test.dir}"/>
146       
147       <classpath>
148         <path refid="unittest.classpath"/>
149         <path refid="compile.classpath"/>
150         <pathelement location="${cobertura.jar}"/>
151         <pathelement location="${classes.test.dir}"/>
152         <pathelement location="${classes.dir}"/>
153       </classpath>
154       
155       
156       <!-- Where ${basedir} is the module base directory -->
157       <env key="SCI" value="${basedir}/../.."/>
158       <jvmarg value="-DtestngTests=1"/>
159       <jvmarg value="-Djava.library.path=${base.dir}/modules/.libs/:${base.dir}/modules/javasci/.libs/:${base.dir}/modules/types/.libs/:${base.dir}/modules/localization/.libs/:${base.dir}/modules/commons/.libs/:${base.dir}/modules/action_binding/.libs/:${base.dir}/thirdparty/:${base.dir}/bin/:/usr/lib/jni/:/usr/lib64/jni:/usr/lib/java/:/usr/lib64/java:"/>
160       
161       <formatter type="brief" useFile="no" />
162       <formatter type="xml" />
163       
164       <batchtest fork="yes" todir="${report.xml.test.dir}" >
165         <fileset dir="tests/java/">
166           <include name="**/*.java"/>
167         </fileset>
168       </batchtest>
169     </junit>
170     
171     <junitreport todir="${report.xml.test.dir}">
172       <fileset dir="${report.xml.test.dir}">
173         <include name="*.xml"/>
174       </fileset>
175       <report format="frames" todir="${report.html.test.dir}"/>
176     </junitreport>
177     
178     <fail if="junit.failure" message="Unit test(s) failed. See the report"/>
179   </target>
180 </project>