system_command_runner 0.1.0 copy "system_command_runner: ^0.1.0" to clipboard
system_command_runner: ^0.1.0 copied to clipboard

A lightweight, testable wrapper around Process.run for executing system commands with cross-platform support and easy mocking.

System Command Runner #

pub package License: MIT GitHub Workflow Status (with branch) Pull Requests are welcome codecov Null safety

A testable wrapper around Process.run for executing system commands.

Why? #

Process.run is hard to mock. This package provides a simple, injectable wrapper that makes your code testable.

Installation #

dependencies:
  system_command_runner: ^0.1.0

Usage #

import 'package:system_command_runner/system_command_runner.dart';

final runner = const SystemCommandRunner();

// Basic command
final result = await runner.run('echo', ['Hello, World!']);
print(result.stdout); // Hello, World!

// With working directory and environment
final result2 = await runner.run(
  'git',
  ['status'],
  workingDirectory: '/path/to/repo',
  environment: {'GIT_CONFIG': '/custom/config'},
);

Testing #

class MockSystemCommandRunner extends Mock implements SystemCommandRunner {}

// In your test
when(() => mockRunner.run('git', ['status'])).thenAnswer(
  (_) async => CommandResult(exitCode: 0, stdout: 'clean', stderr: ''),
);

API #

SystemCommandRunner #

  • run(String executable, List<String> arguments, {String? workingDirectory, Map<String, String>? environment})

CommandResult #

  • exitCode - Exit code
  • stdout - Standard output
  • stderr - Standard error
0
likes
160
points
64
downloads

Publisher

verified publisherfluttered.io

Weekly Downloads

A lightweight, testable wrapper around Process.run for executing system commands with cross-platform support and easy mocking.

Repository (GitHub)
View/report issues

Topics

#system #command #shell #testing

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on system_command_runner