Files
sdk/tests/standalone_2/io/process_start_exception_test.dart
T
Siva Annamalai bd2a8e1d60 Reland migrate most of the tests in standalone to be strong mode clean and move them to standalone_2 directory.
Bug:
Change-Id: I4ca50f315361422db1d4356055862463bfe1d6f3
Reviewed-on: https://dart-review.googlesource.com/12240
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2017-10-07 01:29:36 +00:00

50 lines
1.7 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// Process test program to errors during startup of the process.
import 'dart:async';
import 'dart:io';
import "package:expect/expect.dart";
// ENOENT and ERROR_FILE_NOT_FOUND on Windows both have the same value.
// Note: we are setting PATH to an empty string in tests below because on
// POSIX systems if target binary name does not contain `/` then it is
// searched through PATH and if it is not found anywhere in the PATH
// but some folder in PATH is inaccessible then underlying execvp(...)
// call will return EACCES (13) instead of ENOENT.
// For example on some Android devices PATH would include /sbin with is
// inaccessible - so this test will fail.
const ENOENT = 2;
testStartError() {
Future<Process> processFuture = Process.start(
"__path_to_something_that_should_not_exist__", const [],
environment: {"PATH": ""});
processFuture
.then((p) => Expect.fail('got process despite start error'))
.catchError((error) {
Expect.isTrue(error is ProcessException);
Expect.equals(ENOENT, error.errorCode, error.toString());
});
}
testRunError() {
Future<ProcessResult> processFuture = Process.run(
"__path_to_something_that_should_not_exist__", const [],
environment: {"PATH": ""});
processFuture
.then((result) => Expect.fail("exit handler called"))
.catchError((error) {
Expect.isTrue(error is ProcessException);
Expect.equals(ENOENT, error.errorCode, error.toString());
});
}
main() {
testStartError();
testRunError();
}