public String test(RuntimeTestDescriptor descriptor, RuntimeRunner runner, String targetName) {
		FileUtils.mkdir(runner.getTempDirPath());

		String grammarName = descriptor.grammarName;
		String grammar = descriptor.grammar;

		String lexerName, parserName;
		boolean useListenerOrVisitor;
		String superClass;
		if (descriptor.testType == GrammarType.Parser || descriptor.testType == GrammarType.CompositeParser) {
			lexerName = grammarName + "Lexer";
			parserName = grammarName + "Parser";
			useListenerOrVisitor = true;
			if ( targetName!=null && targetName.equals("Java") ) {
				superClass = JavaRunner.runtimeTestParserName;
			}
			else {
				superClass = null;
			}
		}
		else {
			lexerName = grammarName;
			parserName = null;
			useListenerOrVisitor = false;
			if (targetName.equals("Java")) {
				superClass = JavaRunner.runtimeTestLexerName;
			}
			else {
				superClass = null;
			}
		}

		RunOptions runOptions = new RunOptions(grammarName + ".g4",
				grammar,
				parserName,
				lexerName,
				useListenerOrVisitor,
				useListenerOrVisitor,
				descriptor.startRule,
				descriptor.input,
				false,
				descriptor.showDiagnosticErrors,
				descriptor.traceATN,
				descriptor.showDFA,
				Stage.Execute,
				targetName,
				superClass,
				PredictionMode.LL,
				true
		);

		State result = runner.run(runOptions);

		ExecutedState executedState;
		if (result instanceof ExecutedState) {
			executedState = (ExecutedState)result;
			if (executedState.exception != null) {
				return result.getErrorMessage();
			}
			return executedState.output;
		}
		else {
			return result.getErrorMessage();
		}
	}
Run a lexer/parser and dump ATN debug/trace information

 java org.antlr.v4.test.runtime.TraceATN [X.g4|XParser.g4 XLexer.g4] startRuleName -target [Java|Cpp|...] inputFileName


In preparation, run this so we get right jars before trying this script:

cd ANTLR-ROOT-DIR
mvn install -DskipTests=true
cd runtime-tests
mvn install jar:test-jar -DskipTests=true

Run shell script with

scripts/traceatn.sh /tmp/JSON.g4 json /tmp/foo.json

Here is scripts/traceatn.sh:

export ANTLRJAR=/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.2-SNAPSHOT/antlr4-4.11.2-SNAPSHOT-complete.jar
export TESTJAR=/Users/parrt/.m2/repository/org/antlr/antlr4-runtime-testsuite/4.11.2-SNAPSHOT/antlr4-runtime-testsuite-4.11.2-SNAPSHOT-tests.jar
java -classpath $ANTLRJAR:$TESTJAR org.antlr.v4.test.runtime.TraceATN $@
runtime-testsuite/test/org/antlr/v4/test/runtime/TraceATN.java