Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lit] Support %if ... %else syntax for RUN lines
This syntax allows to modify RUN lines based on features available. For example: RUN: ... | FileCheck %s --check-prefix=%if windows %{CHECK-W%} %else %{CHECK-NON-W%} CHECK-W: ... CHECK-NON-W: ... The whole command can be put under %if ... %else: RUN: %if tool_available %{ %tool %} %else %{ true %} or: RUN: %if tool_available %{ %tool %} If tool_available feature is missing, we'll have an empty command in this RUN line. LIT used to emit an error for empty commands, but now it treats such commands as nop in all cases. Multi-line expressions are also supported: RUN: %if tool_available %{ \ RUN: %tool \ RUN: %} %else %{ \ RUN: true \ RUN: %} Background and motivation: D121727 [NVPTX] Integrate ptxas to LIT tests https://reviews.llvm.org/D121727 Differential Revision: https://reviews.llvm.org/D122569
- Loading branch information
Showing
9 changed files
with
250 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import lit.formats | ||
config.name = 'shtest-if-else' | ||
config.test_format = lit.formats.ShTest() | ||
config.test_source_root = None | ||
config.test_exec_root = None | ||
config.suffixes = ['.txt'] | ||
config.available_features.add('feature') | ||
config.substitutions.append(('%{sub}', 'ok')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CHECK: ValueError: '%{' is missing for %if substitution | ||
# | ||
# RUN: %if feature echo "test-1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CHECK: ValueError: '%}' is missing for %if substitution | ||
# | ||
# RUN: %if feature %{ echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CHECK: ValueError: '%{' is missing for %else substitution | ||
# | ||
# RUN: %if feature %{ echo %} %else fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CHECK: ValueError: '%}' is missing for %else substitution | ||
# | ||
# RUN: %if feature %{ echo %} %else %{ fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# CHECK: -- Testing:{{.*}} | ||
# CHECK-NEXT: PASS: shtest-if-else :: test.txt (1 of 1) | ||
# CHECK-NEXT: Script: | ||
# CHECK-NEXT: -- | ||
|
||
# RUN: %if feature %{ echo "test-1" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-1" | ||
|
||
# If %else is not present it is treated like %else %{%}. Empty commands | ||
# are ignored. | ||
# | ||
# RUN: %if nofeature %{ echo "fail" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]' | ||
# CHECK-NOT: fail | ||
|
||
# RUN: %if nofeature %{ echo "fail" %} %else %{ echo "test-2" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-2" | ||
|
||
# Spaces inside curly braces are not ignored | ||
# | ||
# RUN: echo test-%if feature %{ 3 %} %else %{ fail %}-test | ||
# RUN: echo test-%if feature %{ 4 4 %} %else %{ fail %}-test | ||
# RUN: echo test-%if nofeature %{ fail %} %else %{ 5 5 %}-test | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 3 -test | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 4 4 -test | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo test- 5 5 -test | ||
|
||
# Escape line breaks for multi-line expressions | ||
# | ||
# RUN: %if feature \ | ||
# RUN: %{ echo \ | ||
# RUN: "test-5" \ | ||
# RUN: %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-4]]'; echo "test-5" | ||
|
||
# RUN: %if nofeature \ | ||
# RUN: %{ echo "fail" %} \ | ||
# RUN: %else \ | ||
# RUN: %{ echo "test-6" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-4]]'; echo "test-6" | ||
|
||
# RUN: echo "test%if feature %{%} %else %{%}-7" | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-7" | ||
|
||
# Escape %if. Without %if..%else context '%{' and '%}' are treated | ||
# literally. | ||
# | ||
# RUN: echo %%if feature %{ echo "test-8" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo %if feature %{ echo "test-8" %} | ||
|
||
# Nested expressions are supported: | ||
# | ||
# RUN: echo %if feature %{ %if feature %{ %if nofeature %{"fail"%} %else %{"test-9"%} %} %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "test-9" | ||
|
||
# Binary expression evaluation and regex match can be used as | ||
# conditions. | ||
# | ||
# RUN: echo %if feature && !nofeature %{ "test-10" %} | ||
# RUN: echo %if feature && nofeature %{ "fail" %} %else %{ "test-11" %} | ||
# RUN: echo %if {{fea.+}} %{ "test-12" %} %else %{ "fail" %} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-10" | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-11" | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo "test-12" | ||
|
||
# Spaces between %if and %else are ignored. If there is no %else - | ||
# space after %if %{...%} is not ignored. | ||
# | ||
# RUN: echo XX %if feature %{YY%} ZZ | ||
# RUN: echo AA %if feature %{BB%} %else %{CC%} DD | ||
# RUN: echo AA %if nofeature %{BB%} %else %{CC%} DD | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo XX YY ZZ | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo AA BB DD | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-3]]'; echo AA CC DD | ||
|
||
# '{' and '}' can be used without escaping | ||
# | ||
# RUN: %if feature %{echo {}%} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo {} | ||
|
||
# Spaces are not required | ||
# | ||
# RUN: echo %if feature%{"ok"%}%else%{"fail"%} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo "ok" | ||
|
||
# Substitutions with braces are handled correctly | ||
# | ||
# RUN: echo %{sub} %if feature%{test-%{sub}%}%else%{"fail"%} | ||
# CHECK-NEXT: {{^.*'RUN}}: at line [[#@LINE-1]]'; echo ok test-ok | ||
|
||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: Exit Code: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# RUN: %{lit} -v --show-all %{inputs}/shtest-if-else/test.txt \ | ||
# RUN: | FileCheck %{inputs}/shtest-if-else/test.txt --match-full-lines | ||
|
||
# RUN: not %{lit} -v --show-all %{inputs}/shtest-if-else/test-neg1.txt 2>&1 \ | ||
# RUN: | FileCheck %{inputs}/shtest-if-else/test-neg1.txt | ||
|
||
# RUN: not %{lit} -v --show-all %{inputs}/shtest-if-else/test-neg2.txt 2>&1 \ | ||
# RUN: | FileCheck %{inputs}/shtest-if-else/test-neg2.txt | ||
|
||
# RUN: not %{lit} -v --show-all %{inputs}/shtest-if-else/test-neg3.txt 2>&1 \ | ||
# RUN: | FileCheck %{inputs}/shtest-if-else/test-neg3.txt | ||
|
||
# RUN: not %{lit} -v --show-all %{inputs}/shtest-if-else/test-neg4.txt 2>&1 \ | ||
# RUN: | FileCheck %{inputs}/shtest-if-else/test-neg4.txt |