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

Unified Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 816133002: Improve tests for refactoring exceptions. Catch initial exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use runZoned(). Created 6 years 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/edit/refactoring_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/edit/edit_domain.dart
diff --git a/pkg/analysis_server/lib/src/edit/edit_domain.dart b/pkg/analysis_server/lib/src/edit/edit_domain.dart
index b7c09b142471198f51da0486250291734247a2f5..2d598717ed322980d976cb915d15574914347015 100644
--- a/pkg/analysis_server/lib/src/edit/edit_domain.dart
+++ b/pkg/analysis_server/lib/src/edit/edit_domain.dart
@@ -25,11 +25,9 @@ import 'package:analyzer/src/generated/scanner.dart' as engine;
import 'package:analyzer/src/generated/source.dart';
-/**
- * This flag is used in tests to check behavior when an exception happens
- * inside a refactoring.
- */
-bool test_simulateRefactoringException = false;
+bool test_simulateRefactoringException_change = false;
+bool test_simulateRefactoringException_final = false;
+bool test_simulateRefactoringException_init = false;
/**
@@ -259,41 +257,51 @@ class _RefactoringManager {
EMPTY_PROBLEM_LIST);
// process the request
var params = new EditGetRefactoringParams.fromRequest(request);
- _init(params.kind, params.file, params.offset, params.length).then((_) {
- if (initStatus.hasFatalError) {
- feedback = null;
- return _sendResultResponse();
- }
- // set options
- if (_requiresOptions) {
- if (params.options == null) {
- optionsStatus = new RefactoringStatus();
+ runZoned(() {
+ _init(params.kind, params.file, params.offset, params.length).then((_) {
+ if (initStatus.hasFatalError) {
+ feedback = null;
return _sendResultResponse();
}
- optionsStatus = _setOptions(params);
- if (_hasFatalError) {
- return _sendResultResponse();
+ // set options
+ if (_requiresOptions) {
+ if (params.options == null) {
+ optionsStatus = new RefactoringStatus();
+ return _sendResultResponse();
+ }
+ optionsStatus = _setOptions(params);
+ if (_hasFatalError) {
+ return _sendResultResponse();
+ }
}
- }
- // done if just validation
- if (params.validateOnly) {
- finalStatus = new RefactoringStatus();
- return _sendResultResponse();
- }
- // validation and create change
- refactoring.checkFinalConditions().then((_finalStatus) {
- finalStatus = _finalStatus;
- if (_hasFatalError) {
+ // done if just validation
+ if (params.validateOnly) {
+ finalStatus = new RefactoringStatus();
return _sendResultResponse();
}
- // create change
- return refactoring.createChange().then((change) {
- result.change = change;
- result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds);
- return _sendResultResponse();
+ // simulate an exception
+ if (test_simulateRefactoringException_final) {
+ throw 'A simulated refactoring exception - final.';
+ }
+ // validation and create change
+ return refactoring.checkFinalConditions().then((_finalStatus) {
+ finalStatus = _finalStatus;
+ if (_hasFatalError) {
+ return _sendResultResponse();
+ }
+ // simulate an exception
+ if (test_simulateRefactoringException_change) {
+ throw 'A simulated refactoring exception - change.';
+ }
+ // create change
+ return refactoring.createChange().then((change) {
+ result.change = change;
+ result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds);
+ return _sendResultResponse();
+ });
});
});
- }).catchError((exception, stackTrace) {
+ }, onError: (exception, stackTrace) {
server.instrumentationService.logException(exception, stackTrace);
server.sendResponse(
new Response.serverError(request, exception, stackTrace));
@@ -320,8 +328,8 @@ class _RefactoringManager {
this.offset = offset;
this.length = length;
// simulate an exception
- if (test_simulateRefactoringException) {
- throw 'A simulated refactoring exception.';
+ if (test_simulateRefactoringException_init) {
+ throw 'A simulated refactoring exception - init.';
}
// create a new Refactoring instance
if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/edit/refactoring_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698