Skip to content

arturograu/system_command_runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages