<commit_before>package main

import (
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)

func test_compiler(t *testing.T, input_file string, reference_file string, expect_errors bool) {
	// output_file is the name of the text-format proto file that is generated by the compiler
	var suffix string
	if expect_errors {
		suffix = ".errors"
	} else {
		suffix = ".text"
	}
	output_file := strings.Replace(filepath.Base(input_file), filepath.Ext(input_file), suffix, 1)
	// remove any preexisting output_file
	var err error
	err = exec.Command("rm", "-f", output_file).Run()
	if err != nil {
		t.Logf("Failed to remove file %s", output_file)
		t.FailNow()
	}
	// run the compiler
	err = exec.Command("openapic", "-in", input_file, "-text", "-errors").Run()
	if err != nil && !expect_errors {
		t.Logf("Compile failed: %+v", err)
		t.FailNow()
	}
	// verify the output_file against the reference_file
	err = exec.Command("diff", output_file, reference_file).Run()
	if err != nil {
		t.Logf("Diff failed: %+v", err)
		t.FailNow()
	}
}

func test_normal(t *testing.T, input_file string, reference_file string) {
	test_compiler(t, input_file, reference_file, false)
}

func test_errors(t *testing.T, input_file string, reference_file string) {
	test_compiler(t, input_file, reference_file, true)
}

func TestPetstoreJSON(t *testing.T) {
	test_normal(t,
		"examples/petstore.json",
		"test/petstore.text")
}

func TestPetstoreYAML(t *testing.T) {
	test_normal(t,
		"examples/petstore.yaml",
		"test/petstore.text")
}

func TestSeparateYAML(t *testing.T) {
	test_normal(t,
		"examples/v2.0/yaml/petstore-separate/spec/swagger.yaml",
		"test/v2.0/yaml/petstore-separate/spec/swagger.text")<commit_msg>Passing tests clean up after themselves.<commit_after>package main

import (
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)

func test_compiler(t *testing.T, input_file string, reference_file string, expect_errors bool) {
	// output_file is the name of the text-format proto file that is generated by the compiler
	var suffix string
	if expect_errors {
		suffix = ".errors"
	} else {
		suffix = ".text"
	}
	output_file := strings.Replace(filepath.Base(input_file), filepath.Ext(input_file), suffix, 1)
	// remove any preexisting output_file
	var err error
	err = exec.Command("rm", "-f", output_file).Run()
	if err != nil {
		t.Logf("Failed to remove file %s", output_file)
		t.FailNow()
	}
	// run the compiler
	err = exec.Command("openapic", "-in", input_file, "-text", "-errors").Run()
	if err != nil && !expect_errors {
		t.Logf("Compile failed: %+v", err)
		t.FailNow()
	}
	// verify the output_file against the reference_file
	err = exec.Command("diff", output_file, reference_file).Run()
	if err != nil {
		t.Logf("Diff failed: %+v", err)
		t.FailNow()
	} else {
		os.Remove(output_file)
	}
}

func test_normal(t *testing.T, input_file string, reference_file string) {
	test_compiler(t, input_file, reference_file, false)
}

func test_errors(t *testing.T, input_file string, reference_file string) {
	test_compiler(t, input_file, reference_file, true)
}

func TestPetstoreJSON(t *testing.T) {
	test_normal(t,
		"examples/petstore.json",
		"test/petstore.text")
}

func TestPetstoreYAML(t *testing.T) {
	test_normal(t,
		"examples/petstore.yaml",
		"test/petstore.text")
}

func TestSeparateYAML(t *testing.T) {
	test_normal(t,
		"examples/v2.0/yaml/petstore-separate/spec/swagger.yaml",
		"test/v2.0/yaml/petstore-separate/spec/swagger.text")
{'fraction_non_alphanumeric': 0.14484356894553882, 'fraction_numerical': 0.0028968713789107765, 'mean_word_length': 4.5248, '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': '7413818', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1264, 'n_words': 293}