<commit_before>package doctor

// This file defines utility functions used exclusively by the testing
// infrastructure.

import (
	"bytes"
	"fmt"
	"go/parser"
	"go/token"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
)

const MARKER = "<<<<<"
const PASS = "pass"
const FAIL_SELECTION = "fail-selection"
const FAIL_CONFIGURE = "fail-configure"
const FAIL = "fail"

// assertEquals is a utility method for unit tests that marks a function as
// having failed if expected != actual
func assertEquals(expected string, actual string) {
	if expected != actual {
		log.Printf("Expected: %s Actual: %s", expected, actual)
	}
}

// assertError is a utility method for unit tests that marks a function as
// having failed if the given string does not begin with "ERROR: "
func assertError(result string) {
	if !strings.HasPrefix(result, "ERROR: ") {
		log.Printf("Expected error; actual: \"%s\"", result)
	}
}

// RunAllTests is a utility method that runs a set of refactoring tests
// based on markers in all of the files in subdirectories of a given directory
func RunAllTests() {
	files, err := recursiveReadDir(".")
	failIfError(err)

	absolutePath, err := filepath.Abs(".")
	failIfError(err)
	err = os.Setenv("GOPATH", absolutePath)
	failIfError(err)

	runTestsInFiles(files)
}

// Assumes no duplication or circularity due to symbolic links
func recursiveReadDir(path string) ([]string, error) {
	result := []string{}

	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return []string{}, err
	}

	for _, fi := range fileInfos {
		if fi.IsDir() {
			current := result<commit_msg>Added helper func for moving away from ./runtests.sh<commit_after>package doctor

// This file defines utility functions used exclusively by the testing
// infrastructure.

import (
	"bytes"
	"fmt"
	"go/parser"
	"go/token"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
)

const MARKER = "<<<<<"
const PASS = "pass"
const FAIL_SELECTION = "fail-selection"
const FAIL_CONFIGURE = "fail-configure"
const FAIL = "fail"

// assertEquals is a utility method for unit tests that marks a function as
// having failed if expected != actual
func assertEquals(expected string, actual string) {
	if expected != actual {
		log.Printf("Expected: %s Actual: %s", expected, actual)
	}
}

// assertError is a utility method for unit tests that marks a function as
// having failed if the given string does not begin with "ERROR: "
func assertError(result string) {
	if !strings.HasPrefix(result, "ERROR: ") {
		log.Printf("Expected error; actual: \"%s\"", result)
	}
}

// RunAllTests is a utility method that runs a set of refactoring tests
// based on markers in all of the files in subdirectories of a given directory
func RunAllTests() {
	RunAllTestsInDirectory(".")
}

// RunAllTests is a utility method that runs a set of refactoring tests
// based on markers in all of the files in subdirectories of a given directory
func RunAllTestsInDirectory(directory string) {
	files, err := recursiveReadDir(directory)
	failIfError(err)

	absolutePath, err := filepath.Abs(directory)
	failIfError(err)
	err = os.Setenv("GOPATH", absolutePath)
	failIfError(err)

	runTestsInFiles(files)
}

// Assumes no duplication or circularity due to symbolic links
func recursiveReadDir(path string) ([]string, error) {
	result := []string{}

	fileInfos, err := ioutil.ReadDir(path)
	if err != nil {
		return []string{}, err
	}

	for _, fi := range fileInfos {
		if fi.IsDir() {
			current := result
{'fraction_non_alphanumeric': 0.1168091168091168, 'fraction_numerical': 0.0, 'mean_word_length': 4.240298507462686, 'pattern_counts': {'":': 0, '<': 13, '<?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': '5242303', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1110, 'n_words': 396}