<commit_before>package main

import (
	"bytes"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"
)

func panicOnError(e error) {
	if e != nil {
		panic(e)
	}
}

func TestEncryptDecrypt(t *testing.T) {
	tempdir, err := ioutil.TempDir(os.TempDir(), "saltyboxtest")
	if err != nil {
		t.Fatalf("failed creating temp dir: %s", err)
	}
	defer func(tempdir string) {
		panicOnError(os.Remove(tempdir))

	}(tempdir)

	plainPath := filepath.Join(tempdir, "plain")
	err = ioutil.WriteFile(plainPath, []byte("super secret"), 0777)
	if err != nil {
		t.Fatalf("failed to write to %s: %s", plainPath, err)
	}
	defer func(plainPath string) {
		panicOnError(os.Remove(plainPath))
	}(plainPath)

	encryptedPath := filepath.Join(tempdir, "encrypted")
	defer func(encryptedPath string) {
		panicOnError(os.Remove(encryptedPath))
	}(encryptedPath)

	panicOnError(passphraseEncryptFile(plainPath, encryptedPath, constantPassphraseReader{constantPassphrase: "test"}))

	newPlainPath := filepath.Join(tempdir, "newplain")
	defer func(newPlainPath string) {
		panicOnError(os.Remove(newPlainPath))
	}(newPlainPath)

	panicOnError(passphraseDecryptFile(encryptedPath, newPlainPath, constantPassphraseReader{constantPassphrase: "test"}))
<commit_msg>That was too disgusting; use checkedRemove() instead.<commit_after>package main

import (
	"bytes"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"testing"
)

func checkedRemove(fname string) {
	err := os.Remove(fname)
	if err != nil {
		log.Panicf("removal of file %s failed: %s", fname, err)
	}
}

func TestEncryptDecrypt(t *testing.T) {
	tempdir, err := ioutil.TempDir(os.TempDir(), "saltyboxtest")
	if err != nil {
		t.Fatalf("failed creating temp dir: %s", err)
	}
	defer checkedRemove(tempdir)

	plainPath := filepath.Join(tempdir, "plain")
	err = ioutil.WriteFile(plainPath, []byte("super secret"), 0777)
	if err != nil {
		t.Fatalf("failed to write to %s: %s", plainPath, err)
	}
	defer checkedRemove(plainPath)

	encryptedPath := filepath.Join(tempdir, "encrypted")
	defer checkedRemove(encryptedPath)

	err = passphraseEncryptFile(plainPath, encryptedPath, constantPassphraseReader{constantPassphrase: "test"})
	if err != nil {
		t.Fatalf("encryption failed: %s", err)
	}

	newPlainPath := filepath.Join(tempdir, "newplain")
	defer checkedRemove(newPlainPath)

	err = passphraseDecryptFile(encryptedPath, newPlainPath, constantPassphraseReader{constantPassphrase: "test"})
	if err != nil {
		t.Fatalf("decryption failed: %s", err)
	}

{'fraction_non_alphanumeric': 0.1416396103896104, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 5.7349726775956285, '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': '2708379', 'n_tokens_mistral': 922, 'n_tokens_neox': 893, 'n_words': 188}