forked from jasder/antlr
Merge pull request #1636 from bhamiltoncx/stream-vacuum-utf8
Consolidate multiple copies of StreamVacuum, make use UTF-8
This commit is contained in:
commit
3e61421e59
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
||||||
|
* Use of this file is governed by the BSD 3-clause license that
|
||||||
|
* can be found in the LICENSE.txt file in the project root.
|
||||||
|
*/
|
||||||
|
package org.antlr.v4.test.runtime;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public final class StreamVacuum implements Runnable {
|
||||||
|
private StringBuilder buf = new StringBuilder();
|
||||||
|
private BufferedReader in;
|
||||||
|
private Thread sucker;
|
||||||
|
public StreamVacuum(InputStream in) {
|
||||||
|
this.in = new BufferedReader( new InputStreamReader(in, StandardCharsets.UTF_8) );
|
||||||
|
}
|
||||||
|
public void start() {
|
||||||
|
sucker = new Thread(this);
|
||||||
|
sucker.start();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String line = in.readLine();
|
||||||
|
while (line!=null) {
|
||||||
|
buf.append(line);
|
||||||
|
buf.append('\n');
|
||||||
|
line = in.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ioe) {
|
||||||
|
System.err.println("can't read output from process");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** wait for the thread to finish */
|
||||||
|
public void join() throws InterruptedException {
|
||||||
|
sucker.join();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
import org.antlr.v4.semantics.SemanticPipeline;
|
import org.antlr.v4.semantics.SemanticPipeline;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.DOTGenerator;
|
import org.antlr.v4.tool.DOTGenerator;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
@ -46,11 +47,7 @@ import org.stringtemplate.v4.ST;
|
||||||
import org.stringtemplate.v4.STGroup;
|
import org.stringtemplate.v4.STGroup;
|
||||||
import org.stringtemplate.v4.STGroupString;
|
import org.stringtemplate.v4.STGroupString;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
@ -750,41 +747,6 @@ public class BaseCppTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader( new InputStreamReader(in) );
|
|
||||||
}
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line!=null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage)
|
GrammarSemanticsMessage expectedMessage)
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.antlr.v4.runtime.WritableToken;
|
||||||
import org.antlr.v4.runtime.misc.Utils;
|
import org.antlr.v4.runtime.misc.Utils;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||||
import org.junit.rules.TestRule;
|
import org.junit.rules.TestRule;
|
||||||
|
@ -31,7 +32,6 @@ import javax.xml.transform.stream.StreamResult;
|
||||||
import javax.xml.xpath.XPathConstants;
|
import javax.xml.xpath.XPathConstants;
|
||||||
import javax.xml.xpath.XPathExpression;
|
import javax.xml.xpath.XPathExpression;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -535,41 +535,6 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader( new InputStreamReader(in) );
|
|
||||||
}
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line!=null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage)
|
GrammarSemanticsMessage expectedMessage)
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.antlr.v4.runtime.misc.Interval;
|
||||||
import org.antlr.v4.semantics.SemanticPipeline;
|
import org.antlr.v4.semantics.SemanticPipeline;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.DOTGenerator;
|
import org.antlr.v4.tool.DOTGenerator;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
@ -43,8 +44,6 @@ import org.stringtemplate.v4.ST;
|
||||||
import org.stringtemplate.v4.STGroup;
|
import org.stringtemplate.v4.STGroup;
|
||||||
import org.stringtemplate.v4.STGroupString;
|
import org.stringtemplate.v4.STGroupString;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -52,7 +51,6 @@ import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -572,45 +570,6 @@ public class BaseGoTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader(new InputStreamReader(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line != null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage) throws Exception {
|
GrammarSemanticsMessage expectedMessage) throws Exception {
|
||||||
ANTLRMessage foundMsg = null;
|
ANTLRMessage foundMsg = null;
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.antlr.v4.semantics.SemanticPipeline;
|
||||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||||
|
@ -53,7 +54,6 @@ import javax.tools.JavaCompiler;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
import javax.tools.StandardJavaFileManager;
|
import javax.tools.StandardJavaFileManager;
|
||||||
import javax.tools.ToolProvider;
|
import javax.tools.ToolProvider;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -703,6 +703,7 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
||||||
try {
|
try {
|
||||||
String[] args = new String[] {
|
String[] args = new String[] {
|
||||||
"java", "-classpath", tmpdir+pathSep+CLASSPATH,
|
"java", "-classpath", tmpdir+pathSep+CLASSPATH,
|
||||||
|
"-Dfile.encoding=UTF-8",
|
||||||
className, new File(tmpdir, "input").getAbsolutePath()
|
className, new File(tmpdir, "input").getAbsolutePath()
|
||||||
};
|
};
|
||||||
// String cmdLine = Utils.join(args, " ");
|
// String cmdLine = Utils.join(args, " ");
|
||||||
|
@ -824,41 +825,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader( new InputStreamReader(in) );
|
|
||||||
}
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line!=null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage)
|
GrammarSemanticsMessage expectedMessage)
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -53,13 +53,8 @@ import org.stringtemplate.v4.ST;
|
||||||
import org.stringtemplate.v4.STGroup;
|
import org.stringtemplate.v4.STGroup;
|
||||||
import org.stringtemplate.v4.STGroupString;
|
import org.stringtemplate.v4.STGroupString;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -529,41 +524,6 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader( new InputStreamReader(in) );
|
|
||||||
}
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line!=null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage)
|
GrammarSemanticsMessage expectedMessage)
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.antlr.v4.runtime.misc.Interval;
|
||||||
import org.antlr.v4.semantics.SemanticPipeline;
|
import org.antlr.v4.semantics.SemanticPipeline;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.DOTGenerator;
|
import org.antlr.v4.tool.DOTGenerator;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
@ -43,15 +44,8 @@ import org.stringtemplate.v4.ST;
|
||||||
import org.stringtemplate.v4.STGroup;
|
import org.stringtemplate.v4.STGroup;
|
||||||
import org.stringtemplate.v4.STGroupString;
|
import org.stringtemplate.v4.STGroupString;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -525,45 +519,6 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader(new InputStreamReader(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line != null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage) throws Exception {
|
GrammarSemanticsMessage expectedMessage) throws Exception {
|
||||||
ANTLRMessage foundMsg = null;
|
ANTLRMessage foundMsg = null;
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
import org.antlr.v4.semantics.SemanticPipeline;
|
import org.antlr.v4.semantics.SemanticPipeline;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.DOTGenerator;
|
import org.antlr.v4.tool.DOTGenerator;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
@ -49,13 +50,7 @@ import org.stringtemplate.v4.ST;
|
||||||
import org.stringtemplate.v4.STGroup;
|
import org.stringtemplate.v4.STGroup;
|
||||||
import org.stringtemplate.v4.STGroupString;
|
import org.stringtemplate.v4.STGroupString;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -494,6 +489,7 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
||||||
try {
|
try {
|
||||||
ProcessBuilder builder = new ProcessBuilder( pythonPath, modulePath, inputPath );
|
ProcessBuilder builder = new ProcessBuilder( pythonPath, modulePath, inputPath );
|
||||||
builder.environment().put("PYTHONPATH",runtimePath);
|
builder.environment().put("PYTHONPATH",runtimePath);
|
||||||
|
builder.environment().put("PYTHONIOENCODING", "utf-8");
|
||||||
builder.directory(new File(tmpdir));
|
builder.directory(new File(tmpdir));
|
||||||
Process process = builder.start();
|
Process process = builder.start();
|
||||||
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
|
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
|
||||||
|
@ -652,41 +648,6 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader( new InputStreamReader(in) );
|
|
||||||
}
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line!=null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** wait for the thread to finish */
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||||
GrammarSemanticsMessage expectedMessage)
|
GrammarSemanticsMessage expectedMessage)
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
|
@ -9,15 +9,11 @@ package org.antlr.v4.test.runtime.swift;
|
||||||
import org.antlr.v4.Tool;
|
import org.antlr.v4.Tool;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||||
|
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||||
import org.stringtemplate.v4.ST;
|
import org.stringtemplate.v4.ST;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -119,49 +115,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
||||||
return runProcess(argsString, ANTLR_FRAMEWORK_DIR);
|
return runProcess(argsString, ANTLR_FRAMEWORK_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StreamVacuum implements Runnable {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
BufferedReader in;
|
|
||||||
Thread sucker;
|
|
||||||
|
|
||||||
public StreamVacuum(InputStream in) {
|
|
||||||
this.in = new BufferedReader(new InputStreamReader(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
sucker = new Thread(this);
|
|
||||||
sucker.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String line = in.readLine();
|
|
||||||
while (line != null) {
|
|
||||||
buf.append(line);
|
|
||||||
buf.append('\n');
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
System.err.println("can't read output from process");
|
|
||||||
ioe.printStackTrace(System.err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wait for the thread to finish
|
|
||||||
*/
|
|
||||||
public void join() throws InterruptedException {
|
|
||||||
sucker.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String tmpdir = null;
|
public String tmpdir = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue