Chromium Code Reviews| 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 /// End-to-end test of the analyzer2dart compiler. | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'mock_sdk.dart'; | |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | |
| 11 import 'package:analyzer/src/generated/element.dart'; | |
| 12 import 'package:analyzer/src/generated/sdk.dart'; | |
| 13 import 'package:analyzer/src/generated/source.dart'; | |
| 14 import 'package:compiler/implementation/dart_backend/backend_ast_to_frontend_ast .dart'; | |
| 15 import 'package:unittest/unittest.dart'; | |
| 16 | |
| 17 import '../lib/src/closed_world.dart'; | |
| 18 import '../lib/src/driver.dart'; | |
| 19 import '../lib/src/converted_world.dart'; | |
| 20 import '../lib/src/dart_backend.dart'; | |
| 21 | |
| 22 main() { | |
| 23 test('Empty main', () { | |
| 24 String expectedResult = ''' | |
| 25 main() $NEW_BACKEND_COMMENT | |
| 26 {} | |
| 27 | |
| 28 '''; | |
| 29 checkResult(''' | |
| 30 main() {}''', | |
| 31 expectedResult); | |
| 32 | |
| 33 checkResult(''' | |
| 34 main() {} | |
| 35 foo() {}''', | |
| 36 expectedResult); | |
| 37 }); | |
| 38 | |
| 39 test('Simple call-chains', () { | |
| 40 checkResult(''' | |
| 41 foo() {} | |
| 42 main() { | |
| 43 foo(); | |
| 44 } | |
| 45 ''', ''' | |
| 46 foo() $NEW_BACKEND_COMMENT | |
| 47 {} | |
| 48 | |
| 49 main() $NEW_BACKEND_COMMENT | |
| 50 { | |
| 51 foo(); | |
| 52 } | |
| 53 | |
| 54 '''); | |
| 55 | |
| 56 checkResult(''' | |
| 57 bar() {} | |
| 58 foo() { | |
| 59 bar(); | |
| 60 } | |
| 61 main() { | |
| 62 foo(); | |
| 63 } | |
| 64 ''', ''' | |
| 65 bar() $NEW_BACKEND_COMMENT | |
| 66 {} | |
| 67 | |
| 68 foo() $NEW_BACKEND_COMMENT | |
| 69 { | |
| 70 bar(); | |
| 71 } | |
| 72 | |
| 73 main() $NEW_BACKEND_COMMENT | |
| 74 { | |
| 75 foo(); | |
| 76 } | |
| 77 | |
| 78 '''); | |
| 79 | |
| 80 checkResult(''' | |
| 81 bar() { | |
| 82 main(); | |
| 83 } | |
| 84 foo() { | |
| 85 bar(); | |
| 86 } | |
| 87 main() { | |
| 88 foo(); | |
| 89 } | |
| 90 ''', ''' | |
| 91 bar() $NEW_BACKEND_COMMENT | |
| 92 { | |
| 93 main(); | |
| 94 } | |
| 95 | |
| 96 foo() $NEW_BACKEND_COMMENT | |
| 97 { | |
| 98 bar(); | |
| 99 } | |
| 100 | |
| 101 main() $NEW_BACKEND_COMMENT | |
| 102 { | |
| 103 foo(); | |
| 104 } | |
| 105 | |
| 106 '''); | |
| 107 }); | |
| 108 } | |
| 109 | |
| 110 checkResult(String input, String expectedOutput) { | |
| 111 CollectingOutputProvider outputProvider = new CollectingOutputProvider(); | |
| 112 MemoryResourceProvider provider = new MemoryResourceProvider(); | |
| 113 DartSdk sdk = new MockSdk(); | |
| 114 Driver driver = new Driver(provider, sdk, outputProvider); | |
| 115 String rootFile = '/root.dart'; | |
| 116 provider.newFile(rootFile, input); | |
| 117 Source rootSource = driver.setRoot(rootFile); | |
| 118 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); | |
| 119 ClosedWorld world = driver.computeWorld(entryPoint); | |
| 120 ConvertedWorld convertedWorld = convertWorld(world); | |
| 121 compileToDart(driver, convertedWorld); | |
| 122 String output = outputProvider.output.text; | |
| 123 print('input:\n$input'); | |
|
sigurdm
2014/09/08 14:07:15
Debugging prints?
Johnni Winther
2014/09/09 14:21:26
Removed.
| |
| 124 print('output:\n$output'); | |
| 125 print('expectedOutput:\n$expectedOutput'); | |
| 126 expect(output, equals(expectedOutput)); | |
| 127 } | |
| 128 | |
| 129 class CollectingOutputProvider { | |
| 130 StringBufferSink output; | |
| 131 | |
| 132 EventSink<String> call(String name, String extension) { | |
| 133 print('outputProvider($name,$extension)'); | |
| 134 return output = new StringBufferSink(); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 class StringBufferSink implements EventSink<String> { | |
| 139 StringBuffer sb = new StringBuffer(); | |
| 140 | |
| 141 void add(String text) { | |
| 142 sb.write(text); | |
| 143 } | |
| 144 | |
| 145 void addError(errorEvent, [StackTrace stackTrace]) {} | |
| 146 | |
| 147 void close() {} | |
| 148 | |
| 149 String get text => sb.toString(); | |
| 150 } | |
| 151 | |
| OLD | NEW |