@@ -11,6 +11,7 @@ import (
11
11
"gopkg.in/src-d/enry.v1/data"
12
12
13
13
"github.com/stretchr/testify/assert"
14
+ "github.com/stretchr/testify/require"
14
15
"github.com/stretchr/testify/suite"
15
16
)
16
17
@@ -19,9 +20,35 @@ const linguistClonedEnvVar = "ENRY_TEST_REPO"
19
20
20
21
type EnryTestSuite struct {
21
22
suite.Suite
22
- repoLinguist string
23
- samplesDir string
24
- cloned bool
23
+ tmpLinguist string
24
+ needToClone bool
25
+ samplesDir string
26
+ }
27
+
28
+ func TestRegexpEdgeCases (t * testing.T ) {
29
+ var regexpEdgeCases = []struct {
30
+ lang string
31
+ filename string
32
+ }{
33
+ {lang : "ActionScript" , filename : "FooBar.as" },
34
+ {lang : "Forth" , filename : "asm.fr" },
35
+ {lang : "X PixMap" , filename : "cc-public_domain_mark_white.pm" },
36
+ //{lang: "SQL", filename: "drop_stuff.sql"}, // Classifier strategy fails :/
37
+ //{lang: "Fstar", filename: "Hacl.Spec.Bignum.Fmul.fst"}, // *.fst fails on GetLanguagesByExtension,
38
+ {lang : "C++" , filename : "Types.h" },
39
+ }
40
+
41
+ for _ , r := range regexpEdgeCases {
42
+ filename := fmt .Sprintf (".linguist/samples/%s/%s" , r .lang , r .filename )
43
+
44
+ content , err := ioutil .ReadFile (filename )
45
+ require .NoError (t , err )
46
+
47
+ lang := GetLanguage (r .filename , content )
48
+ t .Logf ("File:%s, lang:%s" , filename , lang )
49
+
50
+ assert .EqualValues (t , r .lang , lang )
51
+ }
25
52
}
26
53
27
54
func Test_EnryTestSuite (t * testing.T ) {
@@ -30,25 +57,24 @@ func Test_EnryTestSuite(t *testing.T) {
30
57
31
58
func (s * EnryTestSuite ) SetupSuite () {
32
59
var err error
33
- s .repoLinguist = os .Getenv (linguistClonedEnvVar )
34
- s .cloned = s .repoLinguist == ""
35
- if s .cloned {
36
- s .repoLinguist , err = ioutil .TempDir ("" , "linguist-" )
37
- assert .NoError (s .T (), err )
38
- }
39
-
40
- s .samplesDir = filepath .Join (s .repoLinguist , "samples" )
41
-
42
- if s .cloned {
43
- cmd := exec .Command ("git" , "clone" , linguistURL , s .repoLinguist )
60
+ s .tmpLinguist = os .Getenv (linguistClonedEnvVar )
61
+ s .needToClone = s .tmpLinguist == ""
62
+ if s .needToClone {
63
+ s .tmpLinguist , err = ioutil .TempDir ("" , "linguist-" )
64
+ require .NoError (s .T (), err )
65
+ fmt .Printf ("Cloning Linguist repo to '%s' as %s was not set\n " ,
66
+ s .tmpLinguist , linguistClonedEnvVar )
67
+ cmd := exec .Command ("git" , "clone" , linguistURL , s .tmpLinguist )
44
68
err = cmd .Run ()
45
- assert .NoError (s .T (), err )
69
+ require .NoError (s .T (), err )
46
70
}
71
+ s .samplesDir = filepath .Join (s .tmpLinguist , "samples" )
72
+ s .T ().Logf ("using samples from %s" , s .samplesDir )
47
73
48
74
cwd , err := os .Getwd ()
49
75
assert .NoError (s .T (), err )
50
76
51
- err = os .Chdir (s .repoLinguist )
77
+ err = os .Chdir (s .tmpLinguist )
52
78
assert .NoError (s .T (), err )
53
79
54
80
cmd := exec .Command ("git" , "checkout" , data .LinguistCommit )
@@ -60,8 +86,8 @@ func (s *EnryTestSuite) SetupSuite() {
60
86
}
61
87
62
88
func (s * EnryTestSuite ) TearDownSuite () {
63
- if s .cloned {
64
- err := os .RemoveAll (s .repoLinguist )
89
+ if s .needToClone {
90
+ err := os .RemoveAll (s .tmpLinguist )
65
91
assert .NoError (s .T (), err )
66
92
}
67
93
}
@@ -88,7 +114,7 @@ func (s *EnryTestSuite) TestGetLanguage() {
88
114
}
89
115
90
116
func (s * EnryTestSuite ) TestGetLanguagesByModelineLinguist () {
91
- var modelinesDir = filepath .Join (s .repoLinguist , "test/fixtures/Data/Modelines" )
117
+ var modelinesDir = filepath .Join (s .tmpLinguist , "test/fixtures/Data/Modelines" )
92
118
93
119
tests := []struct {
94
120
name string
@@ -400,7 +426,7 @@ func (s *EnryTestSuite) TestGetLanguageByAlias() {
400
426
func (s * EnryTestSuite ) TestLinguistCorpus () {
401
427
const filenamesDir = "filenames"
402
428
var cornerCases = map [string ]bool {
403
- "hello.ms" : true ,
429
+ "hello.ms" : true , //TODO add instead .es
404
430
}
405
431
406
432
var total , failed , ok , other int
@@ -443,5 +469,5 @@ func (s *EnryTestSuite) TestLinguistCorpus() {
443
469
return nil
444
470
})
445
471
446
- fmt . Printf ("\t \t total files: %d, ok: %d, failed: %d, other: %d\n " , total , ok , failed , other )
472
+ s . T (). Logf ("\t \t total files: %d, ok: %d, failed: %d, other: %d\n " , total , ok , failed , other )
447
473
}
0 commit comments