<commit_before>package system

import (
	boshlog "bosh/logger"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestRunComplexCommandWithWorkingDirectory(t *testing.T) {
	cmd := Command{
		Name:       "ls",
		Args:       []string{"-l"},
		WorkingDir: "../../..",
	}
	runner := createRunner()
	stdout, stderr, err := runner.RunComplexCommand(cmd)
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Contains(t, stdout, "README.md")
	assert.Contains(t, stdout, "total")
}

func TestRunComplexCommandWithEnv(t *testing.T) {
	cmd := Command{
		Name: "env",
		Env: map[string]string{
			"FOO": "BAR",
		},
	}
	runner := createRunner()
	stdout, stderr, err := runner.RunComplexCommand(cmd)
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Contains(t, stdout, "FOO=BAR")
	assert.Contains(t, stdout, "PATH=")
}

func TestRunCommand(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("echo", "Hello World!")
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Equal(t, stdout, "Hello World!\n")
}

func TestRunCommandWithErrorOutput(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("sh", "-c", "echo error-output >&2")
	assert.NoError(t, err)
	assert.Contains(t, stderr, "error-output")
	assert.Empty(t, stdout)
}

func TestRunCommandWithError(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("false")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Running command: 'false', stdout: '', stderr: '': exit status 1")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithErrorWithArgs(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("false", "second arg")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Running command: 'false second arg', stdout: '', stderr: '': exit status 1")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithCmdNotFound(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("something that does not exist")
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "not found")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithInput(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommandWithInput("foo\nbar\nbaz", "grep", "ba")

	assert.NoError(t, err)
	assert.Equal(t, "bar\nbaz\n", stdout)
	assert.Empty(t, stderr)
}

func TestCommandExists(t *testing.T) {
	runner := createRunner()

	assert.True(t, runner.CommandExists("cd"))<commit_msg>fix test to check for more common command in PATH<commit_after>package system

import (
	boshlog "bosh/logger"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestRunComplexCommandWithWorkingDirectory(t *testing.T) {
	cmd := Command{
		Name:       "ls",
		Args:       []string{"-l"},
		WorkingDir: "../../..",
	}
	runner := createRunner()
	stdout, stderr, err := runner.RunComplexCommand(cmd)
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Contains(t, stdout, "README.md")
	assert.Contains(t, stdout, "total")
}

func TestRunComplexCommandWithEnv(t *testing.T) {
	cmd := Command{
		Name: "env",
		Env: map[string]string{
			"FOO": "BAR",
		},
	}
	runner := createRunner()
	stdout, stderr, err := runner.RunComplexCommand(cmd)
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Contains(t, stdout, "FOO=BAR")
	assert.Contains(t, stdout, "PATH=")
}

func TestRunCommand(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("echo", "Hello World!")
	assert.NoError(t, err)
	assert.Empty(t, stderr)
	assert.Equal(t, stdout, "Hello World!\n")
}

func TestRunCommandWithErrorOutput(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("sh", "-c", "echo error-output >&2")
	assert.NoError(t, err)
	assert.Contains(t, stderr, "error-output")
	assert.Empty(t, stdout)
}

func TestRunCommandWithError(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("false")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Running command: 'false', stdout: '', stderr: '': exit status 1")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithErrorWithArgs(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("false", "second arg")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Running command: 'false second arg', stdout: '', stderr: '': exit status 1")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithCmdNotFound(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommand("something that does not exist")
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "not found")
	assert.Empty(t, stderr)
	assert.Empty(t, stdout)
}

func TestRunCommandWithInput(t *testing.T) {
	runner := createRunner()

	stdout, stderr, err := runner.RunCommandWithInput("foo\nbar\nbaz", "grep", "ba")

	assert.NoError(t, err)
	assert.Equal(t, "bar\nbaz\n", stdout)
	assert.Empty(t, stderr)
}

func TestCommandExists(t *testing.T) {
	runner := createRunner()

	assert.True(t, runner.CommandExists("env"))
{'fraction_non_alphanumeric': 0.171406461597988, 'fraction_numerical': 0.0011607661056297156, 'mean_word_length': 5.096698113207547, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939772', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1883, 'n_words': 410}