Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: compiler/javatests/com/google/dart/compiler/end2end/End2EndTestCase.java

Issue 9464044: Updates incremental compilation tests to work w/o code generation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 package com.google.dart.compiler.end2end;
6
7 import com.google.dart.compiler.CommandLineOptions;
8 import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
9 import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions;
10 import com.google.dart.compiler.CompilerConfiguration;
11 import com.google.dart.compiler.CompilerTestCase;
12 import com.google.dart.compiler.DartCompilerListener;
13 import com.google.dart.compiler.DartCompilerListenerTest;
14 import com.google.dart.compiler.DartLibrarySourceTest;
15 import com.google.dart.compiler.DartSourceTest;
16 import com.google.dart.compiler.DefaultCompilerConfiguration;
17 import com.google.dart.compiler.LibrarySource;
18 import com.google.dart.compiler.MockLibrarySource;
19 import com.google.dart.compiler.backend.js.JavascriptBackend;
20 import com.google.dart.runner.DartRunner;
21 import com.google.dart.runner.RunnerError;
22
23 import org.kohsuke.args4j.CmdLineException;
24
25 import java.util.List;
26
27 /**
28 * Abstract base for end-to-end tests. Tests are entirely Dart code
29 * that are compiled and run within V8.
30 *
31 * TODO(zundel): code generation is being removed. Remove any references to cod e generation
32 * or running code.
33 */
34 public abstract class End2EndTestCase extends CompilerTestCase {
35
36 /**
37 * Creates an ApplicationSource that should be compiled and executed.
38 *
39 * @param srcs paths to the input.
40 * @param mainClass the name of the main class to execute.
41 * @return an ApplicationSource suitable to be compiled and executed.
42 */
43 protected LibrarySource createApplication(List<String> srcs) {
44 MockLibrarySource app = new MockLibrarySource();
45 for (String src : srcs) {
46 DartSourceTest dartSource = new DartSourceTest(getClass(), src, app);
47 app.addSource(dartSource);
48 }
49 return app;
50 }
51
52 /**
53 * Creates a compiler configuration appropriate for the optimization level.
54 */
55 CompilerConfiguration getCompilerConfiguration() {
56 // TODO(zundel): To be removed when code generation is removed
57 return new DefaultCompilerConfiguration(new JavascriptBackend()) {
58 @Override
59 public boolean checkOnly() {
60 return false;
61 }
62 };
63 }
64
65 /**
66 * Runs an end-to-end Dart test for the given compilation unit.
67 */
68 @Deprecated
69 protected void runTest(LibrarySource app, DartCompilerListener listener) {
70 runTest(app, listener, new String[0]);
71 }
72
73 @Deprecated
74 protected void runTest(LibrarySource app,
75 DartCompilerListener listener, String[] args) {
76 final CompilerConfiguration config = getCompilerConfiguration();
77 runTest(app, listener, config, args);
78 }
79
80 /**
81 * Compiles and runs an end-to-end Dart test for the given compilation unit.
82 *
83 */
84 @Deprecated
85 protected void runTest(LibrarySource app,
86 DartCompilerListener listener,
87 CompilerConfiguration config, String[] args) {
88 DartRunnerOptions verboseOptions = new CommandLineOptions.DartRunnerOptions( ) {
89 @Override
90 public boolean checkOnly() {
91 return false;
92 }
93 };
94 verboseOptions.setVerbose(true);
95 try {
96 DartRunner.compileAndRunApp(app, verboseOptions, config, listener, args,
97 System.out, System.err);
98 } catch (RunnerError e) {
99 fail(e.getLocalizedMessage());
100 }
101 }
102
103 /**
104 * Runs an end-to-end Dart test for the given compilation unit.
105 */
106 protected void runTest(LibrarySource app) {
107 DartCompilerListener listener = new DartCompilerListenerTest(null);
108 runTest(app, listener);
109 }
110
111 /**
112 * Runs an end-to-end Dart test for the given compilation unit.
113 */
114 protected void runTest(String appSrc, String[] args) throws Exception {
115 DartCompilerListener listener = new DartCompilerListenerTest(null);
116 CompilerOptions options = processCommandLineOptions(args);
117 DefaultCompilerConfiguration config = new DefaultCompilerConfiguration(optio ns);
118 runTest(new DartLibrarySourceTest(getClass(), appSrc),
119 listener,
120 config,
121 args);
122 }
123
124 /**
125 * Runs an end-to-end Dart test for the given compilation unit.
126 *
127 * @param srcs path to the Dart source files containing the test
128 * @param opLevel The type of optimization to perform on the test code.
129 */
130 protected void runTest(List<String> srcs) throws SecurityException {
131 runTest(createApplication(srcs));
132 }
133
134 protected void runTest(String appSrc) throws Exception {
135 runTest(new DartLibrarySourceTest(getClass(), appSrc));
136 }
137
138 protected static CompilerOptions processCommandLineOptions(String[] args) {
139 CompilerOptions compilerOptions = null;
140 try {
141 compilerOptions = new CompilerOptions();
142 CommandLineOptions.parse(args, compilerOptions);
143 if (args.length == 0 || compilerOptions.showHelp()) {
144 fail("invalid arguments.");
145 }
146 } catch (CmdLineException e) {
147 fail(e.getLocalizedMessage());
148 }
149 assert compilerOptions != null;
150 return compilerOptions;
151 }
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698