This seems a little fragile.
I don't think it is that fragile, currently we handle directives in 3 points in run_shader_tests(): 1. The first switch, where we detect that we stopped reading the block because a new block starts or the file ended. 2. The reading of the tags at the beginning of new blocks. 3. The reading of individual lines using a second switch.
We don't need to call update_line_number_context() in 1, and we always have to call it in 2 so we don't have to worry about forgetting to do so we add new functionalities.
It is only in 3 that we have to remember to call update_line_number_context() for the switch cases when we want to update the line number context for each line instead of presenting it at the beginning of the block, but even if we forget, the error will be reported at the beginning of the block because of 2.
Could we just track the starting line for things touching "shader_source" and then setup/restore the test context in e.g. compile_shader()?
Here is a patch for that proposal (how I see it), but I find it more complex.
[0001-tests-shader-runner-Report-compilation-errors-on-the.patch](/uploads/02a5639e5c17c001d23e1d89105c949b/0001-tests-shader-runner-Report-compilation-errors-on-the.patch)