| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 // Test of FunctionUpdate by pretty printing the updated element before and | |
| 6 // after. | |
| 7 library trydart.library_updater_test; | |
| 8 | |
| 9 import 'package:dart2js_incremental/library_updater.dart' show | |
| 10 IncrementalCompilerContext, | |
| 11 LibraryUpdater, | |
| 12 Update; | |
| 13 | |
| 14 import 'package:compiler/src/parser/partial_elements.dart' show | |
| 15 PartialFunctionElement; | |
| 16 | |
| 17 import 'package:compiler/src/script.dart' show | |
| 18 Script; | |
| 19 | |
| 20 import 'package:compiler/src/io/source_file.dart' show | |
| 21 StringSourceFile; | |
| 22 | |
| 23 import 'compiler_test_case.dart'; | |
| 24 | |
| 25 import 'library_updater_test.dart' show | |
| 26 LibraryUpdaterTestCase, | |
| 27 newScriptFrom, | |
| 28 nolog; | |
| 29 | |
| 30 class ApplyUpdateTestCase extends LibraryUpdaterTestCase { | |
| 31 final String expectedUpdate; | |
| 32 | |
| 33 ApplyUpdateTestCase( | |
| 34 {String before, | |
| 35 String after, | |
| 36 String update}) | |
| 37 : this.expectedUpdate = update, | |
| 38 super(before: before, after: after, canReuse: true); | |
| 39 | |
| 40 Future run() => loadMainApp().then((LibraryElement library) { | |
| 41 // Capture the current version of [before] before invoking the [updater]. | |
| 42 PartialFunctionElement before = library.localLookup(expectedUpdate); | |
| 43 var beforeNode = before.parseNode(compiler.parsingContext); | |
| 44 | |
| 45 var context = new IncrementalCompilerContext(); | |
| 46 LibraryUpdater updater = | |
| 47 new LibraryUpdater(this.compiler, null, nolog, nolog, context); | |
| 48 context.registerUriWithUpdates([scriptUri]); | |
| 49 | |
| 50 bool actualCanReuse = | |
| 51 updater.canReuseLibrary( | |
| 52 library, <Script>[newScriptFrom(library, newSource)]); | |
| 53 Expect.equals(expectedCanReuse, actualCanReuse); | |
| 54 | |
| 55 Update update = updater.updates.single; | |
| 56 | |
| 57 // Check that the [updater] didn't modify the changed element. | |
| 58 Expect.identical(before, update.before); | |
| 59 Expect.identical(beforeNode, before.parseNode(compiler.parsingContext)); | |
| 60 | |
| 61 PartialFunctionElement after = update.after; | |
| 62 var afterNode = after.parseNode(compiler.parsingContext); | |
| 63 | |
| 64 // Check that pretty-printing the elements match [source] (before), and | |
| 65 // [newSource] (after). | |
| 66 Expect.stringEquals(source, '$beforeNode'); | |
| 67 Expect.stringEquals(newSource, '$afterNode'); | |
| 68 Expect.notEquals(source, newSource); | |
| 69 | |
| 70 // Apply the update. | |
| 71 update.apply(); | |
| 72 | |
| 73 // Check that the update was applied by pretty-printing [before]. Make no | |
| 74 // assumptions about [after], as the update may destroy that element. | |
| 75 beforeNode = before.parseNode(compiler.parsingContext); | |
| 76 Expect.notEquals(source, '$beforeNode'); | |
| 77 Expect.stringEquals(newSource, '$beforeNode'); | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 void main() { | |
| 82 runTests( | |
| 83 [ | |
| 84 new ApplyUpdateTestCase( | |
| 85 before: 'main(){print("Hello, World!");}', | |
| 86 after: 'main(){print("Hello, Brave New World!");}', | |
| 87 update: 'main'), | |
| 88 | |
| 89 new ApplyUpdateTestCase( | |
| 90 before: 'main(){foo(){return 1;}return foo();}', | |
| 91 after: 'main(){bar(){return "1";}return bar();}', | |
| 92 update: 'main'), | |
| 93 | |
| 94 new ApplyUpdateTestCase( | |
| 95 before: 'main()=>null;', | |
| 96 after: 'main(){}', | |
| 97 update: 'main'), | |
| 98 | |
| 99 new ApplyUpdateTestCase( | |
| 100 before: 'main(){}', | |
| 101 after: 'main()=>null;', | |
| 102 update: 'main'), | |
| 103 | |
| 104 // TODO(ahe): When supporting class members, test abstract methods. | |
| 105 ] | |
| 106 ); | |
| 107 } | |
| OLD | NEW |