[PATCH] D132513: [lit] Implement DEFINE and REDEFINE directives

Joel E. Denny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 15:44:51 PDT 2022


jdenny created this revision.
jdenny added reviewers: probinson, jhenderson, rnk, thopre, yln, asavonic, mehdi_amini.
Herald added a subscriber: delcypher.
Herald added a project: All.
jdenny requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Herald added a project: LLVM.

These directives define per-test lit substitutions.  The concept was 
discussed at
https://discourse.llvm.org/t/iterating-lit-run-lines/62596/10.

For example, in a test file, the following directives define a
`%{check}` substitution as well as empty default values for 
substitutions that serve as parameters of `%{check}`:

  // DEFINE: %{cflags} =
  // DEFINE: %{fc-prefix} =
  
  // DEFINE: %{check} = %clang_cc1 %{cflags} -emit-llvm -o - %s | \ 
  // DEFINE:            FileCheck -check-prefix=%{fc-prefix} %s

The following directives then redefine the parameters before each use 
of `%{check}`:

  // REDEFINE: %{cflags} = -foo
  // REDEFINE: %{fc-prefix} = FOO 
  // RUN: %{check}
  
  // REDEFINE: %{cflags} = -bar
  // REDEFINE: %{fc-prefix} = BAR 
  // RUN: %{check}

Of course, `%{check}` would typically be more elaborate, increasing
the benefit of the reuse.

One issue is that the strings `DEFINE:` and `REDEFINE:` already appear
in some tests.  We could adjust those tests.  Alternatively, maybe lit 
keywords from now on should start with `LIT-` to avoid collisions.  In  
this case, we might use `LIT-DEF:` and `LIT-REDEF:`.

This patch also expands the documentation on existing lit substitution
behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132513

Files:
  llvm/docs/TestingGuide.rst
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/before-name.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/between-name-equals.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-empty.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-dot.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-equals.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-newline.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-number.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-ws.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/empty.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/no-equals.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/no-name.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/ws-only.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/empty.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/end-in-double-backslash.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-bad-redefine.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-redefine.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-run.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-bad-define.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-define.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-run.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-run-define.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-run-redefine.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/ws-only.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-already-by-config.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-already-by-test.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-inside-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-multiple-exact.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-multiple-once-exact.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-prefixes-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-suffixes-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-inside-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-multiple-exact.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-multiple-once-exact.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-none.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-prefixes-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-suffixes-pattern.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/location-range.txt
  llvm/utils/lit/tests/Inputs/shtest-define/errors/no-run.txt
  llvm/utils/lit/tests/Inputs/shtest-define/examples/param-subst.txt
  llvm/utils/lit/tests/Inputs/shtest-define/expansion-order.txt
  llvm/utils/lit/tests/Inputs/shtest-define/line-number-substitutions.txt
  llvm/utils/lit/tests/Inputs/shtest-define/lit.cfg
  llvm/utils/lit/tests/Inputs/shtest-define/recursiveExpansionLimit.txt
  llvm/utils/lit/tests/Inputs/shtest-define/shared-substs-0.txt
  llvm/utils/lit/tests/Inputs/shtest-define/shared-substs-1.txt
  llvm/utils/lit/tests/Inputs/shtest-define/value-escaped.txt
  llvm/utils/lit/tests/Inputs/shtest-define/ws-and-continuations.txt
  llvm/utils/lit/tests/shtest-define.py
  llvm/utils/lit/tests/shtest-keyword-parse-errors.py
  llvm/utils/lit/tests/unit/TestRunner.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132513.454980.patch
Type: text/x-patch
Size: 69712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/8dcf96d5/attachment.bin>


More information about the llvm-commits mailing list