a323c55162
Change-Id: I4d492a63a41880ef8cd69321372a4853825b9efd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426321 Reviewed-by: Liam Appelbe <liama@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Liam Appelbe <liama@google.com>
55 lines
1.8 KiB
Dart
55 lines
1.8 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, stackTrace) {
|
|
Expect.isTrue(error is ProcessException);
|
|
Expect.equals(ENOENT, error.errorCode, error.toString());
|
|
Expect.notEquals(stackTrace.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();
|
|
}
|