remove TestRunner and revector callers to DartRunner

It only had a few methods in it that all ended up delegating to DartRunner.

Review URL: http://codereview.chromium.org//8223005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@306 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
zundel@google.com 2011-10-10 19:11:41 +00:00
parent 95ab992168
commit 0294b62be1
10 changed files with 45 additions and 140 deletions

View file

@ -42,7 +42,7 @@ public class CommandLineOptions {
usage = "Treat some type checks as warnings\n instead of fatal errors")
private boolean shouldWarnOnNoSuchType = false;
@Option(name = "--enable_type_checks",
@Option(name = "--enable_type_checks",
usage = "Generate runtime type checks")
private boolean developerModeChecks = false;
@ -349,13 +349,6 @@ public class CommandLineOptions {
}
}
/**
* Command line options accepted by the {@link com.google.dart.runner.TestRunner} entry point.
*/
public static class TestRunnerOptions extends DartRunnerOptions {
}
/**
* Parses command line options, handling the feature to ignore unrecognized
* flags.

View file

@ -5,6 +5,7 @@
package com.google.dart.runner;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.dart.compiler.Backend;
@ -21,6 +22,8 @@ import com.google.dart.compiler.DefaultDartCompilerListener;
import com.google.dart.compiler.DefaultErrorFormatter;
import com.google.dart.compiler.LibrarySource;
import com.google.dart.compiler.Source;
import com.google.dart.compiler.UnitTestBatchRunner;
import com.google.dart.compiler.UnitTestBatchRunner.Invocation;
import com.google.dart.compiler.UrlLibrarySource;
import com.google.dart.compiler.backend.js.ClosureJsBackend;
import com.google.dart.compiler.backend.js.JavascriptBackend;
@ -72,10 +75,34 @@ public class DartRunner {
public static void main(String[] args) {
try {
boolean runBatch = false;
final List<LibrarySource> imports = Collections.emptyList();
DartRunnerOptions options = processCommandLineOptions(args);
throwingMain(options, args, Collections.<LibrarySource>emptyList(), System.out, System.err);
} catch (RunnerError error) {
System.err.println(error.getLocalizedMessage());
if (options.shouldBatch()) {
runBatch = true;
if (args.length > 1) {
System.err
.println("(Extra arguments specified with -batch ignored.)");
}
}
if (runBatch) {
UnitTestBatchRunner.runAsBatch(args, new Invocation() {
@Override
public boolean invoke(String[] args) throws Throwable {
try {
throwingMain(args, System.out, System.err);
} catch (RunnerError e) {
System.out.println(e.getLocalizedMessage());
return false;
}
return true;
}
});
} else {
throwingMain(args, System.out, System.err);
}
} catch (RunnerError e) {
System.err.println(e.getLocalizedMessage());
System.exit(1);
} catch (Throwable e) {
e.printStackTrace();
@ -83,13 +110,12 @@ public class DartRunner {
}
}
public static void throwingMain(DartRunnerOptions options,
String[] args,
List<LibrarySource> imports,
public static void throwingMain(String[] args,
PrintStream stdout,
final PrintStream stderr)
throws RunnerError {
DartRunnerOptions options = processCommandLineOptions(args);
List<LibrarySource> imports = Lists.newArrayList();
if (options.getSourceFiles().isEmpty()) {
throw new RunnerError("No script files specified on the command line: " + Joiner.on(" ").join(args));
}

View file

@ -1,109 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.google.dart.runner;
import com.google.dart.compiler.CommandLineOptions;
import com.google.dart.compiler.CommandLineOptions.TestRunnerOptions;
import com.google.dart.compiler.DartCompiler;
import com.google.dart.compiler.LibrarySource;
import com.google.dart.compiler.UnitTestBatchRunner;
import com.google.dart.compiler.UnitTestBatchRunner.Invocation;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
/**
* Runs dart programs.<br/>
* The command-line interface is similar to the VM's command line interface.
* </br>
*/
public class TestRunner {
public static void main(String[] args) {
try {
boolean runBatch = false;
TestRunnerOptions options = processCommandLineOptions(args);
if (options.shouldBatch()) {
runBatch = true;
if (args.length > 1) {
System.err.println("(Extra arguments specified with -batch ignored.)");
}
}
if (runBatch) {
UnitTestBatchRunner.runAsBatch(args, new Invocation() {
@Override
public boolean invoke(String[] args) throws Throwable {
try {
throwingMain(args, System.out, System.err);
} catch (RunnerError e) {
System.out.println(e.getLocalizedMessage());
return false;
}
return true;
}
});
} else {
throwingMain(args, System.out, System.err);
}
} catch (RunnerError e) {
System.err.println(e.getLocalizedMessage());
System.exit(1);
} catch (Throwable e) {
e.printStackTrace();
DartCompiler.crash();
}
}
private static void printUsageAndThrow(CmdLineParser cmdLineParser, String reason) throws RunnerError {
StringBuilder usage = new StringBuilder();
usage.append(reason);
usage.append("\n");
usage.append("Usage: ");
usage.append(System.getProperty("com.google.dart.runner.progname",
TestRunner.class.getSimpleName()));
usage.append(" [<options>] <dart-script-file> [<script-arguments>]\n");
usage.append("\n");
OutputStream s = new ByteArrayOutputStream();
if (cmdLineParser == null) {
cmdLineParser = new CmdLineParser(new TestRunnerOptions());
}
cmdLineParser.printUsage(s);
usage.append(s);
throw new RunnerError(usage.toString());
}
private static TestRunnerOptions processCommandLineOptions(String[] args) throws RunnerError {
CmdLineParser cmdLineParser = null;
TestRunnerOptions parsedOptions = null;
try {
parsedOptions = new TestRunnerOptions();
cmdLineParser = CommandLineOptions.parse(args, parsedOptions);
if (args.length == 0 || parsedOptions.showHelp()) {
printUsageAndThrow(cmdLineParser, "");
System.exit(1);
}
} catch (CmdLineException e) {
printUsageAndThrow(cmdLineParser, e.getLocalizedMessage());
System.exit(1);
}
assert parsedOptions != null;
return parsedOptions;
}
public static void throwingMain(String[] args, PrintStream stdout, PrintStream stderr)
throws RunnerError {
TestRunnerOptions options = processCommandLineOptions(args);
List<LibrarySource> imports = new ArrayList<LibrarySource>();
DartRunner.throwingMain(options, args, imports, stdout, stderr);
}
}

View file

@ -89,13 +89,8 @@ public abstract class End2EndTestCase extends CompilerTestCase {
DartRunnerOptions verboseOptions = new CommandLineOptions.DartRunnerOptions();
verboseOptions.setVerbose(true);
try {
DartRunner.compileAndRunApp(app,
verboseOptions,
config,
listener,
args,
System.out,
System.err);
DartRunner.compileAndRunApp(app, verboseOptions, config, listener, args,
System.out, System.err);
} catch (RhinoException e) {
// TODO(jgw): This is a hack to dump the translated source when something goes wrong. It can
// be removed as soon as we have a source map we can use to provide source-level errors.

View file

@ -73,8 +73,8 @@ public class NonStrictResolutionTest extends End2EndTestCase {
StringStream outStream = new StringStream(System.out);
StringStream errStream = new StringStream(System.err);
try {
DartRunner
.compileAndRunApp(app, verboseOptions, config, listener, args, outStream, errStream);
DartRunner.compileAndRunApp(app, verboseOptions, config, listener, args,
outStream, errStream);
} catch (RhinoException e) {
super.fail(e.getLocalizedMessage());
} catch (RunnerError e) {

View file

@ -16,8 +16,8 @@ import com.google.dart.compiler.DefaultLibrarySource;
import com.google.dart.compiler.LibrarySource;
import com.google.dart.compiler.Source;
import com.google.dart.compiler.UrlLibrarySource;
import com.google.dart.runner.DartRunner;
import com.google.dart.runner.RunnerError;
import com.google.dart.runner.TestRunner;
import com.google.dart.runner.V8Launcher;
import junit.framework.AssertionFailedError;
@ -138,7 +138,7 @@ public class SharedTestCase extends TestCase {
if (regularCompile) {
invokeCompiler();
} else {
TestRunner.throwingMain(arguments, outputStream, outputStream);
DartRunner.throwingMain(arguments, outputStream, outputStream);
}
} catch (RunnerError e) {
outputStream.close();

View file

@ -11,7 +11,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Dartc test runner tests");
suite.addTestSuite(TestRunnerTest.class);
suite.addTestSuite(DartRunnerTest.class);
return suite;
}

View file

@ -9,11 +9,11 @@ import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
public class TestRunnerTest extends TestCase {
public class DartRunnerTest extends TestCase {
public void testMain() throws Throwable {
try {
PrintStream stream = new PrintStream(new ByteArrayOutputStream());
TestRunner.throwingMain("NoSuchFile.dart".split(" "), stream, stream);
DartRunner.throwingMain("NoSuchFile.dart".split(" "), stream, stream);
fail("Expected a compilation failure.");
} catch (RunnerError e) {
// Expected this exception.

View file

@ -55,7 +55,7 @@ exec $JAVABIN -ea -classpath @CLASSPATH@ \
${JVM_DEBUG_FLAGS} \
${JVM_FLAGS} \
${JVM_FLAGS_CMDLINE} \
com.google.dart.runner.TestRunner \
com.google.dart.runner.DartRunner \
$DARTC_FLAGS \
"$@"

View file

@ -28,4 +28,4 @@ fi
exec java -ea -Dcom.google.dart.runner.d8="$D8_EXEC" \
-Dcom.google.dart.runner.progname="$DART_SCRIPT_NAME" \
-classpath "@CLASSPATH@" \
com.google.dart.runner.TestRunner $@
com.google.dart.runner.DartRunner $@