From c87fb34cf481bf5b3901b1e5aa7f5950ca9b4131 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 23 Apr 2026 19:33:16 +0300 Subject: [PATCH] v.tests: fix Veb early return with $veb.html not working (fixes #25447) --- .../tests/veb_html_return_in_or_block_test.v | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vlib/v/tests/veb_html_return_in_or_block_test.v b/vlib/v/tests/veb_html_return_in_or_block_test.v index bb54ec0ca..438b224d8 100644 --- a/vlib/v/tests/veb_html_return_in_or_block_test.v +++ b/vlib/v/tests/veb_html_return_in_or_block_test.v @@ -20,6 +20,10 @@ fn get_order(valid bool) !Order { return error('missing order') } +fn should_return_early() bool { + return true +} + fn (mut app App) index(mut ctx Context) veb.Result { record := get_order(false) or { ctx.res.set_status(.not_found) @@ -30,6 +34,15 @@ fn (mut app App) index(mut ctx Context) veb.Result { return ctx.text('continued') } +fn (mut app App) if_return(mut ctx Context) veb.Result { + if should_return_early() { + ctx.res.set_status(.not_found) + return $veb.html('templates/veb_html_return_in_or_block_test.html') + } + app.continued = true + return $veb.html('templates/veb_html_return_in_or_block_test.html') +} + fn test_veb_html_return_in_or_block_does_not_continue() { mut app := App{} mut ctx := Context{} @@ -38,3 +51,12 @@ fn test_veb_html_return_in_or_block_does_not_continue() { assert ctx.res.status_code == 404 assert ctx.res.body.trim_space() == 'Order not found!' } + +fn test_veb_html_return_in_if_block_does_not_continue() { + mut app := App{} + mut ctx := Context{} + _ = app.if_return(mut ctx) + assert !app.continued + assert ctx.res.status_code == 404 + assert ctx.res.body.trim_space() == 'Order not found!' +} -- 2.39.5