Testing for result builder errors

Apple has created a great setup for developing macros, including tests for expected errors. I'm wishing for a similar thing for result builders, since you can also have compile-time errors if the result builder isn't used properly.

It's easier for macros, of course, because you can call the macro and check the result. Result builder errors pretty much rely on the compiler's own type checking.

I have a result builder that enforces some rules about element ordering (using various overloads of buildPartialBlock). I would love to have tests that verify that certain cases are in fact rejected, but that means having expected compile-time errors. At the moment I just have them commented out, and I un-comment them and check the errors manually. Has anyone come up with a good approach for this in automated tests?

1 Like