From f206e152e6b72fc6b6cc3d35e1d9b4f02a132dda Mon Sep 17 00:00:00 2001 From: Alex Bezzubov Date: Fri, 3 Mar 2023 23:14:06 +0100 Subject: [PATCH] test: refactor and simplify TestLinguistSamples test plan - go test -run '^Test_EnryOnLinguistCorpus$' github.com/go-enry/go-enry/v2 --- linguist_corpus_test.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/linguist_corpus_test.go b/linguist_corpus_test.go index a930dbf..a8856fd 100644 --- a/linguist_corpus_test.go +++ b/linguist_corpus_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/go-enry/go-enry/v2/data" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) @@ -45,25 +44,23 @@ func (s *linguistCorpusSuite) TestLinguistSamples() { content, _ := ioutil.ReadFile(path) total++ - obtained := GetLanguage(filename, content) - if obtained == OtherLanguage { - obtained = "Other" + got := GetLanguage(filename, content) + if got == OtherLanguage { + got = "Other" other++ } - var status string - if expected == obtained { - status = "ok" + if expected == got { ok++ } else { - status = "failed" failed++ } + errMsg := fmt.Sprintf("file: %q\texpected: %q\tgot: %q\n", path, expected, got) if _, ok := cornerCases[filename]; ok { - s.T().Logf("\t\t[considered corner case] %s\texpected: %s\tobtained: %s\tstatus: %s\n", filename, expected, obtained, status) + s.T().Logf(fmt.Sprintf("\t\t[corner case] %s", errMsg)) } else { - assert.Equal(s.T(), expected, obtained, fmt.Sprintf("%s\texpected: %s\tobtained: %s\tstatus: %s\n", filename, expected, obtained, status)) + s.Equal(expected, got, errMsg) } return nil })