Skip to content

Commit

Permalink
Fix FileNotExist func (#119)
Browse files Browse the repository at this point in the history
* fix FileNotExist on abs path

* run generate
  • Loading branch information
alessio-perugini authored Apr 13, 2023
1 parent b4a8025 commit 3d0938a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/assertions/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,16 @@ func FileExistsFS(system fs.FS, file string) (s string) {

func FileNotExistsFS(system fs.FS, file string) (s string) {
_, err := fs.Stat(system, file)
if !errors.Is(err, fs.ErrNotExist) {
if err == nil {
s = "expected file to not exist\n"
s += bullet("name: %s\n", file)
return
}
if !errors.Is(err, fs.ErrNotExist) {
s = "expected not existing file but got different error\n"
s += bullet("error: %s\n", err)
return
}
return
}

Expand Down
5 changes: 4 additions & 1 deletion must/must.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"

Expand Down Expand Up @@ -519,7 +520,9 @@ func FileNotExistsFS(t T, system fs.FS, file string, settings ...Setting) {
// FileNotExists asserts file does not exist on the OS filesystem.
func FileNotExists(t T, file string, settings ...Setting) {
t.Helper()
invoke(t, assertions.FileNotExistsFS(os.DirFS(brokenfs.Root), file), settings...)
dir := filepath.Dir(file)
file = filepath.Base(file)
invoke(t, assertions.FileNotExistsFS(os.DirFS(dir), file), settings...)
}

// DirExistsFS asserts directory exists on the fs.FS filesystem.
Expand Down

0 comments on commit 3d0938a

Please sign in to comment.