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

Unified Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java

Issue 8523034: Compile Time Constants cycle check (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added new test to exercise code that was throwing ICE Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java
index 5bf7ba73548db88be9b923a977f025d47d2960e0..073adc81c55f440d7449425fea8e55cbc7212576 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java
@@ -49,19 +49,35 @@ abstract class ResolverTestCase extends TestCase {
resetParseErrors();
}
- static Scope resolve(DartUnit unit, TestCompilerContext context) {
- Scope scope = new Scope("library", null);
+ private static CoreTypeProvider setupTypeProvider(DartUnit unit, TestCompilerContext context, Scope scope) {
new TopLevelElementBuilder().exec(unit, context);
new TopLevelElementBuilder().fillInUnitScope(unit, context, scope);
ClassElement object = (ClassElement) scope.findElement(null, "Object");
assertNotNull("Cannot resolve Object", object);
- CoreTypeProvider typeProvider = new MockCoreTypeProvider(object);
+ return new MockCoreTypeProvider(object);
+ }
+
+ static Scope resolve(DartUnit unit, TestCompilerContext context) {
+ Scope scope = new Scope("library", null);
+ CoreTypeProvider typeProvider = setupTypeProvider(unit, context, scope);
new SupertypeResolver().exec(unit, context, scope, typeProvider);
new MemberBuilder().exec(unit, context, scope, typeProvider);
new Resolver(context, scope, typeProvider).exec(unit);
return scope;
}
+ static Scope resolveCompileTimeConst (DartUnit unit, TestCompilerContext context) {
+ Scope scope = new Scope("library", null);
+ CoreTypeProvider typeProvider = setupTypeProvider(unit, context, scope);
+ new SupertypeResolver().exec(unit, context, scope, typeProvider);
+ new MemberBuilder().exec(unit, context, scope, typeProvider);
+ // Substitute the lightweight CTConst resolver
+ new CompileTimeConstantResolver().exec(unit, context, scope, typeProvider);
+ new CompileTimeConstantAnalyzer(typeProvider, context).exec(unit);
+ return scope;
+ }
+
+
static DartClass makeClass(String name, DartTypeNode supertype, String... typeParameters) {
return makeClass(name, supertype, Collections.<DartTypeNode>emptyList(), typeParameters);
}
@@ -365,7 +381,7 @@ abstract class ResolverTestCase extends TestCase {
*/
protected void printEncountered(List<DartCompilationError> encountered) {
for (DartCompilationError error : encountered) {
- ErrorCode errorCode = (ErrorCode) error.getErrorCode();
+ ErrorCode errorCode = error.getErrorCode();
String msg =
String.format(
"%s > %s (%d:%d)",
@@ -379,7 +395,7 @@ abstract class ResolverTestCase extends TestCase {
/**
* Convenience method to parse and resolve a code snippet, then test for error codes.
- *
+ *
* @return resolve errors.
*/
protected List<DartCompilationError> resolveAndTest(String source, ErrorCode... errorCodes) {
@@ -404,4 +420,32 @@ abstract class ResolverTestCase extends TestCase {
checkExpectedErrors(resolveErrors, errorCodes, source);
return resolveErrors;
}
+
+ /**
+ * Convenience method to parse and resolve a code snippet, then test for error codes.
+ *
+ * @return resolve errors.
+ */
+ protected List<DartCompilationError> resolveAndTestCtConst(String source, ErrorCode... errorCodes) {
+ // parse DartUnit
+ DartUnit unit = parseUnit(source);
+ if (parseErrors.size() != 0) {
+ printSource(source);
+ printEncountered(parseErrors);
+ assertEquals("Expected no errors in parse step:", 0, parseErrors.size());
+ }
+ // prepare for recording resolving errors
+ resetParseErrors();
+ final List<DartCompilationError> resolveErrors = Lists.newArrayList();
+ TestCompilerContext ctx = new TestCompilerContext() {
+ @Override
+ public void onError(DartCompilationError event) {
+ resolveErrors.add(event);
+ }
+ };
+ // resolve and check errors
+ resolveCompileTimeConst(unit, ctx);
+ checkExpectedErrors(resolveErrors, errorCodes, source);
+ return resolveErrors;
+ }
}
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698