01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.fixtures;
04:
05: import java.io.ByteArrayOutputStream;
06: import java.io.PrintStream;
07: import java.net.UnknownHostException;
08: import java.util.LinkedList;
09: import java.util.List;
10:
11: import fit.ColumnFixture;
12: import fitnesse.runner.TestRunner;
13: import fitnesse.wikitext.Utils;
14:
15: public class TestRunnerFixture extends ColumnFixture {
16: public String pageName;
17: public String args;
18: private TestRunner runner;
19: private ByteArrayOutputStream outputBytes;
20:
21: public void execute() throws Exception {
22: outputBytes = new ByteArrayOutputStream();
23: runner = new TestRunner(new PrintStream(outputBytes));
24: runner.run(buildArgs());
25: }
26:
27: private String[] buildArgs() {
28: List<String> list = new LinkedList<String>();
29: if (args != null && !args.equals("")) {
30: String[] startingArg = args.split(" ");
31: for (int i = 0; i < startingArg.length; i++)
32: list.add(startingArg[i]);
33: }
34: String hostName;
35: try {
36: hostName = java.net.InetAddress.getLocalHost()
37: .getHostName();
38: } catch (UnknownHostException e) {
39: hostName = "localhost";
40: }
41: list.add(hostName);
42: list.add(String.valueOf(FitnesseFixtureContext.context.port));
43: list.add(pageName);
44:
45: return (String[]) list.toArray(new String[] {});
46: }
47:
48: public int exitCode() {
49: return runner.exitCode();
50: }
51:
52: public String output() {
53: String output = outputBytes.toString();
54: output = output.replaceAll("\r", "");
55: output = output.replaceAll("\n", "\\\\n");
56: output = Utils.escapeText(output);
57:
58: return output;
59: }
60: }
|