Skip to content

Commit

Permalink
Merging from dart3a
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Jan 2, 2024
2 parents 06ebec5 + eb21ac7 commit 00442ff
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/process_run/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
## 0.13.3
## 0.14.0

* No longer replace `\` by `\\` before splitting arguments

## 0.13.3+1

* Fix finding `flutter` on windows in unit tests
* Remove `charcode` dependency.
* Propage added errors in `ShellLinesController`

## 0.13.2

Expand Down
2 changes: 1 addition & 1 deletion packages/process_run/lib/src/io/shell_words.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:string_scanner/string_scanner.dart';
/// This will discard any comments at the end of [command].
///
/// Throws a [FormatException] if [command] isn't a valid shell command.
List<String> shellSplit(String command) {
List<String> shellSplitImpl(String command) {
final scanner = StringScanner(command);
final results = <String>[];
final token = StringBuffer();
Expand Down
2 changes: 2 additions & 0 deletions packages/process_run/lib/src/lines_utils_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Stream<String> shellStreamLines(Stream<List<int>> stream,
// Last one
addCurrentLine();
ctlr.close();
}, onError: (Object e, StackTrace st) {
ctlr.addError(e, st);
});
}, onCancel: () {
subscription?.cancel();
Expand Down
5 changes: 2 additions & 3 deletions packages/process_run/lib/src/shell_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:path/path.dart';
import 'package:process_run/shell.dart';
import 'package:process_run/src/common/constant.dart';
import 'package:process_run/src/io/shell_words.dart' as io show shellSplit;
import 'package:process_run/src/io/shell_words.dart' as io show shellSplitImpl;
import 'package:process_run/src/shell_environment.dart';

import 'bin/shell/import.dart';
Expand Down Expand Up @@ -207,8 +207,7 @@ bool fixRunInShell(bool? runInShell, String executable) {
}

/// Use io package shellSplit implementation
List<String> shellSplit(String command) =>
io.shellSplit(command.replaceAll(r'\', r'\\'));
List<String> shellSplit(String command) => io.shellSplitImpl(command);

/// Inverse of shell split
String shellJoin(List<String> parts) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/process_run/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: process_run
version: 0.13.3
version: 0.14.0
description: Process run helpers for Linux/Win/Mac and which like feature for finding executables.
homepage: https://github.com/tekartik/process_run.dart/blob/master/packages/process_run

Expand Down
2 changes: 1 addition & 1 deletion packages/process_run/test/dartbin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void defineTests() {
// Dart SDK version: 2.9.0-21.2.beta (beta) (Fri Jul 10 17:39:56 2020 +0200) on "linux_x64"
// After 2.15.0
// Dart SDK version: 2.15.0-82.0.dev (dev) (Sat Sep 4 03:33:09 2021 -0700) on "linux_x64"
});
}, skip: 'dart might not be in the path');

test('run', () async {
final result = await Process.run(dartExecutable!, ['--version']);
Expand Down
32 changes: 31 additions & 1 deletion packages/process_run/test/shell_lines_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void main() {
late ShellEnvironment env;
setUpAll(() {
env = ShellEnvironment()
..aliases['streamer'] = 'dart run ${shellArgument(streamerScriptPath)}';
..aliases['streamer'] = 'dart run ${shellArgument(streamerScriptPath)}'
..aliases['echo'] = 'dart run ${shellArgument(echoScriptPath)}';
});
test('stream all', () async {
var ctlr = ShellLinesController();
Expand Down Expand Up @@ -45,5 +46,34 @@ void main() {
// Should fail
}
}, timeout: const Timeout(Duration(milliseconds: 30000)));
test('addError', () async {
var ctlr = ShellLinesController();
var completer = Completer<bool>();
ctlr.stream.listen((event) {
fail('should not be called');
}, onError: (Object e) {
expect(e, 'test');
completer.complete(true);
});
ctlr.sink.addError('test');

await completer.future;
ctlr.close();
});
test('shell error', () async {
var ctlr = ShellLinesController();
var completer = Completer<bool>();
ctlr.stream.listen((event) {}, onError: (Object e) {
var shellException = e as ShellException;
expect(shellException.result!.exitCode, 1);
//expect(e, 'test');
completer.complete(true);
});
var shell = Shell(stdout: ctlr.sink, environment: env);
await shell
.run('echo --exit-code 1')
.then((_) => ctlr.close(), onError: ctlr.sink.addError);
await completer.future;
});
});
}
6 changes: 3 additions & 3 deletions packages/process_run/test/shell_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'hex_utils.dart';
@Deprecated('Dev only, used when uncommenting debug = devTrue')
bool devTrue = true;

//bool debug = devTrue;
// bool debug = devTrue;
bool debug = false;

// To set in both variable for a full empty environment
Expand Down Expand Up @@ -147,7 +147,7 @@ dart example/echo.dart -o ${shellArgument(weirdText)}
''');

expect(results[0].stdout.toString().trim(), r'a/\bc/\d');
expect(results[0].stdout.toString().trim(), r'a/bc/d');
expect(results[1].stdout.toString().trim(), r'a/\b c/\d');
expect(results.length, 2);
});
Expand Down Expand Up @@ -399,7 +399,7 @@ dart current_dir.dart

test('escape backslash', () async {
var shell = Shell(verbose: debug);
var results = await shell.run('''echo "\\"''');
var results = await shell.run(r'echo "\\"');
expect(results[0].stdout.toString().trim(), '\\');
});
test('others', () async {
Expand Down
4 changes: 2 additions & 2 deletions packages/process_run/test/src_shell_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {

test('shellSplit', () {
// We differ from io implementation
expect(shellSplit(r'\'), [r'\']);
expect(shellSplit(r'"\\"'), [r'\']);
expect(shellSplit('Hello world'), ['Hello', 'world']);
expect(shellSplit('"Hello world"'), ['Hello world']);
expect(shellSplit("'Hello world'"), ['Hello world']);
Expand All @@ -90,7 +90,7 @@ void main() {

testSplitJoin('foo');
testSplitJoin('foo bar');
testSplitJoin(r'\');
// testSplitJoin(r'\');
testSplitJoin('"foo bar"');
testSplitJoin("'foo bar'", expected: '"foo bar"');
});
Expand Down

0 comments on commit 00442ff

Please sign in to comment.