[PATCH] D123668: [Testing] TestAST, a helper for writing straight-line AST tests

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 13 04:10:31 PDT 2022


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, mgorny.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

Tests that need ASTs have to deal with the awkward control flow of
FrontendAction in some way. There are a few idioms used:

- don't bother with unit tests, use clang -dump-ast
- create an ASTConsumer by hand, which is bulky
- use ASTMatchFinder - works pretty well if matchers are actually needed, very strange if they are not
- use ASTUnit - this yields nice straight-line code, but ASTUnit is a terrifically complicated library not designed for this purpose

TestAST provides a very simple way to write straight-line tests: specify
the code/flags and it provides an AST that is kept alive until the
object is destroyed.
It's loosely modeled after TestTU in clangd, which we've successfully
used for a variety of tests.

I've updated a couple of clang tests to use this helper, IMO they're clearer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123668

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/include/clang/Testing/CommandLineArgs.h
  clang/include/clang/Testing/TestAST.h
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Testing/CMakeLists.txt
  clang/lib/Testing/CommandLineArgs.cpp
  clang/lib/Testing/TestAST.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/FixItTest.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123668.422467.patch
Type: text/x-patch
Size: 31837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220413/2efb6432/attachment-0001.bin>


More information about the cfe-commits mailing list