blame it on ray

This commit is contained in:
Mark Bates 2019-09-01 15:42:22 -04:00
parent 9666017c2c
commit 926eafe520
5 changed files with 23 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.fstest
*.log
.DS_Store
doc

View File

@ -1,15 +1,13 @@
package fstest
import (
"path"
"github.com/markbates/pkger/fs"
)
func Files(fx fs.FileSystem) (TestFiles, error) {
tf := TestFiles{}
for _, f := range fileList {
pt, err := Path(fx, f)
pt, err := fx.Parse(f)
if err != nil {
return tf, err
}
@ -22,15 +20,6 @@ func Files(fx fs.FileSystem) (TestFiles, error) {
return tf, nil
}
func Path(fx fs.FileSystem, p string) (fs.Path, error) {
pt, err := fx.Parse(p)
if err != nil {
return pt, err
}
pt.Name = path.Join("/.fstest", pt.Name)
return pt, nil
}
var fileList = []string{
"/main.go",
"/go.mod",

View File

@ -3,6 +3,7 @@ package fstest
import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
@ -63,25 +64,26 @@ func (s *FileSystem) sub(t *testing.T, m reflect.Method) {
}
func (s *FileSystem) Clean() error {
pt, err := Path(s, "/")
pt, err := s.Parse("/")
if err != nil {
return err
}
if err := s.RemoveAll(pt.Name); err != nil {
return err
}
if _, err := s.Stat(pt.Name); err == nil {
return fmt.Errorf("expected %q to be, you know, not there any more", pt)
}
_ = pt
// if err := s.RemoveAll(pt.Name); err != nil {
// return err
// }
//
// if _, err := s.Stat(pt.Name); err == nil {
// return fmt.Errorf("expected %q to be, you know, not there any more", pt)
// }
return nil
}
func (s *FileSystem) Test_Create(t *testing.T) {
r := require.New(t)
pt, err := Path(s, "i/want/candy.song")
pt, err := s.Parse("/i/want/candy.song")
r.NoError(err)
f, err := s.Create(pt.Name)
@ -94,6 +96,7 @@ func (s *FileSystem) Test_Create(t *testing.T) {
r.Equal(pt.Name, fi.Name())
r.Equal(os.FileMode(0644), fi.Mode())
r.NotZero(fi.ModTime())
r.NoError(s.RemoveAll(pt.String()))
}
func (s *FileSystem) Test_Current(t *testing.T) {
@ -136,6 +139,7 @@ func (s *FileSystem) Test_Parse(t *testing.T) {
exp fs.Path
}{
{in: "/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: filepath.Join(cur.Dir, "foo.go"), exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip + ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip, exp: fs.Path{Pkg: ip, Name: "/"}},
@ -188,9 +192,7 @@ func (s *FileSystem) Test_Stat(t *testing.T) {
return
}
pt, err := Path(s, tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: tt.in ", tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: pt ", pt)
pt, err := s.Parse(tt.in)
r.NoError(err)
// r.Fail(pt.String())

View File

@ -134,7 +134,12 @@ func (f *FS) Walk(p string, wf filepath.WalkFunc) error {
}
func (f *FS) locate(p string) (string, error) {
return f.current.FilePath(p), nil
pt, err := f.Parse(p)
if err != nil {
return p, err
}
p = f.current.FilePath(pt.Name)
return p, nil
}
func (fx *FS) Remove(name string) error {

View File

@ -179,6 +179,7 @@ func (m *Paths) build(p, pkg, name string) (fs.Path, error) {
if !strings.HasPrefix(pt.Name, "/") {
pt.Name = "/" + pt.Name
}
pt.Name = strings.TrimPrefix(pt.Name, m.Current.Dir)
m.Store(p, pt)
return pt, nil
}