[all-commits] [llvm/llvm-project] a7691d: [Testing] TestAST, a helper for writing straight-l...

Sam McCall via All-commits all-commits at lists.llvm.org
Thu Apr 21 12:47:02 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a7691dee2d3c0ea3f9f4d14c7e52f1359f23671c
      https://github.com/llvm/llvm-project/commit/a7691dee2d3c0ea3f9f4d14c7e52f1359f23671c
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2022-04-21 (Thu, 21 Apr 2022)

  Changed paths:
    M clang/include/clang/Basic/Diagnostic.h
    M clang/include/clang/Testing/CommandLineArgs.h
    A clang/include/clang/Testing/TestAST.h
    M clang/lib/Basic/Diagnostic.cpp
    M clang/lib/Testing/CMakeLists.txt
    M clang/lib/Testing/CommandLineArgs.cpp
    A clang/lib/Testing/TestAST.cpp
    M clang/unittests/Tooling/CMakeLists.txt
    M clang/unittests/Tooling/FixItTest.cpp
    M clang/unittests/Tooling/StandardLibraryTest.cpp

  Log Message:
  -----------
  [Testing] TestAST, a helper for writing straight-line AST tests

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.

Differential Revision: https://reviews.llvm.org/D123668




More information about the All-commits mailing list