Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge package:test_process #2425

Merged
merged 75 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a8137d1
Add template files.
nex3 Feb 7, 2017
d916bb9
Add the package implementation. (dart-lang/test_process#1)
nex3 Mar 11, 2017
8e4796d
Print superclass rather than subclass logs. (dart-lang/test_process#2)
nex3 Jun 1, 2017
544bbb2
Add pid and exitCode getters.
nex3 Jun 6, 2017
f29cd32
Flesh out the README.
nex3 Jun 6, 2017
a30d160
Update the pubspec and CHANGELOG.
nex3 Jun 6, 2017
67d64c7
Describe this as "a package" and not "a library". (dart-lang/test_pro…
nex3 Jun 7, 2017
47d5b43
Declare support for async 2.0.0 (dart-lang/test_process#6)
nex3 Sep 22, 2017
ef12b6f
Enable travis-ci (dart-lang/test_process#7)
kevmoo Oct 13, 2017
0a054b0
Remove upper case constants (dart-lang/test_process#8)
lrhn May 15, 2018
22f3850
Remove usage of deprecated dart:io constants. (dart-lang/test_process…
lrhn Jun 1, 2018
f2fd830
Support test 1.x.x
grouma Jun 15, 2018
4f1ba65
Merge pull request dart-lang/test_process#12 from dart-lang/update-test
grouma Jun 15, 2018
e6b1227
prepare for release
grouma Jun 15, 2018
db9aa9d
Merge pull request dart-lang/test_process#13 from dart-lang/update-ve…
grouma Jun 15, 2018
495da7a
chore: set max SDK version to <3.0.0 (dart-lang/test_process#14)
chalin Jul 17, 2018
3fab9a8
Fix travis for latest dev SDK (dart-lang/test_process#15)
kevmoo Apr 8, 2019
2abab6f
Fix newly enforce lints and clean pubspec (dart-lang/test_process#16)
natebosch Jan 10, 2020
e23529c
Run the test's heartbeat whenever the process emits output (dart-lang…
nex3 Jan 14, 2020
c7ac71e
Update links to eliminate redirects
kevmoo Mar 13, 2020
aa8375f
Merge pull request dart-lang/test_process#18 from dart-lang/fix_links
grouma Mar 13, 2020
759934c
Remove unused dart:async import
MichaelRFairhurst Sep 25, 2020
3080db8
Merge pull request dart-lang/test_process#19 from MichaelRFairhurst/r…
MichaelRFairhurst Oct 2, 2020
1b8f596
Remove unused dart:async imports
srawlins Nov 21, 2020
13fdbaf
Merge pull request dart-lang/test_process#20 from dart-lang/srawlins-…
srawlins Nov 23, 2020
240590e
Migrate to GitHub Actions (dart-lang/test_process#22)
athomas Jan 20, 2021
2171422
Migrate to null safety (dart-lang/test_process#23)
GaspardMerten Feb 11, 2021
85e2d47
Prepare to publish (dart-lang/test_process#24)
natebosch Feb 17, 2021
0009318
Fix formatting (dart-lang/test_process#25)
kevmoo Mar 21, 2021
db948fa
Update LICENSE
franklinyow Apr 1, 2021
a696daf
Merge pull request dart-lang/test_process#26 from dart-lang/frankliny…
franklinyow Apr 1, 2021
a9c8cc9
Add dependabot
kevmoo Jun 5, 2021
1be472c
Bump dart-lang/setup-dart from 0.3 to 1 (dart-lang/test_process#27)
dependabot[bot] Jun 5, 2021
970bd6b
Update test-package.yml (dart-lang/test_process#28)
kevmoo Jun 5, 2021
f093373
Update 'meta' constraint to '>=1.3.0 <3.0.0'.
scheglov Jul 4, 2021
bafc1e5
Merge pull request dart-lang/test_process#29 from scheglov/meta-2.0.0
scheglov Jul 5, 2021
c18144e
Revert to 'meta: ^1.3.0'.
scheglov Jul 7, 2021
811ac5e
Merge pull request dart-lang/test_process#30 from scheglov/meta-1.3.0
scheglov Jul 7, 2021
46edede
Bump actions/checkout from 2 to 3 (dart-lang/test_process#32)
dependabot[bot] Mar 2, 2022
a0f1aaa
populate the repository field
devoncarew May 3, 2022
956092e
Merge pull request dart-lang/test_process#33 from dart-lang/repositor…
devoncarew May 3, 2022
0f25fbf
Update lints, require latest Dart SDK, prepare to release v2.0.3 (dar…
kevmoo Oct 3, 2022
56019d8
Bump actions/checkout from 3.0.2 to 3.1.0 (dart-lang/test_process#36)
dependabot[bot] Nov 1, 2022
8008c37
Bump actions/checkout from 3.1.0 to 3.2.0 (dart-lang/test_process#37)
dependabot[bot] Jan 3, 2023
574f8fd
Bump dart-lang/setup-dart from 1.3 to 1.4 (dart-lang/test_process#39)
dependabot[bot] Feb 1, 2023
2c8734c
Bump actions/checkout from 3.2.0 to 3.3.0 (dart-lang/test_process#38)
dependabot[bot] Feb 1, 2023
1043384
Bump actions/checkout from 3.3.0 to 3.5.0 (dart-lang/test_process#41)
dependabot[bot] Apr 3, 2023
7ee454f
Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (dart-lang/test_process…
dependabot[bot] Apr 3, 2023
1bc8f84
Bump actions/checkout from 3.5.0 to 3.5.2 (dart-lang/test_process#42)
dependabot[bot] May 1, 2023
504c31e
Remove expectation of process exit in test body (dart-lang/test_proce…
natebosch May 15, 2023
253895b
Prepare to publish (dart-lang/test_process#44)
natebosch May 16, 2023
3be0859
blast_repo fixes (dart-lang/test_process#45)
devoncarew May 22, 2023
c587b26
Bump actions/checkout from 3.5.2 to 3.5.3 (dart-lang/test_process#46)
dependabot[bot] Jul 1, 2023
90885fd
Bump actions/checkout from 3.5.3 to 3.6.0 (dart-lang/test_process#47)
dependabot[bot] Sep 1, 2023
910e11f
Bump actions/checkout from 3.6.0 to 4.1.0 (dart-lang/test_process#49)
dependabot[bot] Oct 1, 2023
ab7c369
Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (dart-lang/test_process…
dependabot[bot] Oct 3, 2023
f4aba70
Bump actions/checkout from 4.1.0 to 4.1.1 (dart-lang/test_process#50)
dependabot[bot] Nov 1, 2023
a23c763
Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (dart-lang/test_process…
dependabot[bot] Nov 1, 2023
09d29ba
Update lints, require Dart ^3.1 (dart-lang/test_process#52)
kevmoo Nov 29, 2023
0ad978b
Bump dart-lang/setup-dart from 1.6.0 to 1.6.2 (dart-lang/test_process…
dependabot[bot] Feb 1, 2024
a631d70
Bump actions/checkout from 4.1.1 to 4.1.2 (dart-lang/test_process#54)
dependabot[bot] Apr 1, 2024
1de697b
Bump actions/checkout from 4.1.2 to 4.1.4 (dart-lang/test_process#56)
dependabot[bot] May 1, 2024
731dff0
Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (dart-lang/test_process…
dependabot[bot] May 1, 2024
868150a
blast_repo fixes (dart-lang/test_process#57)
devoncarew May 10, 2024
f2eb7c3
Bump actions/checkout from 4.1.4 to 4.1.5 in the github-actions group…
dependabot[bot] May 10, 2024
571b067
Bump actions/checkout from 4.1.5 to 4.1.6 in the github-actions group…
dependabot[bot] Jun 1, 2024
e2395fb
update lints (dart-lang/test_process#60)
kevmoo Jun 21, 2024
922e52c
Bump the github-actions group with 2 updates (dart-lang/test_process#61)
dependabot[bot] Jul 1, 2024
bbad41c
Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group…
dependabot[bot] Oct 1, 2024
3a8f6fc
blast_repo fixes (dart-lang/test_process#63)
kevmoo Oct 29, 2024
b30f011
Bump actions/checkout from 4.2.0 to 4.2.2 in the github-actions group…
dependabot[bot] Nov 1, 2024
200097b
Bump dart-lang/setup-dart in the github-actions group (dart-lang/test…
dependabot[bot] Dec 1, 2024
6f9c68d
Merge package:test_process into the test monorepo
mosuem Dec 12, 2024
c62a875
Add issue template and other fixes
mosuem Dec 12, 2024
754d970
Moving fixes
mosuem Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/test_process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:test_process"
about: "Create a bug or file a feature request against package:test_process."
labels: "package:test_process"
---
72 changes: 72 additions & 0 deletions .github/workflows/test_process.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: package:test_process

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ master ]
paths:
- '.github/workflows/test_process.yaml'
- 'pkgs/test_process/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/test_process.yaml'
- 'pkgs/test_process/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github


defaults:
run:
working-directory: pkgs/test_process/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.1, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ literate API.
| [test](pkgs/test/) | A full featured library for writing and running Dart tests across platforms. | [![pub package](https://img.shields.io/pub/v/test.svg)](https://pub.dev/packages/test) |
| [test_api](pkgs/test_api/) | | [![pub package](https://img.shields.io/pub/v/test_api.svg)](https://pub.dev/packages/test_api) |
| [test_core](pkgs/test_core/) | | [![pub package](https://img.shields.io/pub/v/test_core.svg)](https://pub.dev/packages/test_core) |
| [test_process](pkgs/test_process/) | Test processes: starting; validating stdout and stderr; checking exit code | [![pub package](https://img.shields.io/pub/v/test_process.svg)](https://pub.dev/packages/test_process) |
9 changes: 9 additions & 0 deletions pkgs/test_process/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.buildlog
.DS_Store
.idea
.settings/
build/
packages
.packages
pubspec.lock
.dart_tool/
6 changes: 6 additions & 0 deletions pkgs/test_process/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Below is a list of people and organizations that have contributed
# to the project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google Inc.
67 changes: 67 additions & 0 deletions pkgs/test_process/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## 2.1.1

* Require Dart 3.1.
* Move to `dart-lang/test` monorepo.

## 2.1.0

- Remove the expectation that the process exits during the normal test body.
The process will still be killed during teardown if it has not exited. The
check can be manually restored with `shouldExit()`.

## 2.0.3

- Populate the pubspec `repository` field.
- Fixed examples in `readme.md`.
- Added `example/example.dart`
- Require Dart >=2.17

## 2.0.2

- Reverted `meta` constraint to `^1.3.0`.

## 2.0.1

- Update `meta` constraint to `>=1.3.0 <3.0.0`.

## 2.0.0

- Migrate to null safety.

## 1.0.6

- Require Dart >=2.1

## 1.0.5

- Don't allow the test to time out as long as the process is emitting output.

## 1.0.4

- Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 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 `TestProcess`es 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.
27 changes: 27 additions & 0 deletions pkgs/test_process/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2017, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
123 changes: 123 additions & 0 deletions pkgs/test_process/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
[![Build Status](https://github.com/dart-lang/test/actions/workflows/test_process.yaml/badge.svg)](https://github.com/dart-lang/test/actions/workflows/test_process.yaml)
[![pub package](https://img.shields.io/pub/v/test_process.svg)](https://pub.dev/packages/test_process)
[![package publisher](https://img.shields.io/pub/publisher/test_process.svg)](https://pub.dev/packages/test_process/publisher)

A package for testing subprocesses.

This exposes a [`TestProcess`][TestProcess] class that wraps `dart:io`'s
[`Process`][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.

[TestProcess]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess-class.html
[Process]: https://api.dart.dev/stable/dart-io/Process-class.html

## 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`][stdout] and
[`TestProcess.stderr`][stderr] emit a string for each line of output the process
produces. What's more, they're [`StreamQueue`][StreamQueue]s, which means
they provide a *pull-based API*. For example:

[stdout]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/stdout.html
[stderr]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/stderr.html
[StreamQueue]: https://pub.dev/documentation/async/latest/async/StreamQueue-class.html

```dart
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('dart', ['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:

[stream matchers]: https://github.com/dart-lang/test#stream-matchers

```dart
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('dart', ['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()`][stdoutStream] and
[`stderrStream()`][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.

[stdoutStream]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/stdoutStream.html
[stderrStream]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/stderrStream.html

## Signals and Termination

The way signaling works is different from `dart:io` as well. `TestProcess` still
has a [`kill()`][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()`][signal].

[kill]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/kill.html
[signal]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/signal.html

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

[exitCode]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/exitCode.html
[shouldExit]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/shouldExit.html

## 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()`][start] to control the headers.

[start]: https://pub.dev/documentation/test_process/latest/test_process/TestProcess/start.html

`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.
18 changes: 18 additions & 0 deletions pkgs/test_process/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://dart.dev/tools/analysis#the-analysis-options-file
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- avoid_unused_constructor_parameters
- cancel_subscriptions
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- unnecessary_await_in_return
26 changes: 26 additions & 0 deletions pkgs/test_process/example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2022, 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.

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('dart', ['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);
});
}
Loading
Loading