OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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 the command line options of dart2js. |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; |
| 11 |
| 12 import 'package:compiler/compiler_new.dart' as api; |
| 13 import 'package:compiler/src/commandline_options.dart'; |
| 14 import 'package:compiler/src/dart2js.dart' as entry; |
| 15 import 'package:compiler/src/options.dart' show CompilerOptions; |
| 16 |
| 17 main() { |
| 18 asyncTest(() async { |
| 19 await test([], exitCode: 1); |
| 20 await test(['foo.dart']); |
| 21 await test([Flags.resolveOnly, 'foo.dart'], |
| 22 resolveOnly: true, |
| 23 resolutionOutput: Uri.base.resolve('out.data')); |
| 24 await test(['--resolution-input=bar.dart', 'foo.dart'], |
| 25 resolutionInputs: [Uri.base.resolve('bar.dart')]); |
| 26 await test([Flags.resolveOnly, '--resolution-input=bar.dart', 'foo.dart'], |
| 27 resolveOnly: true, |
| 28 resolutionOutput: Uri.base.resolve('out.data'), |
| 29 resolutionInputs: [Uri.base.resolve('bar.dart')]); |
| 30 await test([Flags.resolveOnly, '--resolution-input=out.data', 'foo.dart'], |
| 31 exitCode: 1); |
| 32 }); |
| 33 } |
| 34 |
| 35 Future test(List<String> arguments, |
| 36 {int exitCode, |
| 37 bool resolveOnly: false, |
| 38 Uri resolutionOutput, |
| 39 List<Uri> resolutionInputs}) async { |
| 40 print('--------------------------------------------------------------------'); |
| 41 print('dart2js ${arguments.join(' ')}'); |
| 42 print('--------------------------------------------------------------------'); |
| 43 entry.CompileFunc oldCompileFunc = entry.compileFunc; |
| 44 entry.ExitFunc oldExitFunc = entry.exitFunc; |
| 45 |
| 46 CompilerOptions options; |
| 47 int actualExitCode; |
| 48 entry.compileFunc = (_options, input, diagnostics, output) { |
| 49 options = _options; |
| 50 return new Future<api.CompilationResult>.value( |
| 51 new api.CompilationResult(null)); |
| 52 }; |
| 53 entry.exitFunc = (_exitCode) { |
| 54 actualExitCode = _exitCode; |
| 55 throw 'exited'; |
| 56 }; |
| 57 try { |
| 58 await entry.compilerMain(arguments); |
| 59 } catch (e, s) { |
| 60 Expect.equals('exited', e, "Unexpected exception: $e\n$s"); |
| 61 } |
| 62 Expect.equals(exitCode, actualExitCode, "Unexpected exit code"); |
| 63 if (actualExitCode == null) { |
| 64 Expect.isNotNull(options, "Missing options object"); |
| 65 Expect.equals(resolveOnly, options.resolveOnly, |
| 66 "Unexpected resolveOnly value"); |
| 67 Expect.equals(resolutionOutput, options.resolutionOutput, |
| 68 "Unexpected resolutionOutput value"); |
| 69 if (resolutionInputs == null) { |
| 70 Expect.isNull(options.resolutionInputs, |
| 71 "Unexpected resolutionInputs value"); |
| 72 } else { |
| 73 Expect.listEquals(resolutionInputs, options.resolutionInputs, |
| 74 "Unexpected resolutionInputs value"); |
| 75 } |
| 76 } |
| 77 |
| 78 entry.compileFunc = oldCompileFunc; |
| 79 entry.exitFunc = oldExitFunc; |
| 80 } |
OLD | NEW |