diff --git a/src/checker/check_language.go b/src/checker/check_language.go index 93f51e62..06fdb525 100644 --- a/src/checker/check_language.go +++ b/src/checker/check_language.go @@ -24,6 +24,7 @@ package checker import ( "github.com/murex/tcr/checker/model" + "github.com/murex/tcr/language" "github.com/murex/tcr/params" ) @@ -112,15 +113,7 @@ func checkLanguageSrcFiles(_ params.Params) (cp []model.CheckPoint) { if checkEnv.lang == nil { return cp } - srcFiles, err := checkEnv.lang.AllSrcFiles() - if err != nil { - cp = append(cp, model.ErrorCheckPoint(err)) - return cp - } - return model.CheckpointsForList( - "matching source files found:", - "no matching source file found", - srcFiles...) + return checkLanguageFiles("source", checkEnv.lang.AllSrcFiles) } func checkLanguageTestDirectories(_ params.Params) (cp []model.CheckPoint) { @@ -147,15 +140,31 @@ func checkLanguageTestFiles(_ params.Params) (cp []model.CheckPoint) { if checkEnv.lang == nil { return cp } - testFiles, err := checkEnv.lang.AllTestFiles() - if err != nil { + return checkLanguageFiles("test", checkEnv.lang.AllTestFiles) +} + +func checkLanguageFiles(desc string, fileSearcher func() ([]string, error)) (cp []model.CheckPoint) { + languageFiles, err := fileSearcher() + switch err := err.(type) { + case nil: + // do nothing + case *language.UnreachableDirectoryError: + // unreachable directories: we display a warning for each, then continue + for _, dir := range err.DirList() { + cp = append(cp, model.WarningCheckPoint( + "cannot access "+desc+" directory ", dir)) + } + default: + // unhandled errors cp = append(cp, model.ErrorCheckPoint(err)) return cp } - return model.CheckpointsForList( - "matching test files found:", - "no matching test file found", - testFiles...) + + cp = append(cp, model.CheckpointsForList( + "matching "+desc+" files found:", + "no matching "+desc+" file found", + languageFiles...)...) + return cp } func languageAsText() string { diff --git a/src/checker/check_language_test.go b/src/checker/check_language_test.go index a61a9c39..e19f442a 100644 --- a/src/checker/check_language_test.go +++ b/src/checker/check_language_test.go @@ -273,6 +273,33 @@ func Test_check_language_src_files(t *testing.T) { model.ErrorCheckPoint("some error"), }, }, + { + "unreachable directory error and no matching file", "xxx", + language.NewFakeLanguage("").WithAllSrcFiles( + func() ([]string, error) { + err := language.UnreachableDirectoryError{} + err.Add("dir1") + return nil, &err + }), + []model.CheckPoint{ + model.WarningCheckPoint("cannot access source directory dir1"), + model.WarningCheckPoint("no matching source file found"), + }, + }, + { + "unreachable directory error and one matching file", "xxx", + language.NewFakeLanguage("").WithAllSrcFiles( + func() ([]string, error) { + err := language.UnreachableDirectoryError{} + err.Add("dir1") + return []string{"src-file1"}, &err + }), + []model.CheckPoint{ + model.WarningCheckPoint("cannot access source directory dir1"), + model.OkCheckPoint("matching source files found:"), + model.OkCheckPoint("- src-file1"), + }, + }, } for _, test := range tests { t.Run(test.desc, func(t *testing.T) { @@ -430,6 +457,33 @@ func Test_check_language_test_files(t *testing.T) { model.ErrorCheckPoint("some error"), }, }, + { + "unreachable directory error and no matching file", "xxx", + language.NewFakeLanguage("").WithAllTestFiles( + func() ([]string, error) { + err := language.UnreachableDirectoryError{} + err.Add("dir1") + return nil, &err + }), + []model.CheckPoint{ + model.WarningCheckPoint("cannot access test directory dir1"), + model.WarningCheckPoint("no matching test file found"), + }, + }, + { + "unreachable directory error and one matching file", "xxx", + language.NewFakeLanguage("").WithAllTestFiles( + func() ([]string, error) { + err := language.UnreachableDirectoryError{} + err.Add("dir1") + return []string{"test-file1"}, &err + }), + []model.CheckPoint{ + model.WarningCheckPoint("cannot access test directory dir1"), + model.OkCheckPoint("matching test files found:"), + model.OkCheckPoint("- test-file1"), + }, + }, } for _, test := range tests { t.Run(test.desc, func(t *testing.T) { diff --git a/src/language/file_tree_filter.go b/src/language/file_tree_filter.go index 7472502a..3a74bab2 100644 --- a/src/language/file_tree_filter.go +++ b/src/language/file_tree_filter.go @@ -53,8 +53,8 @@ func (e *UnreachableDirectoryError) DirList() []string { return e.dirs } -// add adds directories to the list of unreachable directories -func (e *UnreachableDirectoryError) add(dir ...string) { +// Add adds directories to the list of unreachable directories +func (e *UnreachableDirectoryError) Add(dir ...string) { e.dirs = append(e.dirs, dir...) } @@ -123,7 +123,7 @@ func (ftf FileTreeFilter) findAllMatchingFiles(baseDir string) (files []string, for _, dir := range ftf.Directories { matchingFiles, err := ftf.findMatchingFilesInDir(baseDir, dir) if err != nil { - dirErr.add(filepath.Join(baseDir, dir)) + dirErr.Add(filepath.Join(baseDir, dir)) continue } files = append(files, matchingFiles...) diff --git a/src/language/file_tree_filter_test.go b/src/language/file_tree_filter_test.go index 700ceb21..92aad1a3 100644 --- a/src/language/file_tree_filter_test.go +++ b/src/language/file_tree_filter_test.go @@ -150,7 +150,7 @@ func Test_unreachable_directory_error(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { e := UnreachableDirectoryError{} - e.add(test.dirs...) + e.Add(test.dirs...) assert.Equal(t, test.dirs, e.DirList()) assert.Equal(t, test.expected, e.Error()) })