"""Tests for the command runner."""

from regimen.runner import run_command


def test_run_success():
    result = run_command("echo hello")
    assert result["exit_code"] == 0
    assert "hello" in result["stdout"]


def test_run_failure():
    result = run_command("false")
    assert result["exit_code"] != 0


def test_run_stderr():
    result = run_command("echo err >&2")
    assert "err" in result["stderr"]


def test_run_timeout():
    result = run_command("sleep 10", timeout=1)
    assert result["exit_code"] == -1
    assert "timed out" in result["stderr"]


def test_run_multiline():
    result = run_command("for i in a b c; do echo $i; done")
    assert result["exit_code"] == 0
    assert "a\nb\nc" in result["stdout"]
