v / vlib / sokol / gfx / gfx_test.v
29 lines · 25 sloc · 807 bytes · dca4a2ef662b7b9401b455c0bceaebf46ebdeebc
Raw
1// vtest build: !msvc
2// vtest flaky: true
3// vtest retry: 1
4module gfx
5
6import os
7
8fn assert_program_panics(source string, expected string) {
9 source_path := os.join_path(os.temp_dir(),
10 'sokol_gfx_make_image_requires_setup_${os.getpid()}.v')
11 os.write_file(source_path, source) or { panic(err) }
12 defer {
13 os.rm(source_path) or {}
14 }
15 res := os.execute('${os.quoted_path(@VEXE)} run ${os.quoted_path(source_path)}')
16 assert res.exit_code != 0, 'expected the test program to fail'
17 assert res.output.contains(expected), 'expected `${expected}` in `${res.output}`'
18}
19
20fn test_make_image_requires_setup() {
21 assert_program_panics('import sokol.gfx
22
23fn main() {
24 mut desc := gfx.ImageDesc{}
25 _ = gfx.make_image(&desc)
26}
27',
28 'sokol.gfx is not initialized; call gfx.setup(...) before gfx.make_image(...)')
29}
30