| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:front_end/memory_file_system.dart'; | 7 import 'package:front_end/memory_file_system.dart'; |
| 8 import 'package:front_end/src/base/performace_logger.dart'; | 8 import 'package:front_end/src/base/performace_logger.dart'; |
| 9 import 'package:front_end/src/fasta/kernel/utils.dart'; | 9 import 'package:front_end/src/fasta/kernel/utils.dart'; |
| 10 import 'package:front_end/src/fasta/uri_translator_impl.dart'; | 10 import 'package:front_end/src/fasta/uri_translator_impl.dart'; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 void setUp() { | 37 void setUp() { |
| 38 _createDriver(); | 38 _createDriver(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 test_compile_chain() async { | 41 test_compile_chain() async { |
| 42 writeFile('/test/.packages', 'test:lib/'); | 42 writeFile('/test/.packages', 'test:lib/'); |
| 43 String aPath = '/test/lib/a.dart'; | 43 String aPath = '/test/lib/a.dart'; |
| 44 String bPath = '/test/lib/b.dart'; | 44 String bPath = '/test/lib/b.dart'; |
| 45 String cPath = '/test/lib/c.dart'; | 45 String cPath = '/test/lib/c.dart'; |
| 46 Uri aUri = writeFile(aPath, 'var a = 1;'); | 46 Uri aUri = writeFile(aPath, 'var a = 1;'); |
| 47 Uri bUri = writeFile( | 47 Uri bUri = writeFile(bPath, r''' |
| 48 bPath, | |
| 49 r''' | |
| 50 import 'a.dart'; | 48 import 'a.dart'; |
| 51 var b = a; | 49 var b = a; |
| 52 '''); | 50 '''); |
| 53 Uri cUri = writeFile( | 51 Uri cUri = writeFile(cPath, r''' |
| 54 cPath, | |
| 55 r''' | |
| 56 import 'a.dart'; | 52 import 'a.dart'; |
| 57 import 'b.dart'; | 53 import 'b.dart'; |
| 58 var c1 = a; | 54 var c1 = a; |
| 59 var c2 = b; | 55 var c2 = b; |
| 60 void main() {} | 56 void main() {} |
| 61 '''); | 57 '''); |
| 62 | 58 |
| 63 { | 59 { |
| 64 KernelResult result = await driver.getKernel(cUri); | 60 KernelResult result = await driver.getKernel(cUri); |
| 65 _assertLibraryUris(result, | 61 _assertLibraryUris(result, |
| 66 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 62 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 67 Library library = _getLibrary(result, cUri); | 63 Library library = _getLibrary(result, cUri); |
| 68 expect( | 64 expect(_getLibraryText(library), r''' |
| 69 _getLibraryText(library), | |
| 70 r''' | |
| 71 library; | 65 library; |
| 72 import self as self; | 66 import self as self; |
| 73 import "dart:core" as core; | 67 import "dart:core" as core; |
| 74 import "./a.dart" as a; | 68 import "./a.dart" as a; |
| 75 import "./b.dart" as b; | 69 import "./b.dart" as b; |
| 76 | 70 |
| 77 static field core::int c1 = a::a; | 71 static field core::int c1 = a::a; |
| 78 static field core::int c2 = b::b; | 72 static field core::int c2 = b::b; |
| 79 static method main() → void {} | 73 static method main() → void {} |
| 80 '''); | 74 '''); |
| 81 } | 75 } |
| 82 | 76 |
| 83 // Update b.dart and recompile c.dart | 77 // Update b.dart and recompile c.dart |
| 84 writeFile( | 78 writeFile(bPath, r''' |
| 85 bPath, | |
| 86 r''' | |
| 87 import 'a.dart'; | 79 import 'a.dart'; |
| 88 var b = 1.2; | 80 var b = 1.2; |
| 89 '''); | 81 '''); |
| 90 driver.invalidate(bUri); | 82 driver.invalidate(bUri); |
| 91 { | 83 { |
| 92 KernelResult result = await driver.getKernel(cUri); | 84 KernelResult result = await driver.getKernel(cUri); |
| 93 _assertLibraryUris(result, | 85 _assertLibraryUris(result, |
| 94 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 86 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 95 Library library = _getLibrary(result, cUri); | 87 Library library = _getLibrary(result, cUri); |
| 96 expect( | 88 expect(_getLibraryText(library), r''' |
| 97 _getLibraryText(library), | |
| 98 r''' | |
| 99 library; | 89 library; |
| 100 import self as self; | 90 import self as self; |
| 101 import "dart:core" as core; | 91 import "dart:core" as core; |
| 102 import "./a.dart" as a; | 92 import "./a.dart" as a; |
| 103 import "./b.dart" as b; | 93 import "./b.dart" as b; |
| 104 | 94 |
| 105 static field core::int c1 = a::a; | 95 static field core::int c1 = a::a; |
| 106 static field core::double c2 = b::b; | 96 static field core::double c2 = b::b; |
| 107 static method main() → void {} | 97 static method main() → void {} |
| 108 '''); | 98 '''); |
| 109 } | 99 } |
| 110 } | 100 } |
| 111 | 101 |
| 112 test_compile_export() async { | 102 test_compile_export() async { |
| 113 writeFile('/test/.packages', 'test:lib/'); | 103 writeFile('/test/.packages', 'test:lib/'); |
| 114 String aPath = '/test/lib/a.dart'; | 104 String aPath = '/test/lib/a.dart'; |
| 115 String bPath = '/test/lib/b.dart'; | 105 String bPath = '/test/lib/b.dart'; |
| 116 String cPath = '/test/lib/c.dart'; | 106 String cPath = '/test/lib/c.dart'; |
| 117 writeFile(aPath, 'class A {}'); | 107 writeFile(aPath, 'class A {}'); |
| 118 writeFile(bPath, 'export "a.dart";'); | 108 writeFile(bPath, 'export "a.dart";'); |
| 119 Uri cUri = writeFile( | 109 Uri cUri = writeFile(cPath, r''' |
| 120 cPath, | |
| 121 r''' | |
| 122 import 'b.dart'; | 110 import 'b.dart'; |
| 123 A a; | 111 A a; |
| 124 '''); | 112 '''); |
| 125 | 113 |
| 126 KernelResult result = await driver.getKernel(cUri); | 114 KernelResult result = await driver.getKernel(cUri); |
| 127 Library library = _getLibrary(result, cUri); | 115 Library library = _getLibrary(result, cUri); |
| 128 expect( | 116 expect(_getLibraryText(library), r''' |
| 129 _getLibraryText(library), | |
| 130 r''' | |
| 131 library; | 117 library; |
| 132 import self as self; | 118 import self as self; |
| 133 import "./a.dart" as a; | 119 import "./a.dart" as a; |
| 134 | 120 |
| 135 static field a::A a; | 121 static field a::A a; |
| 136 '''); | 122 '''); |
| 137 } | 123 } |
| 138 | 124 |
| 139 test_compile_export_cycle() async { | 125 test_compile_export_cycle() async { |
| 140 writeFile('/test/.packages', 'test:lib/'); | 126 writeFile('/test/.packages', 'test:lib/'); |
| 141 String aPath = '/test/lib/a.dart'; | 127 String aPath = '/test/lib/a.dart'; |
| 142 String bPath = '/test/lib/b.dart'; | 128 String bPath = '/test/lib/b.dart'; |
| 143 String cPath = '/test/lib/c.dart'; | 129 String cPath = '/test/lib/c.dart'; |
| 144 writeFile(aPath, 'export "b.dart"; class A {}'); | 130 writeFile(aPath, 'export "b.dart"; class A {}'); |
| 145 writeFile(bPath, 'export "a.dart"; class B {}'); | 131 writeFile(bPath, 'export "a.dart"; class B {}'); |
| 146 Uri cUri = writeFile( | 132 Uri cUri = writeFile(cPath, r''' |
| 147 cPath, | |
| 148 r''' | |
| 149 import 'b.dart'; | 133 import 'b.dart'; |
| 150 A a; | 134 A a; |
| 151 B b; | 135 B b; |
| 152 '''); | 136 '''); |
| 153 | 137 |
| 154 { | 138 { |
| 155 KernelResult result = await driver.getKernel(cUri); | 139 KernelResult result = await driver.getKernel(cUri); |
| 156 Library library = _getLibrary(result, cUri); | 140 Library library = _getLibrary(result, cUri); |
| 157 expect( | 141 expect(_getLibraryText(library), r''' |
| 158 _getLibraryText(library), | |
| 159 r''' | |
| 160 library; | 142 library; |
| 161 import self as self; | 143 import self as self; |
| 162 import "./a.dart" as a; | 144 import "./a.dart" as a; |
| 163 import "./b.dart" as b; | 145 import "./b.dart" as b; |
| 164 | 146 |
| 165 static field a::A a; | 147 static field a::A a; |
| 166 static field b::B b; | 148 static field b::B b; |
| 167 '''); | 149 '''); |
| 168 } | 150 } |
| 169 | 151 |
| 170 // Update c.dart and compile. | 152 // Update c.dart and compile. |
| 171 // We should load the cycle [a.dart, b.dart] from the byte store. | 153 // We should load the cycle [a.dart, b.dart] from the byte store. |
| 172 // This tests that we compute export scopes after loading. | 154 // This tests that we compute export scopes after loading. |
| 173 writeFile( | 155 writeFile(cPath, r''' |
| 174 cPath, | |
| 175 r''' | |
| 176 import 'b.dart'; | 156 import 'b.dart'; |
| 177 A a; | 157 A a; |
| 178 B b; | 158 B b; |
| 179 int c; | 159 int c; |
| 180 '''); | 160 '''); |
| 181 driver.invalidate(cUri); | 161 driver.invalidate(cUri); |
| 182 { | 162 { |
| 183 KernelResult result = await driver.getKernel(cUri); | 163 KernelResult result = await driver.getKernel(cUri); |
| 184 Library library = _getLibrary(result, cUri); | 164 Library library = _getLibrary(result, cUri); |
| 185 expect( | 165 expect(_getLibraryText(library), r''' |
| 186 _getLibraryText(library), | |
| 187 r''' | |
| 188 library; | 166 library; |
| 189 import self as self; | 167 import self as self; |
| 190 import "./a.dart" as a; | 168 import "./a.dart" as a; |
| 191 import "./b.dart" as b; | 169 import "./b.dart" as b; |
| 192 import "dart:core" as core; | 170 import "dart:core" as core; |
| 193 | 171 |
| 194 static field a::A a; | 172 static field a::A a; |
| 195 static field b::B b; | 173 static field b::B b; |
| 196 static field core::int c; | 174 static field core::int c; |
| 197 '''); | 175 '''); |
| 198 } | 176 } |
| 199 } | 177 } |
| 200 | 178 |
| 201 test_compile_export_hideWithLocal() async { | 179 test_compile_export_hideWithLocal() async { |
| 202 writeFile('/test/.packages', 'test:lib/'); | 180 writeFile('/test/.packages', 'test:lib/'); |
| 203 String aPath = '/test/lib/a.dart'; | 181 String aPath = '/test/lib/a.dart'; |
| 204 String bPath = '/test/lib/b.dart'; | 182 String bPath = '/test/lib/b.dart'; |
| 205 String cPath = '/test/lib/c.dart'; | 183 String cPath = '/test/lib/c.dart'; |
| 206 writeFile(aPath, 'class A {} class B {}'); | 184 writeFile(aPath, 'class A {} class B {}'); |
| 207 writeFile(bPath, 'export "a.dart"; class B {}'); | 185 writeFile(bPath, 'export "a.dart"; class B {}'); |
| 208 Uri cUri = writeFile( | 186 Uri cUri = writeFile(cPath, r''' |
| 209 cPath, | |
| 210 r''' | |
| 211 import 'b.dart'; | 187 import 'b.dart'; |
| 212 A a; | 188 A a; |
| 213 B b; | 189 B b; |
| 214 '''); | 190 '''); |
| 215 | 191 |
| 216 KernelResult result = await driver.getKernel(cUri); | 192 KernelResult result = await driver.getKernel(cUri); |
| 217 Library library = _getLibrary(result, cUri); | 193 Library library = _getLibrary(result, cUri); |
| 218 expect( | 194 expect(_getLibraryText(library), r''' |
| 219 _getLibraryText(library), | |
| 220 r''' | |
| 221 library; | 195 library; |
| 222 import self as self; | 196 import self as self; |
| 223 import "./a.dart" as a; | 197 import "./a.dart" as a; |
| 224 import "./b.dart" as b; | 198 import "./b.dart" as b; |
| 225 | 199 |
| 226 static field a::A a; | 200 static field a::A a; |
| 227 static field b::B b; | 201 static field b::B b; |
| 228 '''); | 202 '''); |
| 229 } | 203 } |
| 230 | 204 |
| 231 test_compile_recompileMixin() async { | 205 test_compile_recompileMixin() async { |
| 232 writeFile('/test/.packages', 'test:lib/'); | 206 writeFile('/test/.packages', 'test:lib/'); |
| 233 String aPath = '/test/lib/a.dart'; | 207 String aPath = '/test/lib/a.dart'; |
| 234 String bPath = '/test/lib/b.dart'; | 208 String bPath = '/test/lib/b.dart'; |
| 235 String cPath = '/test/lib/c.dart'; | 209 String cPath = '/test/lib/c.dart'; |
| 236 | 210 |
| 237 Uri aUri = writeFile( | 211 Uri aUri = writeFile(aPath, r''' |
| 238 aPath, | |
| 239 r''' | |
| 240 import 'b.dart'; | 212 import 'b.dart'; |
| 241 main() { | 213 main() { |
| 242 new B().foo(); | 214 new B().foo(); |
| 243 } | 215 } |
| 244 '''); | 216 '''); |
| 245 Uri bUri = writeFile( | 217 Uri bUri = writeFile(bPath, r''' |
| 246 bPath, | |
| 247 r''' | |
| 248 import 'c.dart'; | 218 import 'c.dart'; |
| 249 class B extends Object with C {} | 219 class B extends Object with C {} |
| 250 '''); | 220 '''); |
| 251 Uri cUri = writeFile( | 221 Uri cUri = writeFile(cPath, r''' |
| 252 cPath, | |
| 253 r''' | |
| 254 class C { | 222 class C { |
| 255 void foo() { | 223 void foo() { |
| 256 print(0); | 224 print(0); |
| 257 } | 225 } |
| 258 } | 226 } |
| 259 '''); | 227 '''); |
| 260 | 228 |
| 261 { | 229 { |
| 262 KernelResult result = await driver.getKernel(aUri); | 230 KernelResult result = await driver.getKernel(aUri); |
| 263 _assertLibraryUris(result, | 231 _assertLibraryUris(result, |
| 264 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 232 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 265 } | 233 } |
| 266 | 234 |
| 267 // Update c.dart and compute the delta. | 235 // Update c.dart and compute the delta. |
| 268 // Includes: c.dart, b.dart and a.dart files. | 236 // Includes: c.dart, b.dart and a.dart files. |
| 269 // Compiled: c.dart (changed) and b.dart (has mixin), but not a.dart file. | 237 // Compiled: c.dart (changed) and b.dart (has mixin), but not a.dart file. |
| 270 writeFile( | 238 writeFile(cPath, r''' |
| 271 cPath, | |
| 272 r''' | |
| 273 class C { | 239 class C { |
| 274 void foo() { | 240 void foo() { |
| 275 print(1); | 241 print(1); |
| 276 } | 242 } |
| 277 } | 243 } |
| 278 '''); | 244 '''); |
| 279 driver.invalidate(cUri); | 245 driver.invalidate(cUri); |
| 280 { | 246 { |
| 281 KernelResult result = await driver.getKernel(aUri); | 247 KernelResult result = await driver.getKernel(aUri); |
| 282 _assertLibraryUris(result, | 248 _assertLibraryUris(result, |
| 283 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 249 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 284 // Compiled: c.dart (changed), and b.dart (has mixin). | 250 // Compiled: c.dart (changed), and b.dart (has mixin). |
| 285 _assertCompiledUris([cUri, bUri]); | 251 _assertCompiledUris([cUri, bUri]); |
| 286 } | 252 } |
| 287 } | 253 } |
| 288 | 254 |
| 289 test_compile_typedef() async { | 255 test_compile_typedef() async { |
| 290 writeFile('/test/.packages', 'test:lib/'); | 256 writeFile('/test/.packages', 'test:lib/'); |
| 291 String aPath = '/test/lib/a.dart'; | 257 String aPath = '/test/lib/a.dart'; |
| 292 String bPath = '/test/lib/b.dart'; | 258 String bPath = '/test/lib/b.dart'; |
| 293 writeFile(aPath, 'typedef int F<T>(T x);'); | 259 writeFile(aPath, 'typedef int F<T>(T x);'); |
| 294 Uri bUri = writeFile( | 260 Uri bUri = writeFile(bPath, r''' |
| 295 bPath, | |
| 296 r''' | |
| 297 import 'a.dart'; | 261 import 'a.dart'; |
| 298 F<String> f; | 262 F<String> f; |
| 299 '''); | 263 '''); |
| 300 | 264 |
| 301 KernelResult result = await driver.getKernel(bUri); | 265 KernelResult result = await driver.getKernel(bUri); |
| 302 Library library = _getLibrary(result, bUri); | 266 Library library = _getLibrary(result, bUri); |
| 303 expect( | 267 expect(_getLibraryText(library), r''' |
| 304 _getLibraryText(library), | |
| 305 r''' | |
| 306 library; | 268 library; |
| 307 import self as self; | 269 import self as self; |
| 308 import "dart:core" as core; | 270 import "dart:core" as core; |
| 309 | 271 |
| 310 static field (core::String) → core::int f; | 272 static field (core::String) → core::int f; |
| 311 '''); | 273 '''); |
| 312 } | 274 } |
| 313 | 275 |
| 314 test_limited_ast_to_binary() async { | 276 test_limited_ast_to_binary() async { |
| 315 writeFile('/test/.packages', 'test:lib/'); | 277 writeFile('/test/.packages', 'test:lib/'); |
| 316 String aPath = '/test/lib/a.dart'; | 278 String aPath = '/test/lib/a.dart'; |
| 317 String bPath = '/test/lib/b.dart'; | 279 String bPath = '/test/lib/b.dart'; |
| 318 writeFile( | 280 writeFile(aPath, r''' |
| 319 aPath, | |
| 320 r''' | |
| 321 int topField = 0; | 281 int topField = 0; |
| 322 int get topGetter => 0; | 282 int get topGetter => 0; |
| 323 int topFunction({p}) => 0; | 283 int topFunction({p}) => 0; |
| 324 | 284 |
| 325 abstract class I { | 285 abstract class I { |
| 326 int interfaceField; | 286 int interfaceField; |
| 327 int get interfaceGetter; | 287 int get interfaceGetter; |
| 328 int interfaceMethod(); | 288 int interfaceMethod(); |
| 329 } | 289 } |
| 330 | 290 |
| 331 class A implements I { | 291 class A implements I { |
| 332 static int staticField; | 292 static int staticField; |
| 333 static int get staticGetter => 0; | 293 static int get staticGetter => 0; |
| 334 static int staticMethod() => 0; | 294 static int staticMethod() => 0; |
| 335 | 295 |
| 336 int instanceField; | 296 int instanceField; |
| 337 int get instanceGetter => 0; | 297 int get instanceGetter => 0; |
| 338 int instanceMethod() => 0; | 298 int instanceMethod() => 0; |
| 339 | 299 |
| 340 int interfaceField; | 300 int interfaceField; |
| 341 int get interfaceGetter => 0; | 301 int get interfaceGetter => 0; |
| 342 int interfaceMethod() => 0; | 302 int interfaceMethod() => 0; |
| 343 | 303 |
| 344 A(); | 304 A(); |
| 345 A.named(); | 305 A.named(); |
| 346 } | 306 } |
| 347 '''); | 307 '''); |
| 348 Uri bUri = writeFile( | 308 Uri bUri = writeFile(bPath, r''' |
| 349 bPath, | |
| 350 r''' | |
| 351 import 'a.dart'; | 309 import 'a.dart'; |
| 352 | 310 |
| 353 class B extends A { | 311 class B extends A { |
| 354 B() : super(); | 312 B() : super(); |
| 355 B.named() : super.named(); | 313 B.named() : super.named(); |
| 356 | 314 |
| 357 void foo() { | 315 void foo() { |
| 358 super.instanceMethod(); | 316 super.instanceMethod(); |
| 359 instanceMethod(); | 317 instanceMethod(); |
| 360 | 318 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 .firstWhere((procedure) => procedure.name.name == 'main'); | 392 .firstWhere((procedure) => procedure.name.name == 'main'); |
| 435 | 393 |
| 436 expect(_getLibraryText(loadedLibrary), initialKernelText); | 394 expect(_getLibraryText(loadedLibrary), initialKernelText); |
| 437 verifyProgram(program); | 395 verifyProgram(program); |
| 438 } | 396 } |
| 439 | 397 |
| 440 test_updatePackageSourceUsingFileUri() async { | 398 test_updatePackageSourceUsingFileUri() async { |
| 441 _createDriver(packages: {'test': _folderUri('/test/lib')}); | 399 _createDriver(packages: {'test': _folderUri('/test/lib')}); |
| 442 | 400 |
| 443 writeFile('/test/.packages', 'test:lib/'); | 401 writeFile('/test/.packages', 'test:lib/'); |
| 444 Uri aFileUri = writeFile( | 402 Uri aFileUri = writeFile('/test/bin/a.dart', r''' |
| 445 '/test/bin/a.dart', | |
| 446 r''' | |
| 447 import 'package:test/b.dart'; | 403 import 'package:test/b.dart'; |
| 448 var a = b; | 404 var a = b; |
| 449 '''); | 405 '''); |
| 450 Uri bFileUri = writeFile('/test/lib/b.dart', 'var b = 1;'); | 406 Uri bFileUri = writeFile('/test/lib/b.dart', 'var b = 1;'); |
| 451 Uri bPackageUri = Uri.parse('package:test/b.dart'); | 407 Uri bPackageUri = Uri.parse('package:test/b.dart'); |
| 452 | 408 |
| 453 // Compute the initial state. | 409 // Compute the initial state. |
| 454 { | 410 { |
| 455 KernelResult result = await driver.getKernel(aFileUri); | 411 KernelResult result = await driver.getKernel(aFileUri); |
| 456 Library library = _getLibrary(result, aFileUri); | 412 Library library = _getLibrary(result, aFileUri); |
| 457 expect( | 413 expect(_getLibraryText(library), r''' |
| 458 _getLibraryText(library), | |
| 459 r''' | |
| 460 library; | 414 library; |
| 461 import self as self; | 415 import self as self; |
| 462 import "dart:core" as core; | 416 import "dart:core" as core; |
| 463 import "package:test/b.dart" as b; | 417 import "package:test/b.dart" as b; |
| 464 | 418 |
| 465 static field core::int a = b::b; | 419 static field core::int a = b::b; |
| 466 '''); | 420 '''); |
| 467 } | 421 } |
| 468 | 422 |
| 469 // Update b.dart and use file URI to invalidate it. | 423 // Update b.dart and use file URI to invalidate it. |
| 470 // The delta is recomputed even though b.dart is used with the package URI. | 424 // The delta is recomputed even though b.dart is used with the package URI. |
| 471 writeFile('/test/lib/b.dart', 'var b = 1.2;'); | 425 writeFile('/test/lib/b.dart', 'var b = 1.2;'); |
| 472 driver.invalidate(bFileUri); | 426 driver.invalidate(bFileUri); |
| 473 { | 427 { |
| 474 KernelResult result = await driver.getKernel(aFileUri); | 428 KernelResult result = await driver.getKernel(aFileUri); |
| 475 _assertLibraryUris(result, includes: [aFileUri, bPackageUri]); | 429 _assertLibraryUris(result, includes: [aFileUri, bPackageUri]); |
| 476 Library library = _getLibrary(result, aFileUri); | 430 Library library = _getLibrary(result, aFileUri); |
| 477 expect( | 431 expect(_getLibraryText(library), r''' |
| 478 _getLibraryText(library), | |
| 479 r''' | |
| 480 library; | 432 library; |
| 481 import self as self; | 433 import self as self; |
| 482 import "dart:core" as core; | 434 import "dart:core" as core; |
| 483 import "package:test/b.dart" as b; | 435 import "package:test/b.dart" as b; |
| 484 | 436 |
| 485 static field core::double a = b::b; | 437 static field core::double a = b::b; |
| 486 '''); | 438 '''); |
| 487 } | 439 } |
| 488 } | 440 } |
| 489 | 441 |
| 490 test_updatePart() async { | 442 test_updatePart() async { |
| 491 writeFile('/test/.packages', 'test:lib/'); | 443 writeFile('/test/.packages', 'test:lib/'); |
| 492 String libPath = '/test/lib/test.dart'; | 444 String libPath = '/test/lib/test.dart'; |
| 493 String partPath = '/test/lib/bar.dart'; | 445 String partPath = '/test/lib/bar.dart'; |
| 494 Uri libUri = writeFile( | 446 Uri libUri = writeFile(libPath, r''' |
| 495 libPath, | |
| 496 r''' | |
| 497 library foo; | 447 library foo; |
| 498 part 'bar.dart'; | 448 part 'bar.dart'; |
| 499 var a = 1; | 449 var a = 1; |
| 500 var c = b; | 450 var c = b; |
| 501 void main() {} | 451 void main() {} |
| 502 '''); | 452 '''); |
| 503 Uri partUri = writeFile( | 453 Uri partUri = writeFile(partPath, r''' |
| 504 partPath, | |
| 505 r''' | |
| 506 part of foo; | 454 part of foo; |
| 507 var b = 2; | 455 var b = 2; |
| 508 var d = a; | 456 var d = a; |
| 509 '''); | 457 '''); |
| 510 | 458 |
| 511 // Check the initial state - types flow between the part and the library. | 459 // Check the initial state - types flow between the part and the library. |
| 512 KernelResult result = await driver.getKernel(libUri); | 460 KernelResult result = await driver.getKernel(libUri); |
| 513 Library library = _getLibrary(result, libUri); | 461 Library library = _getLibrary(result, libUri); |
| 514 expect( | 462 expect(_getLibraryText(library), r''' |
| 515 _getLibraryText(library), | |
| 516 r''' | |
| 517 library foo; | 463 library foo; |
| 518 import self as self; | 464 import self as self; |
| 519 import "dart:core" as core; | 465 import "dart:core" as core; |
| 520 | 466 |
| 521 static field core::int a = 1; | 467 static field core::int a = 1; |
| 522 static field core::int c = self::b; | 468 static field core::int c = self::b; |
| 523 static field core::int b = 2 /* from file:///test/lib/bar.dart */; | 469 static field core::int b = 2 /* from file:///test/lib/bar.dart */; |
| 524 static field core::int d = self::a /* from file:///test/lib/bar.dart */; | 470 static field core::int d = self::a /* from file:///test/lib/bar.dart */; |
| 525 static method main() → void {} | 471 static method main() → void {} |
| 526 '''); | 472 '''); |
| 527 | 473 |
| 528 // Update [b] in the part, the type is changed in the part and library. | 474 // Update [b] in the part, the type is changed in the part and library. |
| 529 { | 475 { |
| 530 writeFile( | 476 writeFile(partPath, r''' |
| 531 partPath, | |
| 532 r''' | |
| 533 part of foo; | 477 part of foo; |
| 534 var b = 2.3; | 478 var b = 2.3; |
| 535 var d = a; | 479 var d = a; |
| 536 '''); | 480 '''); |
| 537 driver.invalidate(partUri); | 481 driver.invalidate(partUri); |
| 538 KernelResult result = await driver.getKernel(libUri); | 482 KernelResult result = await driver.getKernel(libUri); |
| 539 Library library = _getLibrary(result, libUri); | 483 Library library = _getLibrary(result, libUri); |
| 540 expect( | 484 expect(_getLibraryText(library), r''' |
| 541 _getLibraryText(library), | |
| 542 r''' | |
| 543 library foo; | 485 library foo; |
| 544 import self as self; | 486 import self as self; |
| 545 import "dart:core" as core; | 487 import "dart:core" as core; |
| 546 | 488 |
| 547 static field core::int a = 1; | 489 static field core::int a = 1; |
| 548 static field core::double c = self::b; | 490 static field core::double c = self::b; |
| 549 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; | 491 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; |
| 550 static field core::int d = self::a /* from file:///test/lib/bar.dart */; | 492 static field core::int d = self::a /* from file:///test/lib/bar.dart */; |
| 551 static method main() → void {} | 493 static method main() → void {} |
| 552 '''); | 494 '''); |
| 553 } | 495 } |
| 554 | 496 |
| 555 // Update [a] in the library, the type is changed in the part and library. | 497 // Update [a] in the library, the type is changed in the part and library. |
| 556 { | 498 { |
| 557 writeFile( | 499 writeFile(libPath, r''' |
| 558 libPath, | |
| 559 r''' | |
| 560 library foo; | 500 library foo; |
| 561 part 'bar.dart'; | 501 part 'bar.dart'; |
| 562 var a = 'aaa'; | 502 var a = 'aaa'; |
| 563 var c = b; | 503 var c = b; |
| 564 void main() {} | 504 void main() {} |
| 565 '''); | 505 '''); |
| 566 driver.invalidate(libUri); | 506 driver.invalidate(libUri); |
| 567 KernelResult result = await driver.getKernel(libUri); | 507 KernelResult result = await driver.getKernel(libUri); |
| 568 Library library = _getLibrary(result, libUri); | 508 Library library = _getLibrary(result, libUri); |
| 569 expect( | 509 expect(_getLibraryText(library), r''' |
| 570 _getLibraryText(library), | |
| 571 r''' | |
| 572 library foo; | 510 library foo; |
| 573 import self as self; | 511 import self as self; |
| 574 import "dart:core" as core; | 512 import "dart:core" as core; |
| 575 | 513 |
| 576 static field core::String a = "aaa"; | 514 static field core::String a = "aaa"; |
| 577 static field core::double c = self::b; | 515 static field core::double c = self::b; |
| 578 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; | 516 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; |
| 579 static field core::String d = self::a /* from file:///test/lib/bar.dart */; | 517 static field core::String d = self::a /* from file:///test/lib/bar.dart */; |
| 580 static method main() → void {} | 518 static method main() → void {} |
| 581 '''); | 519 '''); |
| 582 } | 520 } |
| 583 } | 521 } |
| 584 | 522 |
| 585 test_watch() async { | 523 test_watch() async { |
| 586 writeFile('/test/.packages', 'test:lib/'); | 524 writeFile('/test/.packages', 'test:lib/'); |
| 587 String aPath = '/test/lib/a.dart'; | 525 String aPath = '/test/lib/a.dart'; |
| 588 String bPath = '/test/lib/b.dart'; | 526 String bPath = '/test/lib/b.dart'; |
| 589 String cPath = '/test/lib/c.dart'; | 527 String cPath = '/test/lib/c.dart'; |
| 590 Uri aUri = writeFile(aPath, ''); | 528 Uri aUri = writeFile(aPath, ''); |
| 591 Uri bUri = writeFile(bPath, ''); | 529 Uri bUri = writeFile(bPath, ''); |
| 592 Uri cUri = writeFile( | 530 Uri cUri = writeFile(cPath, r''' |
| 593 cPath, | |
| 594 r''' | |
| 595 import 'a.dart'; | 531 import 'a.dart'; |
| 596 '''); | 532 '''); |
| 597 | 533 |
| 598 var usedFiles = <Uri>[]; | 534 var usedFiles = <Uri>[]; |
| 599 _createDriver(fileAddedFn: (Uri uri) { | 535 _createDriver(fileAddedFn: (Uri uri) { |
| 600 usedFiles.add(uri); | 536 usedFiles.add(uri); |
| 601 return new Future.value(); | 537 return new Future.value(); |
| 602 }); | 538 }); |
| 603 | 539 |
| 604 { | 540 { |
| 605 await driver.getKernel(cUri); | 541 await driver.getKernel(cUri); |
| 606 // We use at least c.dart and a.dart now. | 542 // We use at least c.dart and a.dart now. |
| 607 expect(usedFiles, contains(cUri)); | 543 expect(usedFiles, contains(cUri)); |
| 608 expect(usedFiles, contains(aUri)); | 544 expect(usedFiles, contains(aUri)); |
| 609 usedFiles.clear(); | 545 usedFiles.clear(); |
| 610 } | 546 } |
| 611 | 547 |
| 612 // Update c.dart to reference also b.dart file. | 548 // Update c.dart to reference also b.dart file. |
| 613 writeFile( | 549 writeFile(cPath, r''' |
| 614 cPath, | |
| 615 r''' | |
| 616 import 'a.dart'; | 550 import 'a.dart'; |
| 617 import 'b.dart'; | 551 import 'b.dart'; |
| 618 '''); | 552 '''); |
| 619 driver.invalidate(cUri); | 553 driver.invalidate(cUri); |
| 620 { | 554 { |
| 621 await driver.getKernel(cUri); | 555 await driver.getKernel(cUri); |
| 622 // The only new file is b.dart now. | 556 // The only new file is b.dart now. |
| 623 expect(usedFiles, [bUri]); | 557 expect(usedFiles, [bUri]); |
| 624 usedFiles.clear(); | 558 usedFiles.clear(); |
| 625 } | 559 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 .writeLibraryFile(library); | 633 .writeLibraryFile(library); |
| 700 return buffer.toString(); | 634 return buffer.toString(); |
| 701 } | 635 } |
| 702 | 636 |
| 703 /// Return the [Uri] for the given Posix [path]. | 637 /// Return the [Uri] for the given Posix [path]. |
| 704 static Uri _folderUri(String path) { | 638 static Uri _folderUri(String path) { |
| 705 if (!path.endsWith('/')) path += '/'; | 639 if (!path.endsWith('/')) path += '/'; |
| 706 return Uri.parse('file://$path'); | 640 return Uri.parse('file://$path'); |
| 707 } | 641 } |
| 708 } | 642 } |
| OLD | NEW |