-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lit] Add support for readfile to external shell #159431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
boomanaiden154
merged 4 commits into
main
from
users/boomanaiden154/lit-add-support-for-readfile-to-external-shell
Sep 19, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
llvm/utils/lit/tests/Inputs/shtest-readfile/absolute-paths.txt
This file contains hidden or 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,6 @@ | ||
## Tests that readfile works with absolute paths. | ||
# RUN: echo -n "hello" > %t | ||
# RUN: echo %{readfile:%t} | ||
|
||
## Fail the test so we can assert on the output. | ||
# RUN: not echo return |
4 changes: 4 additions & 0 deletions
4
llvm/utils/lit/tests/Inputs/shtest-readfile/file-does-not-exist.txt
This file contains hidden or 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,4 @@ | ||
## Test that readfile reports information appropriately when the file specified | ||
## does not exist. | ||
|
||
# RUN: echo %{readfile:/file/does/not/exist} |
This file contains hidden or 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,19 @@ | ||
import os | ||
|
||
import lit.formats | ||
import lit.util | ||
|
||
config.name = "shtest-readfile" | ||
config.suffixes = [".txt"] | ||
lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL") | ||
use_lit_shell = lit.util.pythonize_bool(lit_shell_env) | ||
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell) | ||
config.test_source_root = None | ||
config.test_exec_root = None | ||
|
||
# If we are testing with the external shell, remove the fake-externals from | ||
# PATH so that we use mkdir in the tests. | ||
if not use_lit_shell: | ||
path_parts = config.environment["PATH"].split(os.path.pathsep) | ||
path_parts = [path_part for path_part in path_parts if "fake-externals" not in path_part] | ||
config.environment["PATH"] = os.path.pathsep.join(path_parts) |
7 changes: 7 additions & 0 deletions
7
llvm/utils/lit/tests/Inputs/shtest-readfile/relative-paths.txt
This file contains hidden or 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,7 @@ | ||
## Tests that readfile works with relative paths. | ||
# RUN: mkdir -p rel_path_test_folder | ||
# RUN: echo -n "hello" > rel_path_test_folder/test_file | ||
# RUN: echo %{readfile:rel_path_test_folder/test_file} | ||
|
||
## Fail the test so we can assert on the output. | ||
# RUN: not echo return |
8 changes: 8 additions & 0 deletions
8
llvm/utils/lit/tests/Inputs/shtest-readfile/two-same-line.txt
This file contains hidden or 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 @@ | ||
## Tests that readfile works with two substitutions on the same line to ensure the | ||
## regular expressions are set up correctly. | ||
# RUN: echo -n "hello" > %t.1 | ||
# RUN: echo -n "bye" > %t.2 | ||
# RUN: echo %{readfile:%t.1} %{readfile:%t.2} | ||
|
||
## Fail the test so we can assert on the output. | ||
# RUN: not echo return |
This file contains hidden or 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,21 @@ | ||
## Tests the readfile substitution. | ||
|
||
# RUN: env LIT_USE_INTERNAL_SHELL=0 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S/Inputs/shtest-readfile/Output %s | ||
|
||
# CHECK: -- Testing: 4 tests{{.*}} | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}}) | ||
# CHECK: echo $(cat [[TEMP_PATH]]/absolute-paths.txt.tmp) && test -e /home/gha/llvm-project/build/utils/lit/tests/Inputs/shtest-readfile/Output/absolute-paths.txt.tmp {{.*}} | ||
# CHECK: + echo hello | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}}) | ||
# CHECK: echo $(cat /file/does/not/exist) && test -e /file/does/not/exist {{.*}} | ||
# CHECK: cat: /file/does/not/exist: No such file or directory | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: relative-paths.txt ({{[^)]*}}) | ||
# CHECK: echo $(cat rel_path_test_folder/test_file) && test -e rel_path_test_folder/test_file {{.*}} | ||
# CHECK: + echo hello | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: two-same-line.txt ({{[^)]*}}) | ||
# CHECK: echo $(cat /home/gha/llvm-project/build/utils/lit/tests/Inputs/shtest-readfile/Output/two-same-line.txt.tmp.1) $(cat /home/gha/llvm-project/build/utils/lit/tests/Inputs/shtest-readfile/Output/two-same-line.txt.tmp.2) && test -e /home/gha/llvm-project/build/utils/lit/tests/Inputs/shtest-readfile/Output/two-same-line.txt.tmp.1 && test -e /home/gha/llvm-project/build/utils/lit/tests/Inputs/shtest-readfile/Output/two-same-line.txt.tmp.2 {{.*}} | ||
# CHECK: + echo hello bye |
This file contains hidden or 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,21 @@ | ||
## Tests the readfile substitution. | ||
|
||
# RUN: env LIT_USE_INTERNAL_SHELL=1 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S/Inputs/shtest-readfile/Output %s | ||
|
||
# CHECK: -- Testing: 4 tests{{.*}} | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}}) | ||
# CHECK: echo hello | ||
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]/absolute-paths.txt.tmp}' | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}}) | ||
# CHECK: # executed command: @echo 'echo %{readfile:/file/does/not/exist}' | ||
# CHECK: # | File does not exist: /file/does/not/exist | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: relative-paths.txt ({{[^)]*}}) | ||
# CHECK: echo hello | ||
# CHECK: # executed command: echo '%{readfile:rel_path_test_folder/test_file}' | ||
|
||
# CHECK-LABEL: FAIL: shtest-readfile :: two-same-line.txt ({{[^)]*}}) | ||
# CHECK: echo hello bye | ||
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]/two-same-line.txt.tmp.1}' '%{readfile:[[TEMP_PATH]]/two-same-line.txt.tmp.2}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.