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 /// Unittest test of the CPS ir generated by the analyzer2dart compiler. | |
6 | |
7 import 'mock_sdk.dart'; | |
8 import 'package:analyzer/file_system/memory_file_system.dart'; | |
9 import 'package:analyzer/src/generated/element.dart'; | |
10 import 'package:analyzer/src/generated/sdk.dart'; | |
11 import 'package:analyzer/src/generated/source.dart'; | |
12 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart'; | |
13 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; | |
14 import 'package:compiler/src/elements/elements.dart' as dart2js; | |
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 'output_helper.dart'; | |
21 import 'test_helper.dart'; | |
22 import 'sexpr_data.dart'; | |
23 | |
24 main(List<String> args) { | |
25 performTests(TEST_DATA, unittester, checkResult, args); | |
26 } | |
27 | |
28 checkResult(TestSpec result) { | |
29 if (result.skipInAnalyzerFrontend) return; | |
30 String input = result.input.trim(); | |
31 CollectingOutputProvider outputProvider = new CollectingOutputProvider(); | |
32 MemoryResourceProvider provider = new MemoryResourceProvider(); | |
33 DartSdk sdk = new MockSdk(); | |
34 Driver driver = new Driver(provider, sdk, outputProvider); | |
35 String rootFile = '/root.dart'; | |
36 provider.newFile(rootFile, input); | |
37 Source rootSource = driver.setRoot(rootFile); | |
38 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); | |
39 ClosedWorld world = driver.computeWorld(entryPoint); | |
40 ConvertedWorld convertedWorld = convertWorld(world); | |
41 | |
42 void checkOutput(String elementName, | |
43 dart2js.Element element, | |
44 String expectedOutput) { | |
45 RootNode ir = convertedWorld.getIr(element); | |
46 if (expectedOutput == null) { | |
47 expect(ir, isNull, | |
48 reason: "\nInput:\n${result.input}\n" | |
49 "No CPS IR expected for $element"); | |
50 } else { | |
51 expect(ir, isNotNull, | |
52 reason: "\nInput:\n${result.input}\n" | |
53 "No CPS IR for $element"); | |
54 expectedOutput = expectedOutput.trim(); | |
55 String output = ir.accept(new SExpressionStringifier()); | |
56 expect(output, equals(expectedOutput), | |
57 reason: "\nInput:\n${result.input}\n" | |
58 "Expected for '$elementName':\n$expectedOutput\n" | |
59 "Actual for '$elementName':\n$output\n"); | |
60 } | |
61 } | |
62 | |
63 if (result.output is String) { | |
64 checkOutput('main', convertedWorld.mainFunction, result.output); | |
65 } else { | |
66 assert(result.output is Map<String, String>); | |
67 dart2js.LibraryElement mainLibrary = convertedWorld.mainFunction.library; | |
68 result.output.forEach((String elementName, String output) { | |
69 bool found = false; | |
70 List<String> names = <String>[]; | |
71 convertedWorld.resolvedElements.forEach((dart2js.Element element) { | |
72 if (element.library == mainLibrary) { | |
73 String name = element.name; | |
74 if (element.enclosingClass != null) { | |
75 name = '${element.enclosingClass.name}.$name'; | |
76 } | |
77 if (name == elementName) { | |
78 checkOutput(elementName, element, output); | |
79 found = true; | |
80 } | |
81 names.add(name); | |
82 } | |
83 }); | |
84 expect(found, isTrue, reason: "'$elementName' not found in $names."); | |
85 }); | |
86 } | |
87 } | |
88 | |
OLD | NEW |