OLD | NEW |
| (Empty) |
1 // Copyright (c) 2017, 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 we can compile from dill and run the generated code with d8. | |
6 library dart2js.kernel.run_from_dill_test; | |
7 | |
8 import 'dart:async'; | |
9 import 'dart:io'; | |
10 | |
11 import 'package:async_helper/async_helper.dart'; | |
12 import 'package:expect/expect.dart'; | |
13 import 'package:compiler/src/commandline_options.dart'; | |
14 import 'package:compiler/src/dart2js.dart' as dart2js; | |
15 import 'package:compiler/src/filenames.dart'; | |
16 | |
17 import 'compiler_helper.dart'; | |
18 import '../sourcemaps/stacktrace_test.dart'; | |
19 import '../serialization/helper.dart'; | |
20 | |
21 const SOURCE = const { | |
22 'main.dart': ''' | |
23 main() { | |
24 print('Hello World!'); | |
25 } | |
26 ''' | |
27 }; | |
28 | |
29 main(List<String> args) { | |
30 asyncTest(() async { | |
31 await mainInternal(args); | |
32 }); | |
33 } | |
34 | |
35 enum ResultKind { crashes, errors, warnings, success, failure } | |
36 | |
37 Future<ResultKind> mainInternal(List<String> args, | |
38 {bool skipWarnings: false, bool skipErrors: false}) async { | |
39 Arguments arguments = new Arguments.from(args); | |
40 Uri entryPoint; | |
41 Map<String, String> memorySourceFiles; | |
42 if (arguments.uri != null) { | |
43 entryPoint = arguments.uri; | |
44 memorySourceFiles = const <String, String>{}; | |
45 } else { | |
46 entryPoint = Uri.parse('memory:main.dart'); | |
47 memorySourceFiles = SOURCE; | |
48 } | |
49 | |
50 Uri dillFile = | |
51 await createTemp(entryPoint, memorySourceFiles, printSteps: true); | |
52 String output = uriPathToNative(dillFile.resolve('out.js').path); | |
53 List<String> dart2jsArgs = [ | |
54 dillFile.toString(), | |
55 '-o$output', | |
56 Flags.loadFromDill, | |
57 Flags.disableTypeInference, | |
58 Flags.disableInlining, | |
59 Flags.enableAssertMessage | |
60 ]; | |
61 print('Running: dart2js ${dart2jsArgs.join(' ')}'); | |
62 | |
63 await dart2js.internalMain(dart2jsArgs); | |
64 | |
65 print('---- run from dill --------------------------------------------'); | |
66 ProcessResult runResult = Process.runSync(d8executable, | |
67 ['sdk/lib/_internal/js_runtime/lib/preambles/d8.js', output]); | |
68 String out = '${runResult.stderr}\n${runResult.stdout}'; | |
69 print('d8 output:'); | |
70 print(out); | |
71 Expect.equals(0, runResult.exitCode); | |
72 | |
73 return ResultKind.success; | |
74 } | |
OLD | NEW |