Skip to content

Commit 51a6725

Browse files
committed
cm: verify dependencies
Package cm should only depend on structs and unsafe.
1 parent 3e38a9f commit 51a6725

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cm/case.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cm
22

3-
import "errors"
4-
53
// CaseUnmarshaler returns an function that can unmarshal text into
64
// [variant] or [enum] case T.
75
//
@@ -46,6 +44,14 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
4644
const linearScanThreshold = 16
4745

4846
var (
49-
errEmpty = errors.New("empty text")
50-
errNoMatchingCase = errors.New("no matching case")
47+
errEmpty = &stringError{"empty text"}
48+
errNoMatchingCase = &stringError{"no matching case"}
5149
)
50+
51+
type stringError struct {
52+
err string
53+
}
54+
55+
func (err *stringError) Error() string {
56+
return err.err
57+
}

cm/dependencies_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !wasm
1+
//go:build !wasip1 && !wasip2 && !tinygo
22

33
package cm
44

@@ -15,11 +15,12 @@ func TestDependencies(t *testing.T) {
1515
cmd.Stdout = stdout
1616
err := cmd.Run()
1717
if err != nil {
18-
t.Fatal(err)
18+
t.Error(err)
19+
return
1920
}
2021

2122
got := strings.TrimSpace(stdout.String())
22-
const want = "[errors structs unsafe]" // Should not include "encoding/json"
23+
const want = "[structs unsafe]" // Should not include "encoding/json"
2324
if got != want {
2425
t.Errorf("Expected dependencies %s, got %s", want, got)
2526
}

0 commit comments

Comments
 (0)