modified benchmark_test.go to use a cloned linguist repo

This commit is contained in:
Manuel Carmona
2017-07-18 13:29:46 +02:00
parent 510c430fd0
commit 8e0a26f810

View File

@ -5,11 +5,12 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"testing" "testing"
)
const samplesDir = ".linguist/samples" "gopkg.in/src-d/enry.v1/data"
)
type sample struct { type sample struct {
filename string filename string
@ -21,18 +22,62 @@ var (
overcomeLanguage string overcomeLanguage string
overcomeLanguages []string overcomeLanguages []string
samples []*sample samples []*sample
samplesDir string
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var exitCode int
defer os.Exit(exitCode)
flag.BoolVar(&slow, "slow", false, "run benchmarks per sample for strategies too") flag.BoolVar(&slow, "slow", false, "run benchmarks per sample for strategies too")
flag.Parse() flag.Parse()
if err := cloneLinguist(linguistURL); err != nil {
log.Fatal(err)
}
defer os.RemoveAll(filepath.Dir(samplesDir))
var err error var err error
samples, err = getSamples(samplesDir) samples, err = getSamples(samplesDir)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
os.Exit(m.Run()) exitCode = m.Run()
}
func cloneLinguist(linguistURL string) error {
repoLinguist, err := ioutil.TempDir("", "linguist-")
if err != nil {
return err
}
samplesDir = filepath.Join(repoLinguist, "samples")
cmd := exec.Command("git", "clone", linguistURL, repoLinguist)
if err := cmd.Run(); err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return err
}
if err = os.Chdir(repoLinguist); err != nil {
return err
}
cmd = exec.Command("git", "checkout", data.LinguistCommit)
if err := cmd.Run(); err != nil {
return err
}
if err = os.Chdir(cwd); err != nil {
return err
}
return nil
} }
func getSamples(dir string) ([]*sample, error) { func getSamples(dir string) ([]*sample, error) {