This allows creating custom test formats on top of executeShTest that inject commands at the beginning of the file being parsed, without requiring these commands to physically appear in the test file itself.
For example, one could define a test format that prints out additional debug information at the beginning of each test. More realistically, this has been used to define custom test formats like one that supports compilation failure tests (e.g. with the extension compile.fail.cpp) by injecting a command that calls the compiler on the file itself and expects it to fail.
Without this change, the only alternative is to create a temporary file with the same content as the original test, then prepend the desired // RUN: lines to that file, and call executeShTest on that file instead. This is both slow and cumbersome to do.
I don't think extra_commands is a command good name. It's not obvious that these are injected as extra commands at the beginning. Here are a few name suggestions