Skip to content

Commit 07f9b8b

Browse files
committed
internal/fudgepb: Make tests work on other archs
1 parent 67f5fae commit 07f9b8b

12 files changed

+59
-47
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module github.com/rossmacarthur/fudge
33
go 1.20
44

55
require (
6+
github.com/dave/dst v0.27.2
67
github.com/sebdah/goldie/v2 v2.5.3
78
github.com/stretchr/testify v1.8.2
89
google.golang.org/grpc v1.53.0
910
google.golang.org/protobuf v1.29.1
1011
)
1112

1213
require (
13-
github.com/dave/dst v0.27.2 // indirect
1414
github.com/davecgh/go-spew v1.1.1 // indirect
1515
github.com/golang/protobuf v1.5.3 // indirect
1616
github.com/kr/pretty v0.3.0 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
22
github.com/dave/dst v0.27.2 h1:4Y5VFTkhGLC1oddtNwuxxe36pnyLxMFXT51FOzH8Ekc=
33
github.com/dave/dst v0.27.2/go.mod h1:jHh6EOibnHgcUW3WjKHisiooEkYwqpHLBSX1iOBhEyc=
4+
github.com/dave/jennifer v1.5.0 h1:HmgPN93bVDpkQyYbqhCHj5QlgvUkvEOzMyEvKLgCRrg=
45
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
67
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -42,6 +43,7 @@ golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
4243
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
4344
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
4445
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
46+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
4547
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
4648
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4749
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=

internal/fudgepb/fudgepb_test.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/rossmacarthur/fudge/errors"
1111
"github.com/sebdah/goldie/v2"
1212
"github.com/stretchr/testify/require"
13-
"google.golang.org/protobuf/encoding/protojson"
1413
)
1514

1615
var errSentinel = errors.Sentinel("such test", "TEST1234")
@@ -52,9 +51,9 @@ func TestFromProto(t *testing.T) {
5251
Line: 1576,
5352
},
5453
{
55-
File: "runtime/asm_arm64.s",
54+
File: "runtime/asm_arch.s",
5655
Function: "goexit",
57-
Line: 1172,
56+
Line: 1337,
5857
},
5958
},
6059
},
@@ -81,9 +80,9 @@ func TestFromProto(t *testing.T) {
8180
Line: 1576,
8281
},
8382
{
84-
File: "runtime/asm_arm64.s",
83+
File: "runtime/asm_arch.s",
8584
Function: "goexit",
86-
Line: 1172,
85+
Line: 1337,
8786
},
8887
},
8988
},
@@ -109,9 +108,9 @@ func TestFromProto(t *testing.T) {
109108
Line: 1576,
110109
},
111110
{
112-
File: "runtime/asm_arm64.s",
111+
File: "runtime/asm_arch.s",
113112
Function: "goexit",
114-
Line: 1172,
113+
Line: 1337,
115114
},
116115
},
117116
},
@@ -150,9 +149,9 @@ func TestFromProto(t *testing.T) {
150149
Line: 1576,
151150
},
152151
{
153-
File: "runtime/asm_arm64.s",
152+
File: "runtime/asm_arch.s",
154153
Function: "goexit",
155-
Line: 1172,
154+
Line: 1337,
156155
},
157156
},
158157
},
@@ -178,6 +177,12 @@ func TestFromProto(t *testing.T) {
178177
}
179178

180179
func TestToProto(t *testing.T) {
180+
dummyFrame := &Frame{
181+
File: "runtime/asm_arch.s",
182+
Function: "goexit",
183+
Line: 1337,
184+
}
185+
181186
tests := []struct {
182187
name string
183188
errFn func() error
@@ -239,9 +244,12 @@ func TestToProto(t *testing.T) {
239244
for _, tt := range tests {
240245
t.Run(tt.name, func(t *testing.T) {
241246
got := ToProto(tt.errFn())
242-
bytes, err := protojson.MarshalOptions{Multiline: true}.Marshal(got)
243-
require.Nil(t, err)
244-
g.Assert(t, tt.name, bytes)
247+
for _, hop := range got.Hops {
248+
if len(hop.Trace) > 0 {
249+
hop.Trace[len(hop.Trace)-1] = dummyFrame
250+
}
251+
}
252+
g.AssertJson(t, tt.name, got)
245253
})
246254
}
247255
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
such test
22
github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go:24 TestFromProto
33
testing/testing.go:1576 tRunner
4-
runtime/asm_arm64.s:1172 goexit
4+
runtime/asm_arch.s:1337 goexit
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
this hop: very wrap: such test
22
github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go:52 TestFromProto
33
testing/testing.go:1576 tRunner
4-
runtime/asm_arm64.s:1172 goexit
4+
runtime/asm_arch.s:1337 goexit

internal/fudgepb/testdata/TestToProto/fudge sentinel.golden

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
{
99
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1010
"function": "TestToProto.func8",
11-
"line": 222,
11+
"line": 227,
1212
"message": "very wrap"
1313
},
1414
{
1515
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1616
"function": "TestToProto.func10",
17-
"line": 241
17+
"line": 246
1818
},
1919
{
2020
"file": "testing/testing.go",
2121
"function": "tRunner",
2222
"line": 1576
2323
},
2424
{
25-
"file": "runtime/asm_arm64.s",
25+
"file": "runtime/asm_arch.s",
2626
"function": "goexit",
27-
"line": 1172
27+
"line": 1337
2828
}
2929
]
3030
}

internal/fudgepb/testdata/TestToProto/fudge with kvs.golden

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
{
88
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
99
"function": "TestToProto.func7",
10-
"line": 215,
10+
"line": 220,
1111
"message": "such test",
12-
"keyValues": [
12+
"key_values": [
1313
{
1414
"key": "hello",
1515
"value": "world"
@@ -19,9 +19,9 @@
1919
{
2020
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
2121
"function": "TestToProto.func7",
22-
"line": 216,
22+
"line": 221,
2323
"message": "very wrap",
24-
"keyValues": [
24+
"key_values": [
2525
{
2626
"key": "foo",
2727
"value": "bar"
@@ -31,17 +31,17 @@
3131
{
3232
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
3333
"function": "TestToProto.func10",
34-
"line": 241
34+
"line": 246
3535
},
3636
{
3737
"file": "testing/testing.go",
3838
"function": "tRunner",
3939
"line": 1576
4040
},
4141
{
42-
"file": "runtime/asm_arm64.s",
42+
"file": "runtime/asm_arch.s",
4343
"function": "goexit",
44-
"line": 1172
44+
"line": 1337
4545
}
4646
]
4747
}

internal/fudgepb/testdata/TestToProto/fudge wrapped.golden

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
{
88
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
99
"function": "TestToProto.func6",
10-
"line": 208,
10+
"line": 213,
1111
"message": "such test"
1212
},
1313
{
1414
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1515
"function": "TestToProto.func6",
16-
"line": 209,
16+
"line": 214,
1717
"message": "very wrap"
1818
},
1919
{
2020
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
2121
"function": "TestToProto.func10",
22-
"line": 241
22+
"line": 246
2323
},
2424
{
2525
"file": "testing/testing.go",
2626
"function": "tRunner",
2727
"line": 1576
2828
},
2929
{
30-
"file": "runtime/asm_arm64.s",
30+
"file": "runtime/asm_arch.s",
3131
"function": "goexit",
32-
"line": 1172
32+
"line": 1337
3333
}
3434
]
3535
}

internal/fudgepb/testdata/TestToProto/fudge.golden

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
{
88
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
99
"function": "TestToProto.func5",
10-
"line": 203,
10+
"line": 208,
1111
"message": "such test"
1212
},
1313
{
1414
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1515
"function": "TestToProto.func10",
16-
"line": 241
16+
"line": 246
1717
},
1818
{
1919
"file": "testing/testing.go",
2020
"function": "tRunner",
2121
"line": 1576
2222
},
2323
{
24-
"file": "runtime/asm_arm64.s",
24+
"file": "runtime/asm_arch.s",
2525
"function": "goexit",
26-
"line": 1172
26+
"line": 1337
2727
}
2828
]
2929
}

internal/fudgepb/testdata/TestToProto/std sentinel wrapped.golden

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
{
88
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
99
"function": "TestToProto.func4",
10-
"line": 199,
10+
"line": 204,
1111
"message": "very wrap"
1212
},
1313
{
1414
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1515
"function": "TestToProto.func10",
16-
"line": 241
16+
"line": 246
1717
},
1818
{
1919
"file": "testing/testing.go",
2020
"function": "tRunner",
2121
"line": 1576
2222
},
2323
{
24-
"file": "runtime/asm_arm64.s",
24+
"file": "runtime/asm_arch.s",
2525
"function": "goexit",
26-
"line": 1172
26+
"line": 1337
2727
}
2828
]
2929
},

internal/fudgepb/testdata/TestToProto/with hops.golden

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
{
88
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
99
"function": "TestToProto.func9",
10-
"line": 228,
10+
"line": 233,
1111
"message": "this hop"
1212
},
1313
{
1414
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
1515
"function": "TestToProto.func10",
16-
"line": 241
16+
"line": 246
1717
},
1818
{
1919
"file": "testing/testing.go",
2020
"function": "tRunner",
2121
"line": 1576
2222
},
2323
{
24-
"file": "runtime/asm_arm64.s",
24+
"file": "runtime/asm_arch.s",
2525
"function": "goexit",
26-
"line": 1172
26+
"line": 1337
2727
}
2828
]
2929
},
@@ -35,23 +35,23 @@
3535
{
3636
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
3737
"function": "TestToProto.func9",
38-
"line": 231,
38+
"line": 236,
3939
"message": "very wrap"
4040
},
4141
{
4242
"file": "github.com/rossmacarthur/fudge/internal/fudgepb/fudgepb_test.go",
4343
"function": "TestToProto.func10",
44-
"line": 241
44+
"line": 246
4545
},
4646
{
4747
"file": "testing/testing.go",
4848
"function": "tRunner",
4949
"line": 1576
5050
},
5151
{
52-
"file": "runtime/asm_arm64.s",
52+
"file": "runtime/asm_arch.s",
5353
"function": "goexit",
54-
"line": 1172
54+
"line": 1337
5555
}
5656
]
5757
}

internal/stack/stack.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Frame struct {
1212
Line int
1313
}
1414

15+
// Trace returns a stack trace, skipping the given number of frames
1516
func Trace(skip int) []Frame {
1617
var pcs [512]uintptr
1718
n := runtime.Callers(skip+1, pcs[:])
@@ -29,6 +30,7 @@ func Trace(skip int) []Frame {
2930
return trace
3031
}
3132

33+
// Call returns the frame of the caller, skipping the given number of frames
3234
func Call(skip int) Frame {
3335
var pcs [3]uintptr
3436
n := runtime.Callers(skip+1, pcs[:])

0 commit comments

Comments
 (0)