| OLD | NEW | 
|---|
| 1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file | 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 | 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 // Test that the helper [Compiler.inUserCode] works as intended. | 5 // Test that the helper [Compiler.inUserCode] works as intended. | 
| 6 | 6 | 
| 7 import 'dart:async'; | 7 import 'dart:async'; | 
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; | 
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; | 
| 10 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; | 
| 11 import 'package:compiler/src/compiler.dart' show Compiler; | 11 import 'package:compiler/src/compiler.dart' show Compiler; | 
| 12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; | 
| 13 | 13 | 
| 14 const SOURCE = const { | 14 const SOURCE = const { | 
| 15   'main.dart': """ | 15   'main.dart': """ | 
| 16 library main; | 16 library main; | 
| 17 | 17 | 
| 18 import 'dart:async'; | 18 import 'dart:async'; | 
| 19 import 'foo.dart'; | 19 import 'foo.dart'; | 
| 20 import 'pkg/sub/bar.dart'; | 20 import 'pkg/sub/bar.dart'; | 
| 21 import 'package:sub/bar.dart'; | 21 import 'package:sub/bar.dart'; | 
| 22 import 'package:sup/boz.dart'; | 22 import 'package:sup/boz.dart'; | 
| 23 | 23 | 
| 24 main() {} | 24 main() {} | 
| 25 """, | 25 """, | 
| 26 |  | 
| 27   'foo.dart': """ | 26   'foo.dart': """ | 
| 28 library foo; | 27 library foo; | 
| 29 """, | 28 """, | 
| 30 |  | 
| 31   'pkg/sub/bar.dart': """ | 29   'pkg/sub/bar.dart': """ | 
| 32 library sub.bar; | 30 library sub.bar; | 
| 33 | 31 | 
| 34 import 'package:sup/boz.dart'; | 32 import 'package:sup/boz.dart'; | 
| 35 import 'baz.dart'; | 33 import 'baz.dart'; | 
| 36 """, | 34 """, | 
| 37 |  | 
| 38   'pkg/sub/baz.dart': """ | 35   'pkg/sub/baz.dart': """ | 
| 39 library sub.baz; | 36 library sub.baz; | 
| 40 """, | 37 """, | 
| 41 |  | 
| 42   'pkg/sup/boz.dart': """ | 38   'pkg/sup/boz.dart': """ | 
| 43 library sup.boz; | 39 library sup.boz; | 
| 44 """, | 40 """, | 
| 45 }; | 41 }; | 
| 46 | 42 | 
| 47 Future test(List<Uri> entryPoints, Map<String, bool> expectedResults) async { | 43 Future test(List<Uri> entryPoints, Map<String, bool> expectedResults) async { | 
| 48   CompilationResult result = await runCompiler( | 44   CompilationResult result = await runCompiler( | 
| 49     entryPoints: entryPoints, | 45       entryPoints: entryPoints, | 
| 50     memorySourceFiles: SOURCE, | 46       memorySourceFiles: SOURCE, | 
| 51     options: [Flags.analyzeOnly, Flags.analyzeAll], | 47       options: [Flags.analyzeOnly, Flags.analyzeAll], | 
| 52     packageRoot: Uri.parse('memory:pkg/')); | 48       packageRoot: Uri.parse('memory:pkg/')); | 
| 53   Compiler compiler = result.compiler; | 49   Compiler compiler = result.compiler; | 
| 54   expectedResults.forEach((String uri, bool expectedResult) { | 50   expectedResults.forEach((String uri, bool expectedResult) { | 
| 55     var element = compiler.libraryLoader.lookupLibrary(Uri.parse(uri)); | 51     var element = compiler.libraryLoader.lookupLibrary(Uri.parse(uri)); | 
| 56     Expect.isNotNull(element, "Unknown library '$uri'."); | 52     Expect.isNotNull(element, "Unknown library '$uri'."); | 
| 57     Expect.equals(expectedResult, compiler.inUserCode(element), | 53     Expect.equals( | 
| 58         expectedResult ? "Library '$uri' expected to be in user code" | 54         expectedResult, | 
| 59                        : "Library '$uri' not expected to be in user code"); | 55         compiler.inUserCode(element), | 
|  | 56         expectedResult | 
|  | 57             ? "Library '$uri' expected to be in user code" | 
|  | 58             : "Library '$uri' not expected to be in user code"); | 
| 60   }); | 59   }); | 
| 61 } | 60 } | 
| 62 | 61 | 
| 63 void main() { | 62 void main() { | 
| 64   asyncTest(runTests); | 63   asyncTest(runTests); | 
| 65 } | 64 } | 
| 66 | 65 | 
| 67 Future runTests() async { | 66 Future runTests() async { | 
|  | 67   await test([ | 
|  | 68     Uri.parse('memory:main.dart') | 
|  | 69   ], { | 
|  | 70     'memory:main.dart': true, | 
|  | 71     'memory:foo.dart': true, | 
|  | 72     'memory:pkg/sub/bar.dart': true, | 
|  | 73     'memory:pkg/sub/baz.dart': true, | 
|  | 74     'package:sub/bar.dart': false, | 
|  | 75     'package:sub/baz.dart': false, | 
|  | 76     'package:sup/boz.dart': false, | 
|  | 77     'dart:core': false, | 
|  | 78     'dart:async': false | 
|  | 79   }); | 
| 68   await test( | 80   await test( | 
| 69       [Uri.parse('memory:main.dart')], | 81       [Uri.parse('dart:async')], {'dart:core': true, 'dart:async': true}); | 
| 70       {'memory:main.dart': true, | 82   await test([ | 
| 71        'memory:foo.dart': true, | 83     Uri.parse('package:sub/bar.dart') | 
| 72        'memory:pkg/sub/bar.dart': true, | 84   ], { | 
| 73        'memory:pkg/sub/baz.dart': true, | 85     'package:sub/bar.dart': true, | 
| 74        'package:sub/bar.dart': false, | 86     'package:sub/baz.dart': true, | 
| 75        'package:sub/baz.dart': false, | 87     'package:sup/boz.dart': false, | 
| 76        'package:sup/boz.dart': false, | 88     'dart:core': false | 
| 77        'dart:core': false, | 89   }); | 
| 78        'dart:async': false}); | 90   await test([ | 
| 79   await test( | 91     Uri.parse('package:sub/bar.dart'), | 
| 80       [Uri.parse('dart:async')], | 92     Uri.parse('package:sup/boz.dart') | 
| 81       {'dart:core': true, | 93   ], { | 
| 82        'dart:async': true}); | 94     'package:sub/bar.dart': true, | 
| 83   await test( | 95     'package:sub/baz.dart': true, | 
| 84       [Uri.parse('package:sub/bar.dart')], | 96     'package:sup/boz.dart': true, | 
| 85       {'package:sub/bar.dart': true, | 97     'dart:core': false | 
| 86        'package:sub/baz.dart': true, | 98   }); | 
| 87        'package:sup/boz.dart': false, | 99   await test([ | 
| 88        'dart:core': false}); | 100     Uri.parse('dart:async'), | 
| 89   await test( | 101     Uri.parse('package:sub/bar.dart') | 
| 90       [Uri.parse('package:sub/bar.dart'), Uri.parse('package:sup/boz.dart')], | 102   ], { | 
| 91       {'package:sub/bar.dart': true, | 103     'package:sub/bar.dart': true, | 
| 92        'package:sub/baz.dart': true, | 104     'package:sub/baz.dart': true, | 
| 93        'package:sup/boz.dart': true, | 105     'package:sup/boz.dart': false, | 
| 94        'dart:core': false}); | 106     'dart:core': true, | 
| 95   await test( | 107     'dart:async': true | 
| 96       [Uri.parse('dart:async'), Uri.parse('package:sub/bar.dart')], | 108   }); | 
| 97       {'package:sub/bar.dart': true, |  | 
| 98        'package:sub/baz.dart': true, |  | 
| 99        'package:sup/boz.dart': false, |  | 
| 100        'dart:core': true, |  | 
| 101        'dart:async': true}); |  | 
| 102 } | 109 } | 
| 103 |  | 
| OLD | NEW | 
|---|