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 LibraryUpdater. |
| 6 library trydart.library_updater_test; |
| 7 |
| 8 import 'dart:convert' show |
| 9 UTF8; |
| 10 |
| 11 import 'package:dart2js_incremental/library_updater.dart' show |
| 12 LibraryUpdater, |
| 13 Update; |
| 14 |
| 15 import 'package:compiler/implementation/elements/elements.dart' show |
| 16 LibraryElement; |
| 17 |
| 18 import 'compiler_test_case.dart'; |
| 19 |
| 20 void nolog(_) {} |
| 21 |
| 22 class LibraryUpdaterTestCase extends CompilerTestCase { |
| 23 final String newSource; |
| 24 |
| 25 final bool expectedCanReuse; |
| 26 |
| 27 final List<String> expectedUpdates; |
| 28 |
| 29 LibraryUpdaterTestCase( |
| 30 {String before, |
| 31 String after, |
| 32 bool canReuse, |
| 33 List<String> updates}) |
| 34 : this.newSource = after, |
| 35 this.expectedCanReuse = canReuse, |
| 36 this.expectedUpdates = updates, |
| 37 super(before); |
| 38 |
| 39 Future run() => mainApp.then((LibraryElement library) { |
| 40 LibraryUpdater updater = |
| 41 new LibraryUpdater(this.compiler, null, scriptUri, nolog, nolog); |
| 42 bool actualCanReuse = |
| 43 updater.canReuseLibrary(library, UTF8.encode(newSource)); |
| 44 Expect.equals(expectedCanReuse, actualCanReuse); |
| 45 |
| 46 Expect.setEquals( |
| 47 expectedUpdates.toSet(), |
| 48 updater.updates.map((Update update) => update.before.name).toSet()); |
| 49 }); |
| 50 |
| 51 String toString() => 'Before:\n$source\n\n\nAfter:\n$newSource'; |
| 52 } |
| 53 |
| 54 void main() { |
| 55 runTests( |
| 56 [ |
| 57 // Only method body changed. Can be reused if 'main' is |
| 58 // updated/patched. |
| 59 new LibraryUpdaterTestCase( |
| 60 before: 'main() { print("Hello, World!"); }', |
| 61 after: 'main() { print("Hello, Brave New World!"); }', |
| 62 canReuse: true, |
| 63 updates: ['main']), |
| 64 |
| 65 // Signature changed. Can't be reused. |
| 66 new LibraryUpdaterTestCase( |
| 67 before: 'main() { print("Hello, World!"); }', |
| 68 after: 'void main() { print("Hello, World!"); }', |
| 69 canReuse: false, |
| 70 updates: []), |
| 71 |
| 72 // Only whitespace changes. Can be reused; no updates/patches needed. |
| 73 new LibraryUpdaterTestCase( |
| 74 before: 'main(){print("Hello, World!");}', |
| 75 after: 'main() { print ( "Hello, World!" ) ; }', |
| 76 canReuse: true, |
| 77 updates: []), |
| 78 |
| 79 // Only whitespace/comment changes (in signature). Can be reused; no |
| 80 // updates/patches needed. |
| 81 new LibraryUpdaterTestCase( |
| 82 before: |
| 83 '/* Implicitly dynamic. */ main ( /* No parameters. */ ) ' |
| 84 '{print("Hello, World!");}', |
| 85 after: 'main() {print("Hello, World!");}', |
| 86 canReuse: true, |
| 87 updates: []), |
| 88 |
| 89 // Arrow function changed to method body. Can be reused if 'main' is |
| 90 // updated/patched. |
| 91 new LibraryUpdaterTestCase( |
| 92 before: 'main() => null', |
| 93 after: 'main() { return null; }', |
| 94 canReuse: true, |
| 95 updates: ['main']), |
| 96 |
| 97 // Empty body changed to contain a statement. Can be reused if 'main' |
| 98 // is updated/patched. |
| 99 new LibraryUpdaterTestCase( |
| 100 before: 'main() {}', |
| 101 after: 'main() { return null; }', |
| 102 canReuse: true, |
| 103 updates: ['main']), |
| 104 |
| 105 // Empty body changed to arrow. Can be reused if 'main' |
| 106 // is updated/patched. |
| 107 new LibraryUpdaterTestCase( |
| 108 before: 'main() {}', |
| 109 after: 'main() => null;', |
| 110 canReuse: true, |
| 111 updates: ['main']), |
| 112 |
| 113 // Arrow changed to empty body. Can be reused if 'main' |
| 114 // is updated/patched. |
| 115 new LibraryUpdaterTestCase( |
| 116 before: 'main() => null;', |
| 117 after: 'main() {}', |
| 118 canReuse: true, |
| 119 updates: ['main']), |
| 120 |
| 121 // TODO(ahe): When supporting class members, test abstract methods. |
| 122 ] |
| 123 ); |
| 124 } |
OLD | NEW |