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 // Test that options '--source-map' and '--out' correctly adds | 5 // Test that options '--source-map' and '--out' correctly adds |
6 // `sourceMappingURL` and "file" attributes to source file and source map file. | 6 // `sourceMappingURL` and "file" attributes to source file and source map file. |
7 | 7 |
8 library test.source_map; | 8 library test.source_map; |
9 | 9 |
10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
13 | 13 |
14 const SOURCE = const { | 14 const SOURCE = const { |
15 '/main.dart': """ | 15 '/main.dart': """ |
16 main() {} | 16 main() {} |
17 """, | 17 """, |
18 }; | 18 }; |
19 | 19 |
20 void find(String text, String substring, bool expected) { | 20 void find(String text, String substring, bool expected) { |
21 bool found = text.contains(substring); | 21 bool found = text.contains(substring); |
22 | 22 |
23 if (expected && !found) { | 23 if (expected && !found) { |
24 Expect.isTrue(found, 'Expected "$substring" in:\n$text'); | 24 Expect.isTrue(found, 'Expected "$substring" in:\n$text'); |
25 } | 25 } |
26 if (!expected && found) { | 26 if (!expected && found) { |
27 Expect.isFalse(found, | 27 Expect.isFalse( |
| 28 found, |
28 'Unexpected "$substring" in:\n' | 29 'Unexpected "$substring" in:\n' |
29 '${text.substring(text.indexOf(substring))}'); | 30 '${text.substring(text.indexOf(substring))}'); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 test({String out, String sourceMap, String mapping, String file}) async { | 34 test({String out, String sourceMap, String mapping, String file}) async { |
34 OutputCollector collector = new OutputCollector(); | 35 OutputCollector collector = new OutputCollector(); |
35 List<String> options = <String>[]; | 36 List<String> options = <String>[]; |
36 if (out != null) { | 37 if (out != null) { |
37 options.add("--out=$out"); | 38 options.add("--out=$out"); |
(...skipping 22 matching lines...) Expand all Loading... |
60 } else { | 61 } else { |
61 find(jsSourceMapOutput, '"file": ', false); | 62 find(jsSourceMapOutput, '"file": ', false); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 void main() { | 66 void main() { |
66 asyncTest(() async { | 67 asyncTest(() async { |
67 await test(); | 68 await test(); |
68 await test(sourceMap: 'file:/out.js.map'); | 69 await test(sourceMap: 'file:/out.js.map'); |
69 await test(out: 'file:/out.js'); | 70 await test(out: 'file:/out.js'); |
70 await test(out: 'file:/out.js', sourceMap: 'file:/out.js.map', | 71 await test( |
71 file: 'out.js', mapping: 'out.js.map'); | 72 out: 'file:/out.js', |
72 await test(out: 'file:/dir/out.js', sourceMap: 'file:/dir/out.js.map', | 73 sourceMap: 'file:/out.js.map', |
73 file: 'out.js', mapping: 'out.js.map'); | 74 file: 'out.js', |
| 75 mapping: 'out.js.map'); |
| 76 await test( |
| 77 out: 'file:/dir/out.js', |
| 78 sourceMap: 'file:/dir/out.js.map', |
| 79 file: 'out.js', |
| 80 mapping: 'out.js.map'); |
74 }); | 81 }); |
75 } | 82 } |
OLD | NEW |