-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
45 lines (37 loc) · 1.38 KB
/
Copy patherrors_test.go
File metadata and controls
45 lines (37 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2025 Julien Bisconti. All rights reserved.
// Derived from rsc.io/script and github.com/rogpeppe/go-internal/testscript.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package script
import (
"errors"
"io/fs"
"testing"
)
func TestWaitErrorUnwrapSingle(t *testing.T) {
inner := &CommandError{File: "test.txt", Line: 1, Op: "exec", Err: fs.ErrNotExist}
w := waitError{errs: []*CommandError{inner}}
if !errors.Is(w, fs.ErrNotExist) {
t.Error("errors.Is failed to find wrapped fs.ErrNotExist in single-error waitError")
}
var ce *CommandError
if !errors.As(w, &ce) {
t.Error("errors.As failed to find *CommandError in single-error waitError")
}
}
func TestWaitErrorUnwrapMultiple(t *testing.T) {
err1 := &CommandError{File: "test.txt", Line: 1, Op: "exec", Err: fs.ErrNotExist}
err2 := &CommandError{File: "test.txt", Line: 2, Op: "cat", Err: fs.ErrPermission}
w := waitError{errs: []*CommandError{err1, err2}}
// Both wrapped errors should be reachable.
if !errors.Is(w, fs.ErrNotExist) {
t.Error("errors.Is failed to find fs.ErrNotExist in multi-error waitError")
}
if !errors.Is(w, fs.ErrPermission) {
t.Error("errors.Is failed to find fs.ErrPermission in multi-error waitError")
}
var ce *CommandError
if !errors.As(w, &ce) {
t.Error("errors.As failed to find *CommandError in multi-error waitError")
}
}