Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Migrate to null safety #23

Merged
merged 10 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 0 additions & 24 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,3 @@ jobs:
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'

# Run tests on a legacy SDK on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release: 2.1.0
test_legacy_sdk:
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: [2.1.0]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v0.3
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: pub get
- name: Run VM tests
run: pub run test --platform vm
if: always() && steps.install.outcome == 'success'
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0-nullsafety.0

* Migrate to null safety.
* Require Dart >=2.12.

## 1.0.6

* Require Dart >=2.1
Expand Down
31 changes: 13 additions & 18 deletions lib/test_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ class TestProcess {

/// A [StreamQueue] that emits each line of stdout from the process.
///
/// A copy of the underlying stream can be retreived using [stdoutStream].
StreamQueue<String> get stdout => _stdout;
StreamQueue<String> _stdout;
/// A copy of the underlying stream can be retrieved using [stdoutStream].
late final StreamQueue<String> stdout = StreamQueue(stdoutStream());
kevmoo marked this conversation as resolved.
Show resolved Hide resolved

/// A [StreamQueue] that emits each line of stderr from the process.
///
/// A copy of the underlying stream can be retreived using [stderrStream].
StreamQueue<String> get stderr => _stderr;
StreamQueue<String> _stderr;
/// A copy of the underlying stream can be retrieved using [stderrStream].
late final StreamQueue<String> stderr = StreamQueue(stderrStream());

/// A splitter that can emit new copies of [stdout].
final StreamSplitter<String> _stdoutSplitter;
Expand All @@ -48,7 +46,7 @@ class TestProcess {
IOSink get stdin => _process.stdin;

/// A buffer of mixed stdout and stderr lines.
final _log = <String>[];
final List<String> _log = <String>[];

/// Whether [_log] has been passed to [printOnFailure] yet.
bool _loggedOutput = false;
Expand All @@ -62,8 +60,9 @@ class TestProcess {

/// Completes to [_process]'s exit code if it's exited, otherwise completes to
/// `null` immediately.
Future<int> get _exitCodeOrNull async =>
await exitCode.timeout(Duration.zero, onTimeout: () => null);
Future<int?> get _exitCodeOrNull async => await exitCode
.then<int?>((value) => value)
.timeout(Duration.zero, onTimeout: () => null);

/// Starts a process.
///
Expand All @@ -79,12 +78,12 @@ class TestProcess {
/// temporarily to help when debugging test failures.
static Future<TestProcess> start(
String executable, Iterable<String> arguments,
{String workingDirectory,
Map<String, String> environment,
{String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
String description,
Encoding encoding,
String? description,
Encoding encoding = utf8,
bool forwardStdio = false}) async {
var process = await Process.start(executable, arguments.toList(),
workingDirectory: workingDirectory,
Expand All @@ -99,7 +98,6 @@ class TestProcess {
description = "$humanExecutable ${arguments.join(" ")}";
}

encoding ??= utf8;
return TestProcess(process, description,
encoding: encoding, forwardStdio: forwardStdio);
}
Expand All @@ -112,7 +110,7 @@ class TestProcess {
/// This is protected, which means it should only be called by subclasses.
@protected
TestProcess(Process process, this.description,
{Encoding encoding, bool forwardStdio = false})
{Encoding encoding= utf8, bool forwardStdio = false})
: _process = process,
_stdoutSplitter = StreamSplitter(process.stdout
.transform(encoding.decoder)
Expand All @@ -124,9 +122,6 @@ class TestProcess {
expect(_process.exitCode.then((_) => _logOutput()), completes,
reason: 'Process `$description` never exited.');

_stdout = StreamQueue(stdoutStream());
_stderr = StreamQueue(stderrStream());

// Listen eagerly so that the lines are interleaved properly between the two
// streams.
//
Expand Down
16 changes: 8 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: test_process
version: 1.0.6-dev
version: 2.0.0

description: A package for testing subprocesses.
homepage: https://github.com/dart-lang/test_process

environment:
sdk: '>=2.1.0 <3.0.0'
sdk: ">=2.12.0-0 <3.0.0"

dependencies:
async: ^2.0.0
meta: ^1.0.0
path: ^1.0.0
test: ^1.0.0
async: ^2.5.0
meta: ^1.3.0
path: ^1.8.0
test: ^1.16.0

dev_dependencies:
pedantic: ^1.0.0
test_descriptor: ^1.0.0
pedantic: ^1.10.0
test_descriptor: ^2.0.0