pkg/eval: Cover more tilde expansion errors.

This commit is contained in:
Qi Xiao 2022-06-20 00:08:20 +01:00
parent 6723b9a226
commit 786b679509
2 changed files with 6 additions and 3 deletions

View File

@ -173,8 +173,8 @@ func doTilde(v any) (any, error) {
}
_, isSlash := v.Segments[1].(glob.Slash)
if isSlash {
// ~username or ~username/xxx. Replace the first segment with
// the home directory of the specified user.
// ~username/xxx. Replace the first segment with the home
// directory of the specified user.
dir, err := getHome(seg.Data)
if err != nil {
return nil, err

View File

@ -92,7 +92,7 @@ func TestTilde(t *testing.T) {
case "other":
return otherHome, nil
default:
return "", fmt.Errorf("don't know home of %q", name)
return "", fmt.Errorf("don't know home of %v", name)
}
})
@ -109,6 +109,8 @@ func TestTilde(t *testing.T) {
// Regression test for #793.
That("put ~other/*").Puts(otherHome+"/other1", otherHome+"/other2"),
That("put ~bad/*").Throws(ErrorWithMessage("don't know home of bad"), "~bad/*"),
// TODO: This should be a compilation error.
That("put ~*").Throws(ErrCannotDetermineUsername, "~*"),
)
@ -121,6 +123,7 @@ func TestTilde_ErrorForCurrentUser(t *testing.T) {
Test(t,
That("put ~").Throws(err, "~"),
That("put ~/foo").Throws(err, "~/foo"),
That("put ~/*").Throws(err, "~/*"),
)
}