OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 /// Tests for summary reporting. | |
6 library dev_compiler.test.report_test; | |
7 | |
8 import 'package:test/test.dart'; | |
9 | |
10 import 'package:dev_compiler/devc.dart'; | |
11 | |
12 import 'package:dev_compiler/src/analysis_context.dart'; | |
13 import 'package:dev_compiler/src/options.dart'; | |
14 import 'package:dev_compiler/src/report.dart'; | |
15 import 'package:dev_compiler/src/summary.dart'; | |
16 | |
17 import 'testing.dart'; | |
18 | |
19 void main() { | |
20 test('toJson/parse', () { | |
21 var files = { | |
22 '/main.dart': ''' | |
23 import 'package:foo/bar.dart'; | |
24 | |
25 test1() { | |
26 x = "hi"; | |
27 } | |
28 ''' | |
29 .replaceAll('\n ', '\n'), | |
30 'package:foo/bar.dart': ''' | |
31 List x; | |
32 test2() { | |
33 List<String> y = x; | |
34 } | |
35 ''' | |
36 .replaceAll('\n ', '\n'), | |
37 }; | |
38 | |
39 var provider = createTestResourceProvider(files); | |
40 var uriResolver = new TestUriResolver(provider); | |
41 var srcOpts = new SourceResolverOptions(useMockSdk: true); | |
42 var context = | |
43 createAnalysisContextWithSources(srcOpts, fileResolvers: [uriResolver]); | |
44 var reporter = new SummaryReporter(context); | |
45 new BatchCompiler(context, new CompilerOptions(sourceOptions: srcOpts), | |
46 reporter: reporter) | |
47 .compileFromUriString('/main.dart'); | |
48 | |
49 _verifySummary(GlobalSummary summary) { | |
50 var mainLib = summary.loose['file:///main.dart']; | |
51 expect(mainLib.messages.length, 2); | |
52 var analyzerMsg = mainLib.messages[0]; | |
53 expect(analyzerMsg.kind, "AnalyzerMessage"); | |
54 | |
55 var mainMessage = mainLib.messages[1]; | |
56 expect(mainMessage.kind, "STATIC_TYPE_ERROR"); | |
57 expect(mainMessage.level, "error"); | |
58 expect(mainMessage.span.text, '"hi"'); | |
59 expect(mainMessage.span.context, ' x = "hi";\n'); | |
60 | |
61 var barLib = summary.packages['foo'].libraries['package:foo/bar.dart']; | |
62 expect(barLib.messages.length, 1); | |
63 var barMessage = barLib.messages[0]; | |
64 expect(barMessage.kind, "DOWN_CAST_COMPOSITE"); | |
65 expect(barMessage.level, "warning"); | |
66 expect(barMessage.span.text, 'x'); | |
67 expect(barMessage.span.context, ' List<String> y = x;\n'); | |
68 } | |
69 | |
70 var original = reporter.result; | |
71 _verifySummary(original); | |
72 _verifySummary(GlobalSummary.parse(original.toJsonMap())); | |
73 }); | |
74 } | |
OLD | NEW |