Skip to content

Commit c863c3b

Browse files
committed
Rename RunOrPanic and BootOrPanic to MustRun and MustBoot
Must prefix is an idiomatic Go - for example regexp package has the MustCompile function. Many 3rd party libraries use similar convention. Additionally, MustRun has lower number of characters than RunOrPanic (which is usually good for public functions).
1 parent 627c46b commit c863c3b

File tree

18 files changed

+93
-92
lines changed

18 files changed

+93
-92
lines changed

examples/boot/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ func main() {
1111
pi.ScreenHeight = 44
1212

1313
// boot the game with custom screen resolution:
14-
pi.BootOrPanic()
14+
pi.MustBoot()
1515

1616
// once boot is executed all drawing functions are available:
1717
pi.Cursor(0, 18)
1818
pi.Print("TINY SCREEN", 7) // print text on the screen before game loop
1919

2020
// Run the game loop.
21-
pi.RunOrPanic()
21+
pi.MustRun()
2222
// Update and Draw functions were not set therefore screen will be fixed.
2323
}

examples/controller/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func main() {
3434
drawPlayerController(2, 67, 20)
3535
drawPlayerController(3, 67, 70)
3636
}
37-
pi.RunOrPanic()
37+
pi.MustRun()
3838
}
3939

4040
func drawPlayerController(player, x, y int) {

examples/hello/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ func main() {
2424
pi.Spr(i, x, 60+int(y))
2525
}
2626
}
27-
pi.RunOrPanic()
27+
pi.MustRun()
2828
}

examples/memory/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func main() {
1616
}
1717
}
1818

19-
pi.RunOrPanic()
19+
pi.MustRun()
2020
}

examples/pal/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ func draw() {
5858
func main() {
5959
pi.Resources = resources
6060
pi.Draw = draw
61-
pi.RunOrPanic()
61+
pi.MustRun()
6262
}

examples/print/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func main() {
1212
pi.Print("HELLO,", 9) // print yellow text and go to next line
1313
pi.Print("GOPHER!", 12)
1414
}
15-
pi.RunOrPanic()
15+
pi.MustRun()
1616
}

examples/shapes/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func main() {
8989
drawMousePointer()
9090
}
9191

92-
pi.RunOrPanic()
92+
pi.MustRun()
9393
}
9494

9595
func drawMousePointer() {

examples/trigonometry/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func main() {
2020
draw(96, 11, pi.Cos)
2121

2222
}
23-
pi.RunOrPanic()
23+
pi.MustRun()
2424
}
2525

2626
func draw(line int, color byte, f func(x float64) float64) {

internal/bench/screen_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func runBenchmarks(b *testing.B, callback func(res Resolution)) {
139139
b.Run(resolution.String(), func(b *testing.B) {
140140
pi.ScreenWidth = resolution.W
141141
pi.ScreenHeight = resolution.H
142-
pi.BootOrPanic()
142+
pi.MustBoot()
143143

144144
b.ReportAllocs()
145145
b.ResetTimer()

internal/fuzz/print_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func FuzzPrint(f *testing.F) {
1515
pi.ScreenWidth = 16
1616
pi.ScreenHeight = 24
17-
pi.BootOrPanic()
17+
pi.MustBoot()
1818
f.Fuzz(func(t *testing.T, x, y int) {
1919
pi.Cursor(x, y)
2020
pi.Print("A", color)

internal/fuzz/screen_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const color = 7
1616
func FuzzPset(f *testing.F) {
1717
pi.ScreenWidth = 16
1818
pi.ScreenHeight = 16
19-
pi.BootOrPanic()
19+
pi.MustBoot()
2020
f.Fuzz(func(t *testing.T, x, y int) {
2121
pi.Pset(x, y, color)
2222
})
@@ -25,7 +25,7 @@ func FuzzPset(f *testing.F) {
2525
func FuzzPget(f *testing.F) {
2626
pi.ScreenWidth = 16
2727
pi.ScreenHeight = 16
28-
pi.BootOrPanic()
28+
pi.MustBoot()
2929
f.Fuzz(func(t *testing.T, x, y int) {
3030
pi.Pget(x, y)
3131
})
@@ -34,7 +34,7 @@ func FuzzPget(f *testing.F) {
3434
func FuzzSprSizeFlip(f *testing.F) {
3535
pi.ScreenWidth = 16
3636
pi.ScreenHeight = 16
37-
pi.BootOrPanic()
37+
pi.MustBoot()
3838
f.Fuzz(func(t *testing.T, n, x, y int, w, h float64, flipX, flipY bool) {
3939
pi.SprSizeFlip(n, x, y, w, h, flipX, flipY)
4040
})

internal/fuzz/shape_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func FuzzRect(f *testing.F) {
1515
pi.ScreenWidth = 16
1616
pi.ScreenHeight = 16
17-
pi.BootOrPanic()
17+
pi.MustBoot()
1818
f.Fuzz(func(t *testing.T, x0, y0, x1, y1 int) {
1919
pi.Rect(x0, y0, x1, y1, color)
2020
})
@@ -23,7 +23,7 @@ func FuzzRect(f *testing.F) {
2323
func FuzzRectFill(f *testing.F) {
2424
pi.ScreenWidth = 16
2525
pi.ScreenHeight = 16
26-
pi.BootOrPanic()
26+
pi.MustBoot()
2727
f.Fuzz(func(t *testing.T, x0, y0, x1, y1 int) {
2828
pi.RectFill(x0, y0, x1, y1, color)
2929
})
@@ -32,7 +32,7 @@ func FuzzRectFill(f *testing.F) {
3232
func FuzzLine(f *testing.F) {
3333
pi.ScreenWidth = 16
3434
pi.ScreenHeight = 16
35-
pi.BootOrPanic()
35+
pi.MustBoot()
3636
f.Fuzz(func(t *testing.T, x0, y0, x1, y1 int) {
3737
pi.Line(x0, y0, x1, y1, color)
3838
})
@@ -41,7 +41,7 @@ func FuzzLine(f *testing.F) {
4141
func FuzzCirc(f *testing.F) {
4242
pi.ScreenWidth = 16
4343
pi.ScreenHeight = 16
44-
pi.BootOrPanic()
44+
pi.MustBoot()
4545
f.Fuzz(func(t *testing.T, x, y, r int) {
4646
pi.Circ(x, y, r, color)
4747
})
@@ -50,7 +50,7 @@ func FuzzCirc(f *testing.F) {
5050
func FuzzCircFill(f *testing.F) {
5151
pi.ScreenWidth = 16
5252
pi.ScreenHeight = 16
53-
pi.BootOrPanic()
53+
pi.MustBoot()
5454
f.Fuzz(func(t *testing.T, x, y, r int) {
5555
pi.CircFill(x, y, r, color)
5656
})

pi.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ func Run() error {
8080
return run()
8181
}
8282

83-
// RunOrPanic does the same as Run, but panics instead of returning an error.
83+
// MustRun does the same as Run, but panics instead of returning an error.
8484
//
8585
// Useful for writing unit tests and quick and dirty prototypes. Do not use on production ;)
86-
func RunOrPanic() {
86+
func MustRun() {
8787
if err := Run(); err != nil {
8888
panic(fmt.Sprintf("Something terrible happened! Pi cannot be run: %v\n", err))
8989
}
@@ -175,10 +175,10 @@ func loadResources(resources fs.ReadFileFS) error {
175175
return loadSpriteSheet(resources)
176176
}
177177

178-
// BootOrPanic does the same as Boot, but panics instead of returning an error.
178+
// MustBoot does the same as Boot, but panics instead of returning an error.
179179
//
180180
// Useful for writing unit tests and quick and dirty prototypes. Do not use on production ;)
181-
func BootOrPanic() {
181+
func MustBoot() {
182182
if err := Boot(); err != nil {
183183
panic("init failed " + err.Error())
184184
}

pi_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestBoot(t *testing.T) {
135135
pi.ScreenHeight = 8
136136
pi.SpriteSheetWidth = 8
137137
pi.SpriteSheetHeight = 8
138-
pi.BootOrPanic()
138+
pi.MustBoot()
139139
// when
140140
pi.ScreenWidth = 1
141141
pi.ScreenHeight = 1
@@ -161,7 +161,7 @@ func TestBoot(t *testing.T) {
161161
pi.Resources = fstest.MapFS{
162162
"sprite-sheet.png": &fstest.MapFile{Data: spriteSheet16x16},
163163
}
164-
pi.BootOrPanic()
164+
pi.MustBoot()
165165
assert.NotPanics(t, func() {
166166
pi.Spr(4, 0, 0) // sprite-sheet.png has only 4 sprites (from 0 to 3)
167167
pi.SprSize(4, 0, 0, 1.0, 1.0)

print_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestPrint(t *testing.T) {
2424
chars := []string{`!`, `A`, `b`, `AB`, `ABCD`}
2525
for _, char := range chars {
2626
t.Run(char, func(t *testing.T) {
27-
pi.BootOrPanic()
27+
pi.MustBoot()
2828
// when
2929
pi.Print(char, color)
3030
// then
@@ -34,25 +34,25 @@ func TestPrint(t *testing.T) {
3434
})
3535

3636
t.Run("should print question mark for characters > 255", func(t *testing.T) {
37-
pi.BootOrPanic()
37+
pi.MustBoot()
3838
pi.Print("\u0100", color)
3939
assertScreenEqual(t, "internal/testimage/print/unknown.png")
4040
})
4141

4242
t.Run("should print special character", func(t *testing.T) {
43-
pi.BootOrPanic()
43+
pi.MustBoot()
4444
pi.Print("\u0080", color)
4545
assertScreenEqual(t, "internal/testimage/print/special.png")
4646
})
4747

4848
t.Run("should print 2 special characters", func(t *testing.T) {
49-
pi.BootOrPanic()
49+
pi.MustBoot()
5050
pi.Print("\u0080\u0081", color)
5151
assertScreenEqual(t, "internal/testimage/print/special-2chars.png")
5252
})
5353

5454
t.Run("should go to next line", func(t *testing.T) {
55-
pi.BootOrPanic()
55+
pi.MustBoot()
5656
pi.Print("0L", color)
5757
pi.Print("1L", color)
5858
assertScreenEqual(t, "internal/testimage/print/two-lines.png")
@@ -68,7 +68,7 @@ func TestPrint(t *testing.T) {
6868
}
6969
for name, test := range tests {
7070
t.Run(name, func(t *testing.T) {
71-
pi.BootOrPanic()
71+
pi.MustBoot()
7272
pi.Cursor(test.x, test.y)
7373
pi.Print("0L", color)
7474
pi.Print("1L", color)
@@ -78,7 +78,7 @@ func TestPrint(t *testing.T) {
7878
})
7979

8080
t.Run("should print moved by camera position", func(t *testing.T) {
81-
pi.BootOrPanic()
81+
pi.MustBoot()
8282
pi.Camera(-1, -2)
8383
pi.Print("0L", color)
8484
pi.Print("1L", color)
@@ -108,7 +108,7 @@ func TestPrint(t *testing.T) {
108108

109109
for name, test := range tests {
110110
t.Run(name, func(t *testing.T) {
111-
pi.BootOrPanic()
111+
pi.MustBoot()
112112
pi.Camera(test.cameraX, test.cameraY)
113113
pi.Clip(test.x, test.y, test.w, test.h)
114114
pi.Cursor(test.cursorX, test.cursorY)
@@ -127,7 +127,7 @@ func TestPrint(t *testing.T) {
127127
}
128128
for name, function := range tests {
129129
t.Run(name, func(t *testing.T) {
130-
pi.BootOrPanic()
130+
pi.MustBoot()
131131
pi.Cursor(20, 20)
132132
// when
133133
function()
@@ -178,7 +178,7 @@ func TestPrint(t *testing.T) {
178178
}
179179
for name, test := range tests {
180180
t.Run(name, func(t *testing.T) {
181-
pi.BootOrPanic()
181+
pi.MustBoot()
182182
pi.ClsCol(3)
183183
pi.Cursor(test.cursorX, test.cursorY)
184184
// when
@@ -222,7 +222,7 @@ func TestPrint(t *testing.T) {
222222
}
223223
for name, test := range tests {
224224
t.Run(name, func(t *testing.T) {
225-
pi.BootOrPanic()
225+
pi.MustBoot()
226226
pi.ScreenData = decodePNG(t, "internal/testimage/print/multicolor.png").Pixels
227227
pi.Clip(test.clipX, test.clipY, test.clipW, test.clipH)
228228
pi.Cursor(0, test.cursorY)
@@ -248,7 +248,7 @@ func TestPrint(t *testing.T) {
248248
}
249249
for name, test := range tests {
250250
t.Run(name, func(t *testing.T) {
251-
pi.BootOrPanic()
251+
pi.MustBoot()
252252
// when
253253
x := pi.Print(test.text, color)
254254
assert.Equal(t, test.expectedX, x)
@@ -268,14 +268,14 @@ func assertScreenEqual(t *testing.T, file string) {
268268

269269
func TestCursor(t *testing.T) {
270270
t.Run("should return default cursor position", func(t *testing.T) {
271-
pi.BootOrPanic()
271+
pi.MustBoot()
272272
x, y := pi.Cursor(1, 1)
273273
assert.Zero(t, x)
274274
assert.Zero(t, y)
275275
})
276276

277277
t.Run("should return previous cursor position", func(t *testing.T) {
278-
pi.BootOrPanic()
278+
pi.MustBoot()
279279
prevX, prevY := 1, 2
280280
pi.Cursor(prevX, prevY)
281281
// when
@@ -287,14 +287,14 @@ func TestCursor(t *testing.T) {
287287

288288
func TestCursorReset(t *testing.T) {
289289
t.Run("should return default cursor position", func(t *testing.T) {
290-
pi.BootOrPanic()
290+
pi.MustBoot()
291291
x, y := pi.CursorReset()
292292
assert.Zero(t, x)
293293
assert.Zero(t, y)
294294
})
295295

296296
t.Run("should return previous cursor position", func(t *testing.T) {
297-
pi.BootOrPanic()
297+
pi.MustBoot()
298298
prevX, prevY := 1, 2
299299
pi.Cursor(prevX, prevY)
300300
// when

0 commit comments

Comments
 (0)