Trying to write or maintain test code for AST dumping of JSON information can be onerous due to small changes in the test requiring a large amount of line numbers or other information to be updated in the expected test output. To help with this, we devised a simple python script that automatically generates the expected output and appends it to the end of a test file.
The script allows you to specify the clang instance to run, clang command line options used within test file, the source file to generate the test output from, and a filter in case you wish to only generate test output for specific AST JSON nodes.
For instance, you can execute python gen_ast_dump_json_test.py --clang D:\trunk_build\build\x64-Debug\bin\clang.exe --opts "-triple x86_64-unknown-unknown -std=gnu11" --source ast-dump-expr-json.c --filters FunctionDecl to generate the test output seen in ast-dump-expr-json.c. The script also works when passing -ast-dump-filter in the options to generate the output.