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

Libraries

system_command_runner
A Dart package for running system commands with cross-platform support.