<commit_before>package rclone

import (
	"context"
	"testing"

	"github.com/restic/restic/internal/restic"
	rtest "github.com/restic/restic/internal/test"
)

// restic should detect rclone exiting.
func TestRcloneExit(t *testing.T) {
	dir, cleanup := rtest.TempDir(t)
	defer cleanup()

	cfg := NewConfig()
	cfg.Remote = dir
	be, err := Open(cfg, nil)
	rtest.OK(t, err)
	defer be.Close()

	err = be.cmd.Process.Kill()
	rtest.OK(t, err)
	t.Log("killed rclone")

	_, err = be.Stat(context.TODO(), restic.Handle{
		Name: "foo",
		Type: restic.DataFile,
	})
	rtest.Assert(t, err != nil, "expected an error")
}<commit_msg>rclone: Skip crash test when rclone is not found<commit_after>package rclone

import (
	"context"
	"os/exec"
	"testing"

	"github.com/restic/restic/internal/errors"
	"github.com/restic/restic/internal/restic"
	rtest "github.com/restic/restic/internal/test"
)

// restic should detect rclone exiting.
func TestRcloneExit(t *testing.T) {
	dir, cleanup := rtest.TempDir(t)
	defer cleanup()

	cfg := NewConfig()
	cfg.Remote = dir
	be, err := Open(cfg, nil)
	if e, ok := errors.Cause(err).(*exec.Error); ok && e.Err == exec.ErrNotFound {
		t.Skipf("program %q not found", e.Name)
		return
	}
	rtest.OK(t, err)
	defer be.Close()

	err = be.cmd.Process.Kill()
	rtest.OK(t, err)
	t.Log("killed rclone")

	_, err = be.Stat(context.TODO(), restic.Handle{
		Name: "foo",
		Type: restic.DataFile,
	})
	rtest.Assert(t, err != nil, "expected an error")
}
{'fraction_non_alphanumeric': 0.16689560439560439, 'fraction_numerical': 0.0, 'mean_word_length': 4.024137931034483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2752549', 'n_tokens_mistral': 597, 'n_tokens_neox': 576, 'n_words': 127}