aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/etc/testcases/types/assertions.xml
blob: dee7ce7c5d925f2f0cdab816e22e882e3c2290f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project name="assertions" basedir="." default="tearDown">

  <import file="../buildfiletest-base.xml"/>

  <target name="setUp">
    <available property="jdk1.6+" classname="java.net.CookieStore"/>
    <condition property="source" value="6">
      <isset property="jdk1.6+"/>
    </condition>
    <property name="source" value="1.4"/>
    <mkdir dir="${output}"/>
    <javac srcdir="${src.dir}"
           includes="*.java"
           source="${source}"
           debug="true"
           destdir="${output}"
        />
  </target>

  <property name="src.dir" location="assertions"/>
  <property name="classname" value="AssertionMain"/>
  <property name="test.classname" value="AssertionTest"/>
  
  <path id="assert.classpath">
    <pathelement location="${output}"/>
  </path>                                   
  
  
  <!-- if per-class assertions work, this run asserts -->
  <target name="test-classname" depends="setUp">
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enablesystemassertions="true">
        <enable class="${classname}" />
      </assertions>
    </java>
  </target>
  
  <!-- if package works, this run asserts -->
  <target name="test-package" depends="setUp">
    <java fork="true"  failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enableSystemAssertions="false" >
        <enable package="..." />
      </assertions>
    </java>
  </target>

  <!-- this test should run the app successfully -->
  <target name="test-empty-assertions" depends="setUp">
    <java fork="true"  failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions/>
    </java>
  </target>  

  <!-- this test should run the app successfully -->
  <target name="test-disable" depends="setUp">
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enableSystemAssertions="false" >
        <enable package="..." />
        <disable class="${classname}" />
      </assertions>
    </java>
  </target>  

  <!-- repeated settigns result in the last declaration winning
    except that the rule 'classes win over packages takes priority
    this run will assert -->
  <target name="test-override" depends="setUp">
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enableSystemAssertions="false" >
        <enable package="..." />
        <disable class="${classname}" />
        <enable class="${classname}" />
        <disable package="..." />
      </assertions>
    </java>
  </target>  

  <!-- repeated settigns result in the last declaration winning;
    this run will not assert -->
  <target name="test-override2" depends="setUp">
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enableSystemAssertions="false" >
        <enable package="..." />
        <enable class="${classname}" />
        <disable class="${classname}" />
      </assertions>
    </java>
  </target>  
  
  <!-- if references work, this run asserts -->
  <target name="test-references">
  <assertions id="project.assertions" >
    <enable package="org.apache.test" />
    <disable package="org.apache.log4j"/>
    <enable package="..."/>
  </assertions>  
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions refid="project.assertions"/>
    </java>
  </target>
  
  <!-- when fork=false; we need to reject the construct -->
  <target name="test-nofork" depends="setUp">
    <java fork="false" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enablesystemassertions="true">
        <enable class="${classname}" />
      </assertions>
    </java>
  </target>  

  <!-- this throws a build error -->
  <target name="test-multiple-assertions" depends="setUp">
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions enablesystemassertions="true">
        <enable class="${classname}" />
      </assertions>
      <assertions/>
    </java>
  </target>  
  
  <!-- should throw a build exception -->
  <target name="test-reference-abuse" depends="setUp">
  <assertions id="project.assertions2" >
    <enable package="org.apache.test" />
    <disable package="org.apache.log4j"/>
    <enable package="..."/>
  </assertions>  
    <java fork="true" failonerror="true"
      classname="${classname}"
      classpathref="assert.classpath">
      <assertions refid="project.assertions2">
        <disable class="${classname}" />
      </assertions>      
    </java>
  </target>    
  
    
  <target name="test-junit" depends="setUp">
    <junit fork="true" 
      haltonerror="true" haltonfailure="true"
      >
      <classpath>
        <path refid="assert.classpath"/>
      </classpath>
      <formatter type="plain"     usefile="false"/>
      <assertions >
        <enable class="${test.classname}" />
      </assertions> 
      <test name="${test.classname}"/>
    </junit>
  </target>
    
  <!-- This is here to show that setting it as a property works
  so there is some defect in pass-on of assertions that
  is causing the problem -->
  <target name="test-junit-manual-setup" depends="setUp">
    <junit fork="true" 
      haltonerror="true" haltonfailure="true"
      >
      <classpath>
        <path refid="assert.classpath"/>
      </classpath>
      <formatter type="plain"     usefile="false"/>
      <test name="${test.classname}"/>
      <jvmarg value="-ea:AssertionTest"/>
    </junit>
  </target>  
  
</project>