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 /// And end-to-end test that generates code and checks that the output matches | 5 /// And end-to-end test that generates code and checks that the output matches |
6 /// the code in `static_test.dart`. Techincally we could run the result in an | 6 /// the code in `static_test.dart`. Techincally we could run the result in an |
7 /// isolate, but instead we decided to split that up in two tests. This test | 7 /// isolate, but instead we decided to split that up in two tests. This test |
8 /// ensures that we generate the code as it was written in static_test, and | 8 /// ensures that we generate the code as it was written in static_test, and |
9 /// separately static_test ensures that the smoke.static library behaves as | 9 /// separately static_test ensures that the smoke.static library behaves as |
10 /// expected. | 10 /// expected. |
(...skipping 12 matching lines...) Expand all Loading... |
23 main(args) { | 23 main(args) { |
24 final updateStaticTest = args.length > 0 && args[0] == '--update_static_test'; | 24 final updateStaticTest = args.length > 0 && args[0] == '--update_static_test'; |
25 | 25 |
26 test('static_test is up to date', () { | 26 test('static_test is up to date', () { |
27 var scriptPath = path.fromUri(Platform.script); | 27 var scriptPath = path.fromUri(Platform.script); |
28 var testDir = path.dirname(path.dirname(scriptPath)); | 28 var testDir = path.dirname(path.dirname(scriptPath)); |
29 var commonPath = path.join(testDir, 'common.dart'); | 29 var commonPath = path.join(testDir, 'common.dart'); |
30 var testCode = new File('$commonPath').readAsStringSync(); | 30 var testCode = new File('$commonPath').readAsStringSync(); |
31 var lib = initAnalyzer({'common.dart' : testCode}) | 31 var lib = initAnalyzer({'common.dart' : testCode}) |
32 .libraryFor('common.dart'); | 32 .libraryFor('common.dart'); |
33 var coreLib = lib.visibleLibraries.firstWhere( | |
34 (l) => l.displayName == 'dart.core'); | |
35 var generator = new SmokeCodeGenerator(); | 33 var generator = new SmokeCodeGenerator(); |
36 var recorder = new Recorder(generator, _resolveImportUrl); | 34 var recorder = new Recorder(generator, _resolveImportUrl); |
37 | 35 |
38 lookupMember(String className, String memberName, bool recursive) { | 36 lookupMember(String className, String memberName, bool recursive) { |
39 recorder.lookupMember(lib.getType(className), memberName, | 37 recorder.lookupMember(lib.getType(className), memberName, |
40 recursive: recursive, includeAccessors: false); | 38 recursive: recursive, includeAccessors: false); |
41 } | 39 } |
42 | 40 |
43 runQuery(String className, QueryOptions options) { | 41 runQuery(String className, QueryOptions options) { |
44 recorder.runQuery(lib.getType(className), options, | 42 recorder.runQuery(lib.getType(className), options, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ..writeln(' common.main();') | 144 ..writeln(' common.main();') |
147 ..writeln('}'); | 145 ..writeln('}'); |
148 return sb.toString(); | 146 return sb.toString(); |
149 } | 147 } |
150 | 148 |
151 _resolveImportUrl(LibraryElement lib) { | 149 _resolveImportUrl(LibraryElement lib) { |
152 if (lib.isDartCore) return 'dart:core'; | 150 if (lib.isDartCore) return 'dart:core'; |
153 if (lib.displayName == 'smoke.test.common') return 'common.dart'; | 151 if (lib.displayName == 'smoke.test.common') return 'common.dart'; |
154 return 'unknown.dart'; | 152 return 'unknown.dart'; |
155 } | 153 } |
OLD | NEW |