This is an archive of the discontinued LLVM Phabricator instance.

Script for generating AST JSON dump test cases
ClosedPublic

Authored by aaron.ballman on Jun 18 2019, 6:21 AM.

Details

Reviewers
rsmith
Summary

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.

Diff Detail

Event Timeline

aaron.ballman created this revision.Jun 18 2019, 6:21 AM
rsmith accepted this revision.Jun 18 2019, 11:45 AM

Thanks!

I think we can maybe make this a little more convenient to use. For the non-JSON -ast-dump format, I added utils/make-ast-dump-check.sh which can be used as (for example):

$ lit -DFileCheck=$PWD/utils/make-ast-dump-check.sh test/AST/ast-dump-openmp-*

That is: run the tests, and instead of piping their output through FileCheck, run it through a script that converts the actual output into test expectations. That way, the script doesn't need to run clang (or know what command-line arguments would be used to do so); lit does that for you. I don't think that approach would be able to provide your --filters flag, but maybe that could be passed in as part of the -D?

This revision is now accepted and ready to land.Jun 18 2019, 11:45 AM
aaron.ballman closed this revision.Jun 19 2019, 8:23 AM

Committed in r363820; we'll look into integrating the script into lit as you suggested for a possible follow-up.