executableRunner function

String executableRunner(
  1. String executable, {
  2. bool node = false,
})

Returns an executable that can be passed to Process.start and similar APIs along with the arguments returned by executableArgs to run executable, which is the name of the executable as listed in the pubspec (or in pkg.executables).

If node is true, this and executableArgs will run a NodeJS process using the executable compiled by pkg-npm-dev. Otherwise, they'll run a Dart VM process using the executable compiled by pkg-standalone-dev if one exists and running from source otherwise.

For example:

import 'dart:io';

import 'package:cli_pkg/testing.dart' as pkg;
import 'package:test/test.dart';

void main() {
  test("hello-world prints a message", () async {
    var result = await Process.run(
        pkg.executableRunner("hello-world"),
        pkg.executableArgs("hello-world"));
    expect(result.stdout, equals("Hello, world!\n");
  });
}

Note that in practice it's usually easier to use start.

Implementation

String executableRunner(String executable, {bool node = false}) =>
    // We take the [executable] argument because it's likely that we'll need to
    // choose between `dart` and `dartaotrunner` once dart-lang/sdk#39973 is
    // fixed.
    node ? "node" : Platform.executable;