test_process 1.0.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 94

A package for testing subprocesses.

This exposes a TestProcess class that wraps dart:io's Process class and makes it easy to read standard output line-by-line. TestProcess works the same as Process in many ways, but there are a few major differences.

Standard Output

Process.stdout and Process.stderr are binary streams, which is the most general API but isn't the most helpful when working with a program that produces plain text. Instead, TestProcess.stdout and TestProcess.stderr emit a string for each line of output the process produces. What's more, they're StreamQueues, which means they provide a pull-based API. For example:

import 'package:test/test.dart';
import 'package:test_process/test_process.dart';

void main() {
  test("pub get gets dependencies", () async {
    // TestProcess.start() works just like Process.start() from dart:io.
    var process = await TestProcess.start("pub", ["get"]);

    // StreamQueue.next returns the next line emitted on standard out.
    var firstLine = await process.stdout.next;
    expect(firstLine, equals("Resolving dependencies..."));

    // Each call to StreamQueue.next moves one line further.
    String next;
    do {
      next = await process.stdout.next;
    } while (next != "Got dependencies!");

    // Assert that the process exits with code 0.
    await process.shouldExit(0);
  });
}

The test package's stream matchers have built-in support for StreamQueues, which makes them perfect for making assertions about a process's output. We can use this to clean up the previous example:

import 'package:test/test.dart';
import 'package:test_process/test_process.dart';

void main() {
  test("pub get gets dependencies", () async {
    var process = await TestProcess.start("pub", ["get"]);

    // Each stream matcher will consume as many lines as it matches from a
    // StreamQueue, and no more, so it's safe to use them in sequence.
    await expectLater(process.stdout, emits("Resolving dependencies..."));

    // The emitsThrough matcher matches and consumes any number of lines, as
    // long as they end with one matching the argument.
    await expectLater(process.stdout, emitsThrough("Got dependencies!"));

    await process.shouldExit(0);
  });
}

If you want to access the standard output streams without consuming any values from the queues, you can use the stdoutStream() and stderrStream() methods. Each time you call one of these, it produces an entirely new stream that replays the corresponding output stream from the beginning, regardless of what's already been produced by stdout, stderr, or other calls to the stream method.

Signals and Termination

The way signaling works is different from dart:io as well. TestProcess still has a kill() method, but it defaults to SIGKILL on Mac OS and Linux to ensure (as best as possible) that processes die without leaving behind zombies. If you want to send a particular signal (which is unsupported on Windows), you can do so by explicitly calling signal().

In addition to exitCode, which works the same as in dart:io, TestProcess also adds a new method named shouldExit(). This lets tests wait for a process to exit, and (if desired) assert what particular exit code it produced.

Debugging Output

When a test using TestProcess fails, it will print all the output produced by that process. This makes it much easier to figure out what went wrong and why. The debugging output uses a header based on the process's invocation by default, but you can pass in custom description parameters to TestProcess.start() to control the headers.

TestProcess will also produce debugging output as the test runs if you pass forwardStdio: true to TestProcess.start(). This can be particularly useful when you're using an interactive debugger and you want to figure out what a process is doing before the test finishes and the normal debugging output is printed.

1.0.3

  • Support test 1.x.x.

1.0.2

  • Update SDK version to 2.0.0-dev.17.0

1.0.1

  • Declare support for async 2.0.0.

1.0.0

  • Added pid and exitCode getters to TestProcess.

1.0.0-rc.2

  • Subclassed TestProcesses now emit log output based on the superclass's standard IO streams rather than the subclass's. This matches the documented behavior.

1.0.0-rc.1

  • Initial release candidate.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  test_process: "^1.0.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:test_process/test_process.dart';
  
Version Uploaded Documentation Archive
1.0.3 Jun 15, 2018 Go to the documentation of test_process 1.0.3 Download test_process 1.0.3 archive
1.0.2 Jun 1, 2018 Go to the documentation of test_process 1.0.2 Download test_process 1.0.2 archive
1.0.1 Sep 22, 2017 Go to the documentation of test_process 1.0.1 Download test_process 1.0.1 archive
1.0.0 Jun 7, 2017 Go to the documentation of test_process 1.0.0 Download test_process 1.0.0 archive
1.0.0-rc.2 Jun 1, 2017 Go to the documentation of test_process 1.0.0-rc.2 Download test_process 1.0.0-rc.2 archive
1.0.0-rc.1 Mar 11, 2017 Go to the documentation of test_process 1.0.0-rc.1 Download test_process 1.0.0-rc.1 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
87 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
94
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

Primary library: package:test_process/test_process.dart with components: io.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use test_process.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <2.0.0
async >=1.12.0 <3.0.0 2.0.7
meta >=0.9.0 <2.0.0 1.1.5
path ^1.0.0 1.6.1
test >=0.12.19 <2.0.0 1.0.0
Transitive dependencies
analyzer 0.32.1
args 1.4.3
boolean_selector 1.0.3
charcode 1.1.1
collection 1.14.10
convert 2.0.1
crypto 2.0.5
csslib 0.14.4
front_end 0.1.1
glob 1.1.5
html 0.13.3+1
http 0.11.3+16
http_multi_server 2.0.5
http_parser 3.1.2
io 0.3.2+1
js 0.6.1
json_rpc_2 2.0.8
kernel 0.3.1
logging 0.11.3+1
matcher 0.12.3
mime 0.9.6+1
multi_server_socket 1.0.1
node_preamble 1.4.2
package_config 1.0.3
package_resolver 1.0.3
plugin 0.2.0+2
pool 1.3.5
pub_semver 1.4.1
shelf 0.7.3+1
shelf_packages_handler 1.0.3
shelf_static 0.2.7+1
shelf_web_socket 0.2.2+2
source_map_stack_trace 1.1.4
source_maps 0.10.5
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.7+1
string_scanner 1.0.2
term_glyph 1.0.0
typed_data 1.1.5
utf 0.9.0+4
vm_service_client 0.2.4+3
watcher 0.9.7+8
web_socket_channel 1.0.8
yaml 2.1.14
Dev dependencies
test_descriptor ^1.0.0