1 | /*
|
---|
2 | * Copyright 2005 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant;
|
---|
19 |
|
---|
20 | import java.util.Vector;
|
---|
21 |
|
---|
22 | import org.apache.tools.ant.taskdefs.Exit;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Executor tests
|
---|
26 | */
|
---|
27 | public class ExecutorTest extends BuildFileTest implements BuildListener {
|
---|
28 | private static final String SINGLE_CHECK
|
---|
29 | = "org.apache.tools.ant.helper.SingleCheckExecutor";
|
---|
30 | private static final Vector targetNames;
|
---|
31 | static {
|
---|
32 | targetNames = new Vector();
|
---|
33 | targetNames.add("a");
|
---|
34 | targetNames.add("b");
|
---|
35 | }
|
---|
36 |
|
---|
37 | private int targetCount;
|
---|
38 |
|
---|
39 | /* BuildListener stuff */
|
---|
40 | public void targetStarted(BuildEvent event) {
|
---|
41 | targetCount++;
|
---|
42 | }
|
---|
43 | public void buildStarted(BuildEvent event) {}
|
---|
44 | public void buildFinished(BuildEvent event) {}
|
---|
45 | public void targetFinished(BuildEvent event) {}
|
---|
46 | public void taskStarted(BuildEvent event) {}
|
---|
47 | public void taskFinished(BuildEvent event) {}
|
---|
48 | public void messageLogged(BuildEvent event) {}
|
---|
49 |
|
---|
50 | public ExecutorTest(String name) {
|
---|
51 | super(name);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void setUp() {
|
---|
55 | configureProject("src/etc/testcases/core/executor.xml");
|
---|
56 | targetCount = 0;
|
---|
57 | getProject().addBuildListener(this);
|
---|
58 | }
|
---|
59 |
|
---|
60 | private Project getProject(String e) {
|
---|
61 | return getProject(e, false);
|
---|
62 | }
|
---|
63 |
|
---|
64 | private Project getProject(String e, boolean f) {
|
---|
65 | return getProject(e, f, false);
|
---|
66 | }
|
---|
67 |
|
---|
68 | private Project getProject(String e, boolean f, boolean k) {
|
---|
69 | Project p = getProject();
|
---|
70 | p.setNewProperty("ant.executor.class", e);
|
---|
71 | p.setKeepGoingMode(k);
|
---|
72 | if (f) {
|
---|
73 | p.setNewProperty("failfoo", "foo");
|
---|
74 | }
|
---|
75 | return p;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public void testDefaultExecutor() {
|
---|
79 | getProject().executeTargets(targetNames);
|
---|
80 | assertEquals(targetCount, 4);
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void testSingleCheckExecutor() {
|
---|
84 | getProject(SINGLE_CHECK).executeTargets(targetNames);
|
---|
85 | assertEquals(targetCount, 3);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void testDefaultFailure() {
|
---|
89 | try {
|
---|
90 | getProject(null, true).executeTargets(targetNames);
|
---|
91 | fail("should fail");
|
---|
92 | } catch (BuildException e) {
|
---|
93 | assertTrue(e.getMessage().equals("failfoo"));
|
---|
94 | assertEquals(targetCount, 1);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | public void testSingleCheckFailure() {
|
---|
99 | try {
|
---|
100 | getProject(SINGLE_CHECK, true).executeTargets(targetNames);
|
---|
101 | fail("should fail");
|
---|
102 | } catch (BuildException e) {
|
---|
103 | assertTrue(e.getMessage().equals("failfoo"));
|
---|
104 | assertEquals(targetCount, 1);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void testKeepGoingDefault() {
|
---|
109 | try {
|
---|
110 | getProject(null, true, true).executeTargets(targetNames);
|
---|
111 | fail("should fail");
|
---|
112 | } catch (BuildException e) {
|
---|
113 | assertTrue(e.getMessage().equals("failfoo"));
|
---|
114 | assertEquals(targetCount, 2);
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | public void testKeepGoingSingleCheck() {
|
---|
119 | try {
|
---|
120 | getProject(SINGLE_CHECK, true, true).executeTargets(targetNames);
|
---|
121 | fail("should fail");
|
---|
122 | } catch (BuildException e) {
|
---|
123 | assertTrue(e.getMessage().equals("failfoo"));
|
---|
124 | assertEquals(targetCount, 1);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | }
|
---|
129 |
|
---|