1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 00:57:15 +03:00

windows: Unbreak tests

Normalize OS specific errors paths to make difftests work

Related to #21
This commit is contained in:
Mattias Wadman 2022-01-04 22:09:50 +01:00
parent a41f0d4b5f
commit bf9e13c85a

View File

@ -3,6 +3,7 @@ package script
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"io"
"io/fs"
@ -284,6 +285,15 @@ func (c *Case) ToActual() string {
return sb.String()
}
func normalizeOSError(err error) error {
var pe *os.PathError
if errors.As(err, &pe) {
pe.Err = errors.New("no such file or directory")
pe.Path = filepath.ToSlash(pe.Path)
}
return err
}
func (c *Case) Open(name string) (fs.File, error) {
for _, p := range c.Parts {
f, ok := p.(*caseFile)
@ -297,7 +307,10 @@ func (c *Case) Open(name string) (fs.File, error) {
}, nil
}
}
return os.Open(filepath.Join(filepath.Dir(c.Path), name))
f, err := os.Open(filepath.Join(filepath.Dir(c.Path), name))
// normalizeOSError is used to normalize OS specific path and messages into the ones unix uses
// this needed to make difftest work
return f, normalizeOSError(err)
}
type Section struct {