From 9f8c83d72d3a3c7ded35d85501f70389237d88f7 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Sun, 24 Dec 2023 10:12:19 +0100 Subject: [PATCH 1/4] [process_run] fix issue #101, properly propage errors in shell line controller. --- .../lib/src/lines_utils_common.dart | 2 ++ .../test/shell_lines_controller_test.dart | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/process_run/lib/src/lines_utils_common.dart b/packages/process_run/lib/src/lines_utils_common.dart index 6d53396..da573e9 100644 --- a/packages/process_run/lib/src/lines_utils_common.dart +++ b/packages/process_run/lib/src/lines_utils_common.dart @@ -135,6 +135,8 @@ Stream shellStreamLines(Stream> stream, // Last one addCurrentLine(); ctlr.close(); + }, onError: (Object e, StackTrace st) { + ctlr.addError(e, st); }); }, onCancel: () { subscription?.cancel(); diff --git a/packages/process_run/test/shell_lines_controller_test.dart b/packages/process_run/test/shell_lines_controller_test.dart index 4531253..1aa90df 100644 --- a/packages/process_run/test/shell_lines_controller_test.dart +++ b/packages/process_run/test/shell_lines_controller_test.dart @@ -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(); @@ -45,5 +46,34 @@ void main() { // Should fail } }, timeout: const Timeout(Duration(milliseconds: 30000))); + test('addError', () async { + var ctlr = ShellLinesController(); + var completer = Completer(); + 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(); + 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; + }); }); } From cb68cc6b74e432f15d80394ecc84dc51490283c9 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Sun, 24 Dec 2023 10:13:41 +0100 Subject: [PATCH 2/4] [process_run] v0.13.3+1 --- packages/process_run/CHANGELOG.md | 3 ++- packages/process_run/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/process_run/CHANGELOG.md b/packages/process_run/CHANGELOG.md index 943ee62..c6b2fac 100644 --- a/packages/process_run/CHANGELOG.md +++ b/packages/process_run/CHANGELOG.md @@ -1,7 +1,8 @@ -## 0.13.3 +## 0.13.3+1 * Fix finding `flutter` on windows in unit tests * Remove `charcode` dependency. +* Propage added errors in `ShellLinesController` ## 0.13.2 diff --git a/packages/process_run/pubspec.yaml b/packages/process_run/pubspec.yaml index 84c5873..3e7c4cb 100644 --- a/packages/process_run/pubspec.yaml +++ b/packages/process_run/pubspec.yaml @@ -1,5 +1,5 @@ name: process_run -version: 0.13.3 +version: 0.13.3+1 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 From 294ecb81050239c2d5781cf8b26a5aff5b1a3576 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Tue, 2 Jan 2024 17:57:31 +0100 Subject: [PATCH 3/4] [process_run] fix issue #19 no longer weirdly replace `\` by `\\` --- packages/process_run/lib/src/io/shell_words.dart | 2 +- packages/process_run/lib/src/shell_utils.dart | 5 ++--- packages/process_run/test/dartbin_test.dart | 2 +- packages/process_run/test/shell_test.dart | 6 +++--- packages/process_run/test/src_shell_utils_test.dart | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/process_run/lib/src/io/shell_words.dart b/packages/process_run/lib/src/io/shell_words.dart index bdc7cd0..c808499 100644 --- a/packages/process_run/lib/src/io/shell_words.dart +++ b/packages/process_run/lib/src/io/shell_words.dart @@ -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 shellSplit(String command) { +List shellSplitImpl(String command) { final scanner = StringScanner(command); final results = []; final token = StringBuffer(); diff --git a/packages/process_run/lib/src/shell_utils.dart b/packages/process_run/lib/src/shell_utils.dart index e1899cd..655399b 100644 --- a/packages/process_run/lib/src/shell_utils.dart +++ b/packages/process_run/lib/src/shell_utils.dart @@ -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'; @@ -207,8 +207,7 @@ bool fixRunInShell(bool? runInShell, String executable) { } /// Use io package shellSplit implementation -List shellSplit(String command) => - io.shellSplit(command.replaceAll(r'\', r'\\')); +List shellSplit(String command) => io.shellSplitImpl(command); /// Inverse of shell split String shellJoin(List parts) => diff --git a/packages/process_run/test/dartbin_test.dart b/packages/process_run/test/dartbin_test.dart index 93eeb21..d091038 100644 --- a/packages/process_run/test/dartbin_test.dart +++ b/packages/process_run/test/dartbin_test.dart @@ -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']); diff --git a/packages/process_run/test/shell_test.dart b/packages/process_run/test/shell_test.dart index b002f1d..a8cc504 100644 --- a/packages/process_run/test/shell_test.dart +++ b/packages/process_run/test/shell_test.dart @@ -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 @@ -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); }); @@ -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 { diff --git a/packages/process_run/test/src_shell_utils_test.dart b/packages/process_run/test/src_shell_utils_test.dart index c291dc0..337f99d 100644 --- a/packages/process_run/test/src_shell_utils_test.dart +++ b/packages/process_run/test/src_shell_utils_test.dart @@ -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']); @@ -90,7 +90,7 @@ void main() { testSplitJoin('foo'); testSplitJoin('foo bar'); - testSplitJoin(r'\'); + // testSplitJoin(r'\'); testSplitJoin('"foo bar"'); testSplitJoin("'foo bar'", expected: '"foo bar"'); }); From eb21ac7d5f635d06685281cfaef0e47ebd6a2056 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Tue, 2 Jan 2024 17:59:18 +0100 Subject: [PATCH 4/4] [process_run] v0.14.0 --- packages/process_run/CHANGELOG.md | 4 ++++ packages/process_run/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/process_run/CHANGELOG.md b/packages/process_run/CHANGELOG.md index c6b2fac..0eb6b63 100644 --- a/packages/process_run/CHANGELOG.md +++ b/packages/process_run/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.14.0 + +* No longer replace `\` by `\\` before splitting arguments + ## 0.13.3+1 * Fix finding `flutter` on windows in unit tests diff --git a/packages/process_run/pubspec.yaml b/packages/process_run/pubspec.yaml index 3e7c4cb..9800934 100644 --- a/packages/process_run/pubspec.yaml +++ b/packages/process_run/pubspec.yaml @@ -1,5 +1,5 @@ name: process_run -version: 0.13.3+1 +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