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 // Test that options '--source-map' and '--out' correctly adds | |
6 // `sourceMappingURL` and "file" attributes to source file and source map file. | |
7 | |
8 library test.source_map; | |
9 | |
10 import 'package:async_helper/async_helper.dart'; | |
11 import 'package:expect/expect.dart'; | |
12 import 'memory_compiler.dart'; | |
13 | |
14 const SOURCE = const { | |
15 '/main.dart': """ | |
16 main() {} | |
17 """, | |
18 }; | |
19 | |
20 void find(String text, String substring, bool expected) { | |
21 bool found = text.contains(substring); | |
22 | |
23 if (expected && !found) { | |
24 Expect.isTrue(found, 'Expected "$substring" in:\n$text'); | |
25 } | |
26 if (!expected && found) { | |
27 Expect.isFalse(found, | |
28 'Unexpected "$substring" in:\n' | |
29 '${text.substring(text.indexOf(substring))}'); | |
30 } | |
31 } | |
32 | |
33 void test({String out, String sourceMap, String mapping, String file}) { | |
34 OutputCollector collector = new OutputCollector(); | |
35 List<String> options = <String>[]; | |
36 if (out != null) { | |
37 options.add("--out=$out"); | |
38 } | |
39 if (sourceMap != null) { | |
40 options.add("--source-map=$sourceMap"); | |
41 } | |
42 var compiler = compilerFor(SOURCE, | |
43 showDiagnostics: true, | |
44 outputProvider: collector, | |
45 options: options); | |
46 asyncTest(() => compiler.runCompiler(Uri.parse('memory:/main.dart')).then((_) { | |
floitsch
2014/03/07 10:27:24
long line.
Johnni Winther
2014/03/07 12:38:48
Done.
| |
47 String jsOutput = collector.getOutput('', 'js'); | |
48 Expect.isNotNull(jsOutput); | |
49 if (mapping != null) { | |
50 find(jsOutput, '//# sourceMappingURL=$mapping', true); | |
51 find(jsOutput, '//@ sourceMappingURL=$mapping', true); | |
52 } else { | |
53 find(jsOutput, '//# sourceMappingURL=', false); | |
54 find(jsOutput, '//@ sourceMappingURL=', false); | |
55 } | |
56 String jsSourceMapOutput = collector.getOutput('', 'js.map'); | |
57 Expect.isNotNull(jsSourceMapOutput); | |
58 if (file != null) { | |
59 find(jsSourceMapOutput, '"file": "$file"', true); | |
60 } else { | |
61 find(jsSourceMapOutput, '"file": ', false); | |
62 } | |
63 })); | |
64 } | |
65 | |
66 void main() { | |
67 test(); | |
68 test(sourceMap: 'file:/out.js.map'); | |
69 test(out: 'file:/out.js'); | |
70 test(out: 'file:/out.js', sourceMap: 'file:/out.js.map', | |
71 file: 'out.js', mapping: 'out.js.map'); | |
72 test(out: 'file:/dir/out.js', sourceMap: 'file:/dir/out.js.map', | |
73 file: 'out.js', mapping: 'out.js.map'); | |
74 } | |
OLD | NEW |