mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 13:32:24 +00:00
Merge pull request #114 from vmarkovtsev/patch-2
Add the external test linguist dir from env var
This commit is contained in:
commit
b92be473c4
@ -23,6 +23,7 @@ var (
|
|||||||
overcomeLanguages []string
|
overcomeLanguages []string
|
||||||
samples []*sample
|
samples []*sample
|
||||||
samplesDir string
|
samplesDir string
|
||||||
|
cloned bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -35,7 +36,9 @@ func TestMain(m *testing.M) {
|
|||||||
if err := cloneLinguist(linguistURL); err != nil {
|
if err := cloneLinguist(linguistURL); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(filepath.Dir(samplesDir))
|
if cloned {
|
||||||
|
defer os.RemoveAll(filepath.Dir(samplesDir))
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
samples, err = getSamples(samplesDir)
|
samples, err = getSamples(samplesDir)
|
||||||
@ -47,16 +50,23 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cloneLinguist(linguistURL string) error {
|
func cloneLinguist(linguistURL string) error {
|
||||||
repoLinguist, err := ioutil.TempDir("", "linguist-")
|
repoLinguist := os.Getenv(linguistClonedEnvVar)
|
||||||
if err != nil {
|
cloned = repoLinguist == ""
|
||||||
return err
|
if cloned {
|
||||||
|
var err error
|
||||||
|
repoLinguist, err = ioutil.TempDir("", "linguist-")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
samplesDir = filepath.Join(repoLinguist, "samples")
|
samplesDir = filepath.Join(repoLinguist, "samples")
|
||||||
|
|
||||||
cmd := exec.Command("git", "clone", linguistURL, repoLinguist)
|
if cloned {
|
||||||
if err := cmd.Run(); err != nil {
|
cmd := exec.Command("git", "clone", linguistURL, repoLinguist)
|
||||||
return err
|
if err := cmd.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
@ -68,7 +78,7 @@ func cloneLinguist(linguistURL string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command("git", "checkout", data.LinguistCommit)
|
cmd := exec.Command("git", "checkout", data.LinguistCommit)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const linguistURL = "https://github.com/github/linguist.git"
|
const linguistURL = "https://github.com/github/linguist.git"
|
||||||
|
const linguistClonedEnvVar = "ENRY_TEST_REPO"
|
||||||
|
|
||||||
type EnryTestSuite struct {
|
type EnryTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
repoLinguist string
|
repoLinguist string
|
||||||
samplesDir string
|
samplesDir string
|
||||||
|
cloned bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnryTestSuite(t *testing.T) {
|
func TestEnryTestSuite(t *testing.T) {
|
||||||
@ -28,14 +30,20 @@ func TestEnryTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (s *EnryTestSuite) SetupSuite() {
|
func (s *EnryTestSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
s.repoLinguist, err = ioutil.TempDir("", "linguist-")
|
s.repoLinguist = os.Getenv(linguistClonedEnvVar)
|
||||||
assert.NoError(s.T(), err)
|
s.cloned = s.repoLinguist == ""
|
||||||
|
if s.cloned {
|
||||||
|
s.repoLinguist, err = ioutil.TempDir("", "linguist-")
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
s.samplesDir = filepath.Join(s.repoLinguist, "samples")
|
s.samplesDir = filepath.Join(s.repoLinguist, "samples")
|
||||||
|
|
||||||
cmd := exec.Command("git", "clone", linguistURL, s.repoLinguist)
|
if s.cloned {
|
||||||
err = cmd.Run()
|
cmd := exec.Command("git", "clone", linguistURL, s.repoLinguist)
|
||||||
assert.NoError(s.T(), err)
|
err = cmd.Run()
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
@ -43,7 +51,7 @@ func (s *EnryTestSuite) SetupSuite() {
|
|||||||
err = os.Chdir(s.repoLinguist)
|
err = os.Chdir(s.repoLinguist)
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cmd = exec.Command("git", "checkout", data.LinguistCommit)
|
cmd := exec.Command("git", "checkout", data.LinguistCommit)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
@ -52,8 +60,10 @@ func (s *EnryTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *EnryTestSuite) TearDownSuite() {
|
func (s *EnryTestSuite) TearDownSuite() {
|
||||||
err := os.RemoveAll(s.repoLinguist)
|
if s.cloned {
|
||||||
assert.NoError(s.T(), err)
|
err := os.RemoveAll(s.repoLinguist)
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EnryTestSuite) TestGetLanguage() {
|
func (s *EnryTestSuite) TestGetLanguage() {
|
||||||
|
@ -13,7 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
lingustURL = "https://github.com/github/linguist.git"
|
linguistURL = "https://github.com/github/linguist.git"
|
||||||
|
linguistClonedEnvVar = "ENRY_TEST_REPO"
|
||||||
commit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68"
|
commit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68"
|
||||||
samplesDir = "samples"
|
samplesDir = "samples"
|
||||||
languagesFile = "lib/linguist/languages.yml"
|
languagesFile = "lib/linguist/languages.yml"
|
||||||
@ -80,6 +81,7 @@ const (
|
|||||||
type GeneratorTestSuite struct {
|
type GeneratorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
tmpLinguist string
|
tmpLinguist string
|
||||||
|
cloned bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratorTestSuite(t *testing.T) {
|
func TestGeneratorTestSuite(t *testing.T) {
|
||||||
@ -88,12 +90,15 @@ func TestGeneratorTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (s *GeneratorTestSuite) SetupSuite() {
|
func (s *GeneratorTestSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
s.tmpLinguist, err = ioutil.TempDir("", "linguist-")
|
s.tmpLinguist = os.Getenv(linguistClonedEnvVar)
|
||||||
assert.NoError(s.T(), err)
|
s.cloned = s.tmpLinguist == ""
|
||||||
|
if s.cloned {
|
||||||
cmd := exec.Command("git", "clone", lingustURL, s.tmpLinguist)
|
s.tmpLinguist, err = ioutil.TempDir("", "linguist-")
|
||||||
err = cmd.Run()
|
assert.NoError(s.T(), err)
|
||||||
assert.NoError(s.T(), err)
|
cmd := exec.Command("git", "clone", linguistURL, s.tmpLinguist)
|
||||||
|
err = cmd.Run()
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
@ -101,7 +106,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
err = os.Chdir(s.tmpLinguist)
|
err = os.Chdir(s.tmpLinguist)
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cmd = exec.Command("git", "checkout", commit)
|
cmd := exec.Command("git", "checkout", commit)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
@ -110,8 +115,10 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *GeneratorTestSuite) TearDownSuite() {
|
func (s *GeneratorTestSuite) TearDownSuite() {
|
||||||
err := os.RemoveAll(s.tmpLinguist)
|
if s.cloned {
|
||||||
assert.NoError(s.T(), err)
|
err := os.RemoveAll(s.tmpLinguist)
|
||||||
|
assert.NoError(s.T(), err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GeneratorTestSuite) TestGenerationFiles() {
|
func (s *GeneratorTestSuite) TestGenerationFiles() {
|
||||||
|
Loading…
Reference in New Issue
Block a user