001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.ruby.platform.execution;
042:
043: import java.io.ByteArrayOutputStream;
044: import java.io.IOException;
045: import java.io.PrintWriter;
046: import java.io.Writer;
047: import java.util.ArrayList;
048: import java.util.Collections;
049: import java.util.List;
050: import junit.framework.TestCase;
051: import org.netbeans.modules.ruby.platform.execution.OutputRecognizer.RecognizedOutput;
052: import org.openide.windows.OutputListener;
053: import org.openide.windows.OutputWriter;
054: import static org.netbeans.modules.ruby.platform.execution.OutputForwarder.RANGE_ERROR_RE;
055:
056: public class OutputForwarderTest extends TestCase {
057:
058: public OutputForwarderTest(String testName) {
059: super (testName);
060: }
061:
062: public void testRangeErrorRegExp() throws Exception {
063: assertFalse(RANGE_ERROR_RE.matcher("whatever").matches());
064: assertFalse(RANGE_ERROR_RE.matcher(
065: "#<RangeError: 0x is recycled object>").matches());
066: assertTrue(RANGE_ERROR_RE.matcher(
067: "#<RangeError: 0xdb4a90ec is recycled object>")
068: .matches());
069: assertTrue(RANGE_ERROR_RE.matcher(
070: "#<RangeError: 0x15a64524196c is recycled object>")
071: .matches());
072: assertTrue(RANGE_ERROR_RE.matcher(
073: "#<RangeError: 0x1 is recycled object>").matches());
074: }
075:
076: public void testRSpec4AnsiColors() throws Exception {
077: TestOutputRecognizer tor = new TestOutputRecognizer();
078: TestOutputWriter writer = new TestOutputWriter(new PrintWriter(
079: new ByteArrayOutputStream()));
080: OutputForwarder forwarder = new OutputForwarder(null, writer,
081: null,
082: Collections.<OutputRecognizer> singletonList(tor), null);
083:
084: forwarder
085: .processLine("\033[1;35m2 examples, 0 failures, 5 not implemented\033[0m");
086: forwarder.processLine("\033[32m1 example, 1 failure\033[0m\r");
087: assertEquals("two lines", 2, tor.lines.size());
088: assertEquals("2 examples, 0 failures, 5 not implemented",
089: tor.lines.get(0));
090: assertEquals("1 example, 1 failure\r", tor.lines.get(1));
091: }
092:
093: private static class TestOutputRecognizer extends OutputRecognizer {
094:
095: List<String> lines = new ArrayList<String>();
096:
097: public @Override
098: RecognizedOutput processLine(String line) {
099: lines.add(line);
100: return null;
101: }
102:
103: }
104:
105: private static class TestOutputWriter extends OutputWriter {
106:
107: TestOutputWriter(Writer w) {
108: super (w);
109: }
110:
111: public @Override
112: void println(String s, OutputListener l) throws IOException {
113: throw new UnsupportedOperationException(
114: "Not supported yet.");
115: }
116:
117: public @Override
118: void reset() throws IOException {
119: throw new UnsupportedOperationException(
120: "Not supported yet.");
121: }
122:
123: }
124:
125: }
|