| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:async' show | 5 import 'dart:async' show |
| 6 Future; | 6 Future; |
| 7 | 7 |
| 8 import 'dart:io' show | 8 import 'dart:io' show |
| 9 Process, | 9 Process, |
| 10 ProcessResult; | 10 ProcessResult; |
| 11 | 11 |
| 12 import 'package:expect/expect.dart' show | 12 import 'package:expect/expect.dart' show |
| 13 Expect; | 13 Expect; |
| 14 | 14 |
| 15 import 'interactive_debugger_tests.dart' as | 15 import 'interactive_debugger_tests.dart' as |
| 16 interactiveDebuggerTests; | 16 interactiveDebuggerTests; |
| 17 | 17 |
| 18 import 'package:fletchc/src/hub/exit_codes.dart' show | 18 import 'package:dartino_compiler/src/hub/exit_codes.dart' show |
| 19 DART_VM_EXITCODE_COMPILE_TIME_ERROR; | 19 DART_VM_EXITCODE_COMPILE_TIME_ERROR; |
| 20 | 20 |
| 21 /// Absolute path to the build directory used by test.py. | 21 /// Absolute path to the build directory used by test.py. |
| 22 const String buildDirectory = | 22 const String buildDirectory = |
| 23 const String.fromEnvironment('test.dart.build-dir'); | 23 const String.fromEnvironment('test.dart.build-dir'); |
| 24 | 24 |
| 25 /// Absolute path to the fletch executable. | 25 /// Absolute path to the dartino executable. |
| 26 final Uri fletchBinary = Uri.base.resolve("$buildDirectory/fletch"); | 26 final Uri dartinoBinary = Uri.base.resolve("$buildDirectory/dartino"); |
| 27 | 27 |
| 28 final Uri thisDirectory = new Uri.directory("tests/cli_tests"); | 28 final Uri thisDirectory = new Uri.directory("tests/cli_tests"); |
| 29 | 29 |
| 30 final List<CliTest> CLI_TESTS = <CliTest>[] | 30 final List<CliTest> CLI_TESTS = <CliTest>[] |
| 31 ..addAll(interactiveDebuggerTests.tests) | 31 ..addAll(interactiveDebuggerTests.tests) |
| 32 ..add(new NoSuchFile()); | 32 ..add(new NoSuchFile()); |
| 33 | 33 |
| 34 abstract class CliTest { | 34 abstract class CliTest { |
| 35 final String name; | 35 final String name; |
| 36 String sessionName; | 36 String sessionName; |
| 37 | 37 |
| 38 CliTest(this.name); | 38 CliTest(this.name); |
| 39 | 39 |
| 40 Future<Null> run(); | 40 Future<Null> run(); |
| 41 | 41 |
| 42 bool get sessionCreated => sessionName != null; | 42 bool get sessionCreated => sessionName != null; |
| 43 | 43 |
| 44 Future<ProcessResult> createSession({String workingDirectory}) { | 44 Future<ProcessResult> createSession({String workingDirectory}) { |
| 45 assert(!sessionCreated); | 45 assert(!sessionCreated); |
| 46 sessionName = "clitest-$name-$hashCode"; | 46 sessionName = "clitest-$name-$hashCode"; |
| 47 return Process.run( | 47 return Process.run( |
| 48 fletchBinary.toFilePath(), | 48 dartinoBinary.toFilePath(), |
| 49 ["create", "session", sessionName], | 49 ["create", "session", sessionName], |
| 50 workingDirectory: workingDirectory); | 50 workingDirectory: workingDirectory); |
| 51 } | 51 } |
| 52 | 52 |
| 53 Future<Process> fletch(List<String> arguments, | 53 Future<Process> dartino(List<String> arguments, |
| 54 {String workingDirectory}) async { | 54 {String workingDirectory}) async { |
| 55 if (!sessionCreated) { | 55 if (!sessionCreated) { |
| 56 ProcessResult result = await createSession(); | 56 ProcessResult result = await createSession(); |
| 57 Expect.equals(0, result.exitCode); | 57 Expect.equals(0, result.exitCode); |
| 58 } | 58 } |
| 59 return Process.start(fletchBinary.toFilePath(), inSession(arguments), | 59 return Process.start(dartinoBinary.toFilePath(), inSession(arguments), |
| 60 workingDirectory: workingDirectory); | 60 workingDirectory: workingDirectory); |
| 61 } | 61 } |
| 62 | 62 |
| 63 Iterable<String> inSession(List<String> arguments) { | 63 Iterable<String> inSession(List<String> arguments) { |
| 64 return arguments..addAll(["in", "session", sessionName]); | 64 return arguments..addAll(["in", "session", sessionName]); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 class NoSuchFile extends CliTest { | 68 class NoSuchFile extends CliTest { |
| 69 NoSuchFile() | 69 NoSuchFile() |
| 70 : super("no_such_file"); | 70 : super("no_such_file"); |
| 71 | 71 |
| 72 Future<Null> run() async { | 72 Future<Null> run() async { |
| 73 Process process = await fletch(["run", "no-such-file.dart"]); | 73 Process process = await dartino(["run", "no-such-file.dart"]); |
| 74 process.stdin.close(); | 74 process.stdin.close(); |
| 75 Future outClosed = process.stdout.listen(null).asFuture(); | 75 Future outClosed = process.stdout.listen(null).asFuture(); |
| 76 await process.stderr.listen(null).asFuture(); | 76 await process.stderr.listen(null).asFuture(); |
| 77 await outClosed; | 77 await outClosed; |
| 78 Expect.equals(DART_VM_EXITCODE_COMPILE_TIME_ERROR, await process.exitCode); | 78 Expect.equals(DART_VM_EXITCODE_COMPILE_TIME_ERROR, await process.exitCode); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Test entry point. | 82 // Test entry point. |
| 83 | 83 |
| 84 typedef Future NoArgFuture(); | 84 typedef Future NoArgFuture(); |
| 85 | 85 |
| 86 Future<Map<String, NoArgFuture>> listTests() async { | 86 Future<Map<String, NoArgFuture>> listTests() async { |
| 87 var tests = <String, NoArgFuture>{}; | 87 var tests = <String, NoArgFuture>{}; |
| 88 for (CliTest test in CLI_TESTS) { | 88 for (CliTest test in CLI_TESTS) { |
| 89 tests["cli_tests/${test.name}"] = () => test.run(); | 89 tests["cli_tests/${test.name}"] = () => test.run(); |
| 90 } | 90 } |
| 91 return tests; | 91 return tests; |
| 92 } | 92 } |
| OLD | NEW |