| 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 that the debugging helper [Compiler.inUserCode] works as intended. |
| 6 |
| 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:expect/expect.dart'; |
| 9 |
| 10 import 'memory_compiler.dart'; |
| 11 |
| 12 const SOURCE = const { |
| 13 'main.dart': """ |
| 14 library main; |
| 15 |
| 16 import 'dart:async'; |
| 17 import 'foo.dart'; |
| 18 import 'pkg/sub/bar.dart'; |
| 19 import 'package:sub/bar.dart'; |
| 20 import 'package:sup/boz.dart'; |
| 21 |
| 22 main() {} |
| 23 """, |
| 24 |
| 25 'foo.dart': """ |
| 26 library foo; |
| 27 """, |
| 28 |
| 29 'pkg/sub/bar.dart': """ |
| 30 library sub.bar; |
| 31 |
| 32 import 'package:sup/boz.dart'; |
| 33 import 'baz.dart'; |
| 34 """, |
| 35 |
| 36 'pkg/sub/baz.dart': """ |
| 37 library sub.baz; |
| 38 """, |
| 39 |
| 40 'pkg/sup/boz.dart': """ |
| 41 library sup.boz; |
| 42 """, |
| 43 }; |
| 44 |
| 45 void test(List<Uri> entryPoints, Map<String, bool> expectedResults) { |
| 46 var compiler = compilerFor(SOURCE, |
| 47 options: ['--analyze-only', '--analyze-all'], |
| 48 packageRoot: Uri.parse('memory:pkg/')); |
| 49 Uri mainUri = null; |
| 50 if (entryPoints.length == 1) { |
| 51 mainUri = entryPoints[0]; |
| 52 } else { |
| 53 compiler.librariesToAnalyzeWhenRun = entryPoints; |
| 54 } |
| 55 asyncTest(() => compiler.run(mainUri).then((_) { |
| 56 expectedResults.forEach((String uri, bool expectedResult) { |
| 57 var element = compiler.libraries[uri]; |
| 58 Expect.isNotNull(element, "Unknown library '$uri'."); |
| 59 Expect.equals(expectedResult, compiler.inUserCode(element), |
| 60 expectedResult ? "Library '$uri' expected to be in user code" |
| 61 : "Library '$uri' not expected to be in user code"); |
| 62 }); |
| 63 })); |
| 64 } |
| 65 |
| 66 void main() { |
| 67 test([Uri.parse('memory:main.dart')], |
| 68 {'memory:main.dart': true, |
| 69 'memory:foo.dart': true, |
| 70 'memory:pkg/sub/bar.dart': true, |
| 71 'memory:pkg/sub/baz.dart': true, |
| 72 'package:sub/bar.dart': false, |
| 73 'package:sub/baz.dart': false, |
| 74 'package:sup/boz.dart': false, |
| 75 'dart:core': false, |
| 76 'dart:async': false}); |
| 77 test([Uri.parse('dart:async')], |
| 78 {'dart:core': true, |
| 79 'dart:async': true}); |
| 80 test([Uri.parse('package:sub/bar.dart')], |
| 81 {'package:sub/bar.dart': true, |
| 82 'package:sub/baz.dart': true, |
| 83 'package:sup/boz.dart': false, |
| 84 'dart:core': false}); |
| 85 test([Uri.parse('package:sub/bar.dart'), Uri.parse('package:sup/boz.dart')], |
| 86 {'package:sub/bar.dart': true, |
| 87 'package:sub/baz.dart': true, |
| 88 'package:sup/boz.dart': true, |
| 89 'dart:core': false}); |
| 90 test([Uri.parse('dart:async'), Uri.parse('package:sub/bar.dart')], |
| 91 {'package:sub/bar.dart': true, |
| 92 'package:sub/baz.dart': true, |
| 93 'package:sup/boz.dart': false, |
| 94 'dart:core': true, |
| 95 'dart:async': true}); |
| 96 } |
| 97 |
| OLD | NEW |