mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
changes to improve detection accuracy
This commit is contained in:
@ -13,60 +13,55 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
lingustURL = "https://github.com/github/linguist.git"
|
||||
commitTree = "60f864a138650dd17fafc94814be9ee2d3aaef8c"
|
||||
commitTest = "0123456789abcdef0123456789abcdef01234567"
|
||||
lingustURL = "https://github.com/github/linguist.git"
|
||||
commit = "b6460f8ed6b249281ada099ca28bd8f1230b8892"
|
||||
samplesDir = "samples"
|
||||
languagesFile = "lib/linguist/languages.yml"
|
||||
|
||||
// Extensions test
|
||||
extensionsTestFile = "test_files/extensions.test.yml"
|
||||
extensionsGold = "test_files/extensions.gold"
|
||||
extensionsTestTmplPath = "../assets/extensions.go.tmpl"
|
||||
extensionsTestTmplName = "extensions.go.tmpl"
|
||||
extensionGold = "test_files/extension.gold"
|
||||
extensionTestTmplPath = "../assets/extension.go.tmpl"
|
||||
extensionTestTmplName = "extension.go.tmpl"
|
||||
|
||||
// Heuristics test
|
||||
heuristicsTestFile = "test_files/heuristics.test.rb"
|
||||
heuristicsTestFile = "lib/linguist/heuristics.rb"
|
||||
contentGold = "test_files/content.gold"
|
||||
contentTestTmplPath = "../assets/content.go.tmpl"
|
||||
contentTestTmplName = "content.go.tmpl"
|
||||
|
||||
// Vendor test
|
||||
vendorTestFile = "test_files/vendor.test.yml"
|
||||
vendorTestFile = "lib/linguist/vendor.yml"
|
||||
vendorGold = "test_files/vendor.gold"
|
||||
vendorTestTmplPath = "../assets/vendor.go.tmpl"
|
||||
vendorTestTmplName = "vendor.go.tmpl"
|
||||
|
||||
// Documentation test
|
||||
documentationTestFile = "test_files/documentation.test.yml"
|
||||
documentationTestFile = "lib/linguist/documentation.yml"
|
||||
documentationGold = "test_files/documentation.gold"
|
||||
documentationTestTmplPath = "../assets/documentation.go.tmpl"
|
||||
documentationTestTmplName = "documentation.go.tmpl"
|
||||
|
||||
// Types test
|
||||
typesTestFile = "test_files/types.test.yml"
|
||||
typesGold = "test_files/types.gold"
|
||||
typesTestTmplPath = "../assets/types.go.tmpl"
|
||||
typesTestTmplName = "types.go.tmpl"
|
||||
typeGold = "test_files/type.gold"
|
||||
typeTestTmplPath = "../assets/type.go.tmpl"
|
||||
typeTestTmplName = "type.go.tmpl"
|
||||
|
||||
// Interpreters test
|
||||
interpretersTestFile = "test_files/interpreters.test.yml"
|
||||
interpretersGold = "test_files/interpreters.gold"
|
||||
interpretersTestTmplPath = "../assets/interpreters.go.tmpl"
|
||||
interpretersTestTmplName = "interpreters.go.tmpl"
|
||||
interpreterGold = "test_files/interpreter.gold"
|
||||
interpreterTestTmplPath = "../assets/interpreter.go.tmpl"
|
||||
interpreterTestTmplName = "interpreter.go.tmpl"
|
||||
|
||||
// Filenames test
|
||||
filenamesTestFile = "test_files/filenames.test.yml"
|
||||
filenamesGold = "test_files/filenames.gold"
|
||||
filenamesTestTmplPath = "../assets/filenames.go.tmpl"
|
||||
filenamesTestTmplName = "filenames.go.tmpl"
|
||||
filenameGold = "test_files/filename.gold"
|
||||
filenameTestTmplPath = "../assets/filename.go.tmpl"
|
||||
filenameTestTmplName = "filename.go.tmpl"
|
||||
|
||||
// Aliases test
|
||||
aliasesTestFile = "test_files/aliases.test.yml"
|
||||
aliasesGold = "test_files/aliases.gold"
|
||||
aliasesTestTmplPath = "../assets/aliases.go.tmpl"
|
||||
aliasesTestTmplName = "aliases.go.tmpl"
|
||||
aliasGold = "test_files/alias.gold"
|
||||
aliasTestTmplPath = "../assets/alias.go.tmpl"
|
||||
aliasTestTmplName = "alias.go.tmpl"
|
||||
|
||||
// Frequencies test
|
||||
frequenciesTestDir = "/samples"
|
||||
frequenciesGold = "test_files/frequencies.gold"
|
||||
frequenciesTestTmplPath = "../assets/frequencies.go.tmpl"
|
||||
frequenciesTestTmplName = "frequencies.go.tmpl"
|
||||
@ -96,7 +91,7 @@ func (g *GeneratorTestSuite) SetupSuite() {
|
||||
err = os.Chdir(tmpLinguist)
|
||||
assert.NoError(g.T(), err)
|
||||
|
||||
cmd = exec.Command("git", "checkout", commitTree)
|
||||
cmd = exec.Command("git", "checkout", commit)
|
||||
err = cmd.Run()
|
||||
assert.NoError(g.T(), err)
|
||||
|
||||
@ -109,87 +104,105 @@ func (g *GeneratorTestSuite) TearDownSuite() {
|
||||
assert.NoError(g.T(), err)
|
||||
}
|
||||
|
||||
func (g *GeneratorTestSuite) TestFromFile() {
|
||||
func (g *GeneratorTestSuite) TestGenerationFiles() {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileToParse string
|
||||
samplesDir string
|
||||
tmplPath string
|
||||
tmplName string
|
||||
commit string
|
||||
generate Func
|
||||
generate File
|
||||
wantOut string
|
||||
}{
|
||||
{
|
||||
name: "TestFromFile_Extensions",
|
||||
fileToParse: extensionsTestFile,
|
||||
tmplPath: extensionsTestTmplPath,
|
||||
tmplName: extensionsTestTmplName,
|
||||
commit: commitTest,
|
||||
name: "Extensions()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
||||
samplesDir: "",
|
||||
tmplPath: extensionTestTmplPath,
|
||||
tmplName: extensionTestTmplName,
|
||||
commit: commit,
|
||||
generate: Extensions,
|
||||
wantOut: extensionsGold,
|
||||
wantOut: extensionGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Heuristics",
|
||||
fileToParse: heuristicsTestFile,
|
||||
name: "Heuristics()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, heuristicsTestFile),
|
||||
samplesDir: "",
|
||||
tmplPath: contentTestTmplPath,
|
||||
tmplName: contentTestTmplName,
|
||||
commit: commitTest,
|
||||
commit: commit,
|
||||
generate: Heuristics,
|
||||
wantOut: contentGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Vendor",
|
||||
fileToParse: vendorTestFile,
|
||||
name: "Vendor()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, vendorTestFile),
|
||||
samplesDir: "",
|
||||
tmplPath: vendorTestTmplPath,
|
||||
tmplName: vendorTestTmplName,
|
||||
commit: commitTest,
|
||||
commit: commit,
|
||||
generate: Vendor,
|
||||
wantOut: vendorGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Documentation",
|
||||
fileToParse: documentationTestFile,
|
||||
name: "Documentation()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, documentationTestFile),
|
||||
samplesDir: "",
|
||||
tmplPath: documentationTestTmplPath,
|
||||
tmplName: documentationTestTmplName,
|
||||
commit: commitTest,
|
||||
commit: commit,
|
||||
generate: Documentation,
|
||||
wantOut: documentationGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Types",
|
||||
fileToParse: typesTestFile,
|
||||
tmplPath: typesTestTmplPath,
|
||||
tmplName: typesTestTmplName,
|
||||
commit: commitTest,
|
||||
name: "Types()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
||||
samplesDir: "",
|
||||
tmplPath: typeTestTmplPath,
|
||||
tmplName: typeTestTmplName,
|
||||
commit: commit,
|
||||
generate: Types,
|
||||
wantOut: typesGold,
|
||||
wantOut: typeGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Interpreters",
|
||||
fileToParse: interpretersTestFile,
|
||||
tmplPath: interpretersTestTmplPath,
|
||||
tmplName: interpretersTestTmplName,
|
||||
commit: commitTest,
|
||||
name: "Interpreters()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
||||
samplesDir: "",
|
||||
tmplPath: interpreterTestTmplPath,
|
||||
tmplName: interpreterTestTmplName,
|
||||
commit: commit,
|
||||
generate: Interpreters,
|
||||
wantOut: interpretersGold,
|
||||
wantOut: interpreterGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Filenames",
|
||||
fileToParse: filenamesTestFile,
|
||||
tmplPath: filenamesTestTmplPath,
|
||||
tmplName: filenamesTestTmplName,
|
||||
commit: commitTest,
|
||||
name: "Filenames()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
||||
samplesDir: filepath.Join(g.tmpLinguist, samplesDir),
|
||||
tmplPath: filenameTestTmplPath,
|
||||
tmplName: filenameTestTmplName,
|
||||
commit: commit,
|
||||
generate: Filenames,
|
||||
wantOut: filenamesGold,
|
||||
wantOut: filenameGold,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Aliases",
|
||||
fileToParse: aliasesTestFile,
|
||||
tmplPath: aliasesTestTmplPath,
|
||||
tmplName: aliasesTestTmplName,
|
||||
commit: commitTest,
|
||||
name: "Aliases()",
|
||||
fileToParse: filepath.Join(g.tmpLinguist, languagesFile),
|
||||
samplesDir: "",
|
||||
tmplPath: aliasTestTmplPath,
|
||||
tmplName: aliasTestTmplName,
|
||||
commit: commit,
|
||||
generate: Aliases,
|
||||
wantOut: aliasesGold,
|
||||
wantOut: aliasGold,
|
||||
},
|
||||
{
|
||||
name: "Frequencies()",
|
||||
samplesDir: filepath.Join(g.tmpLinguist, samplesDir),
|
||||
tmplPath: frequenciesTestTmplPath,
|
||||
tmplName: frequenciesTestTmplName,
|
||||
commit: commit,
|
||||
generate: Frequencies,
|
||||
wantOut: frequenciesGold,
|
||||
},
|
||||
}
|
||||
|
||||
@ -201,45 +214,10 @@ func (g *GeneratorTestSuite) TestFromFile() {
|
||||
assert.NoError(g.T(), err)
|
||||
defer os.Remove(outPath.Name())
|
||||
|
||||
err = FromFile(test.fileToParse, outPath.Name(), test.tmplPath, test.tmplName, test.commit, test.generate)
|
||||
err = test.generate(test.fileToParse, test.samplesDir, outPath.Name(), test.tmplPath, test.tmplName, test.commit)
|
||||
assert.NoError(g.T(), err)
|
||||
out, err := ioutil.ReadFile(outPath.Name())
|
||||
assert.NoError(g.T(), err)
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(test.wantOut)))
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GeneratorTestSuite) TestFrequencies() {
|
||||
tests := []struct {
|
||||
name string
|
||||
samplesDir string
|
||||
tmplPath string
|
||||
tmplName string
|
||||
commit string
|
||||
wantOut string
|
||||
}{
|
||||
{
|
||||
name: "Frequencies_1",
|
||||
samplesDir: filepath.Join(g.tmpLinguist, frequenciesTestDir),
|
||||
tmplPath: frequenciesTestTmplPath,
|
||||
tmplName: frequenciesTestTmplName,
|
||||
commit: commitTree,
|
||||
wantOut: frequenciesGold,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
gold, err := ioutil.ReadFile(test.wantOut)
|
||||
assert.NoError(g.T(), err)
|
||||
|
||||
outPath, err := ioutil.TempFile("/tmp", "frequencies-test-")
|
||||
assert.NoError(g.T(), err)
|
||||
defer os.Remove(outPath.Name())
|
||||
|
||||
err = Frequencies(test.samplesDir, test.tmplPath, test.tmplName, test.commit, outPath.Name())
|
||||
assert.NoError(g.T(), err)
|
||||
out, err := ioutil.ReadFile(outPath.Name())
|
||||
assert.NoError(g.T(), err)
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(test.wantOut)))
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(gold)))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user