[PATCH] D122569: [lit] Support %if ... %else syntax for RUN lines

Artem Belevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 13:11:09 PDT 2022


tra added inline comments.


================
Comment at: llvm/utils/lit/tests/shtest-if-else.py:1
+# RUN: %{lit} -v --show-all %{inputs}/shtest-if-else | FileCheck %s
+# END.
----------------
asavonic wrote:
> tra wrote:
> > probinson wrote:
> > > asavonic wrote:
> > > > tra wrote:
> > > > > I'd use the full name `%{inputs}/shtest-if-else/test.txt`. 
> > > > > This way it's obvious how the input file is used and it avoids accidentally picking up some other file we may eventually have in that directory.
> > > > > 
> > > > > Perhaps it would make sense to incorporate the test.txt into this file. E.g add another RUN line to generate the test input file and then run lit on it.
> > > > > This would allow  interleaving the RUN/check directives in the same source. Right now it's a bit of a pain to follow what we're exacuting and which output it's supposed to generate.
> > > > > 
> > > > > E.g. we could do something like this:
> > > > > ```
> > > > > RUN: grep LITRUN %s | sed -e 's/LITRUN/RUN/' > %t/test.txt
> > > > > RUN: grep LITCFG %s | sed -e 's/# LITCFG://' > %t/lit.cfg
> > > > > RUN: %{lit} -v --show-all %t.txt | FileCheck %s
> > > > > 
> > > > > # LITCFG: lit config lines go here.
> > > > > 
> > > > > # LITRUN: echo XX %if feature {YY} ZZ
> > > > > # CHECK-NEXT: 'RUN: at line 32'; echo XX YY ZZ
> > > > > # LITRUN: ...
> > > > > # CHECK-NEXT: ...
> > > > > ```
> > > > > ```
> > > > > RUN: grep LITRUN %s | sed -e 's/LITRUN/RUN/' > %t/test.txt
> > > > > RUN: grep LITCFG %s | sed -e 's/# LITCFG://' > %t/lit.cfg
> > > > > ```
> > > > I wonder if grep and sed are available (and required) for windows builds. Probably not.
> > > > In any case, I don't like this separation between inputs and checks either, so I'll try to figure out the way to combine them in one file.
> > > You probably want split-file which is an LLVM-built tool.
> > We can also use %python and run this test to write out the files we need.
> > 
> We can easily combine CHECK and RUN lines if we "escape" `RUN:` in the patterns by using a regex. I decided to keep the `lit.cfg`file separate to keep things simple. Otherwise we'll have to deal with test discovery and `split-file`.
Nice. It's so much easier to follow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122569/new/

https://reviews.llvm.org/D122569



More information about the llvm-commits mailing list