mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-08-08 09:07:54 +00:00
test: refactored to clarify Linguist cloning logic on codegen
This commit is contained in:
@@ -97,9 +97,9 @@ var (
|
|||||||
|
|
||||||
type GeneratorTestSuite struct {
|
type GeneratorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
tmpLinguist string
|
tmpLinguistDir string
|
||||||
cloned bool
|
isLinguistCloned bool
|
||||||
testCases []testCase
|
testCases []testCase
|
||||||
}
|
}
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
@@ -121,19 +121,19 @@ func Test_GeneratorTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (s *GeneratorTestSuite) maybeCloneLinguist() {
|
func (s *GeneratorTestSuite) maybeCloneLinguist() {
|
||||||
var err error
|
var err error
|
||||||
s.tmpLinguist = os.Getenv(linguistClonedEnvVar)
|
s.tmpLinguistDir = os.Getenv(linguistClonedEnvVar)
|
||||||
s.cloned = s.tmpLinguist == ""
|
s.isLinguistCloned = s.tmpLinguistDir != ""
|
||||||
if s.cloned {
|
if !s.isLinguistCloned {
|
||||||
s.tmpLinguist, err = ioutil.TempDir("", "linguist-")
|
s.tmpLinguistDir, err = ioutil.TempDir("", "linguist-")
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
cmd := exec.Command("git", "clone", linguistURL, s.tmpLinguist)
|
cmd := exec.Command("git", "clone", linguistURL, s.tmpLinguistDir)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
err = os.Chdir(s.tmpLinguist)
|
err = os.Chdir(s.tmpLinguistDir)
|
||||||
assert.NoError(s.T(), err)
|
assert.NoError(s.T(), err)
|
||||||
|
|
||||||
cmd = exec.Command("git", "checkout", commit)
|
cmd = exec.Command("git", "checkout", commit)
|
||||||
@@ -150,7 +150,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
s.testCases = []testCase{
|
s.testCases = []testCase{
|
||||||
{
|
{
|
||||||
name: "Extensions()",
|
name: "Extensions()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: extensionTestTmplPath,
|
tmplPath: extensionTestTmplPath,
|
||||||
tmplName: extensionTestTmplName,
|
tmplName: extensionTestTmplName,
|
||||||
@@ -160,7 +160,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Heuristics()",
|
name: "Heuristics()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, heuristicsTestFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, heuristicsTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: contentTestTmplPath,
|
tmplPath: contentTestTmplPath,
|
||||||
tmplName: contentTestTmplName,
|
tmplName: contentTestTmplName,
|
||||||
@@ -170,7 +170,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Vendor()",
|
name: "Vendor()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, vendorTestFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, vendorTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: vendorTestTmplPath,
|
tmplPath: vendorTestTmplPath,
|
||||||
tmplName: vendorTestTmplName,
|
tmplName: vendorTestTmplName,
|
||||||
@@ -180,7 +180,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Documentation()",
|
name: "Documentation()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, documentationTestFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, documentationTestFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: documentationTestTmplPath,
|
tmplPath: documentationTestTmplPath,
|
||||||
tmplName: documentationTestTmplName,
|
tmplName: documentationTestTmplName,
|
||||||
@@ -190,7 +190,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Types()",
|
name: "Types()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: typeTestTmplPath,
|
tmplPath: typeTestTmplPath,
|
||||||
tmplName: typeTestTmplName,
|
tmplName: typeTestTmplName,
|
||||||
@@ -200,7 +200,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Interpreters()",
|
name: "Interpreters()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: interpreterTestTmplPath,
|
tmplPath: interpreterTestTmplPath,
|
||||||
tmplName: interpreterTestTmplName,
|
tmplName: interpreterTestTmplName,
|
||||||
@@ -210,8 +210,8 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Filenames()",
|
name: "Filenames()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: filepath.Join(s.tmpLinguist, samplesDir),
|
samplesDir: filepath.Join(s.tmpLinguistDir, samplesDir),
|
||||||
tmplPath: filenameTestTmplPath,
|
tmplPath: filenameTestTmplPath,
|
||||||
tmplName: filenameTestTmplName,
|
tmplName: filenameTestTmplName,
|
||||||
commit: commit,
|
commit: commit,
|
||||||
@@ -220,7 +220,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Aliases()",
|
name: "Aliases()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: aliasTestTmplPath,
|
tmplPath: aliasTestTmplPath,
|
||||||
tmplName: aliasTestTmplName,
|
tmplName: aliasTestTmplName,
|
||||||
@@ -230,7 +230,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Frequencies()",
|
name: "Frequencies()",
|
||||||
samplesDir: filepath.Join(s.tmpLinguist, samplesDir),
|
samplesDir: filepath.Join(s.tmpLinguistDir, samplesDir),
|
||||||
tmplPath: frequenciesTestTmplPath,
|
tmplPath: frequenciesTestTmplPath,
|
||||||
tmplName: frequenciesTestTmplName,
|
tmplName: frequenciesTestTmplName,
|
||||||
commit: commit,
|
commit: commit,
|
||||||
@@ -248,7 +248,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "MimeType()",
|
name: "MimeType()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: mimeTypeTestTmplPath,
|
tmplPath: mimeTypeTestTmplPath,
|
||||||
tmplName: mimeTypeTestTmplName,
|
tmplName: mimeTypeTestTmplName,
|
||||||
@@ -258,7 +258,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Colors()",
|
name: "Colors()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: colorsTestTmplPath,
|
tmplPath: colorsTestTmplPath,
|
||||||
tmplName: colorsTestTmplName,
|
tmplName: colorsTestTmplName,
|
||||||
@@ -268,7 +268,7 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Groups()",
|
name: "Groups()",
|
||||||
fileToParse: filepath.Join(s.tmpLinguist, languagesFile),
|
fileToParse: filepath.Join(s.tmpLinguistDir, languagesFile),
|
||||||
samplesDir: "",
|
samplesDir: "",
|
||||||
tmplPath: groupsTestTmplPath,
|
tmplPath: groupsTestTmplPath,
|
||||||
tmplName: groupsTestTmplName,
|
tmplName: groupsTestTmplName,
|
||||||
@@ -280,10 +280,10 @@ func (s *GeneratorTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *GeneratorTestSuite) TearDownSuite() {
|
func (s *GeneratorTestSuite) TearDownSuite() {
|
||||||
if s.cloned {
|
if s.isLinguistCloned {
|
||||||
err := os.RemoveAll(s.tmpLinguist)
|
err := os.RemoveAll(s.tmpLinguistDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.T().Logf("Failed to clean up %s after the test.\n", s.tmpLinguist)
|
s.T().Logf("Failed to clean up %s after the test.\n", s.tmpLinguistDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ func (s *GeneratorTestSuite) TestGenerationFiles() {
|
|||||||
|
|
||||||
func (s *GeneratorTestSuite) TestTokenizerOnATS() {
|
func (s *GeneratorTestSuite) TestTokenizerOnATS() {
|
||||||
const suspiciousSample = "samples/ATS/csv_parse.hats"
|
const suspiciousSample = "samples/ATS/csv_parse.hats"
|
||||||
sFile := filepath.Join(s.tmpLinguist, suspiciousSample)
|
sFile := filepath.Join(s.tmpLinguistDir, suspiciousSample)
|
||||||
content, err := ioutil.ReadFile(sFile)
|
content, err := ioutil.ReadFile(sFile)
|
||||||
require.NoError(s.T(), err)
|
require.NoError(s.T(), err)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user