-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lit] Add readfile substitution #158441
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
[lit] Add readfile substitution #158441
Changes from 3 commits
98b4330
7901d97
82bf25b
ff3041a
1599e05
c1d1b84
77fccd4
c547d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -720,6 +720,23 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files): | |||||
return std_fds | ||||||
|
||||||
|
||||||
def _expandLateSubstitutions(arguments, cwd): | ||||||
for i, arg in enumerate(arguments): | ||||||
if not isinstance(arg, str): | ||||||
continue | ||||||
|
||||||
def _replaceReadFile(match): | ||||||
filePath = match.group(1) | ||||||
if not os.path.isabs(filePath): | ||||||
filePath = os.path.join(cwd, filePath) | ||||||
with open(filePath) as fileHandle: | ||||||
|
||||||
return fileHandle.read() | ||||||
|
||||||
arguments[i] = re.sub(r"%{readfile:([^}]*)}", _replaceReadFile, arg) | ||||||
|
||||||
return arguments | ||||||
|
||||||
|
||||||
def _executeShCmd(cmd, shenv, results, timeoutHelper): | ||||||
if timeoutHelper.timeoutReached(): | ||||||
# Prevent further recursion if the timeout has been hit | ||||||
|
@@ -834,6 +851,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): | |||||
# Ensure args[0] is hashable. | ||||||
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0] | ||||||
|
||||||
# Expand all late substitutions | ||||||
|
# Expand all late substitutions | |
# Expand all late substitutions. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||
## Tests that readfile works with absolute paths | ||||||
|
## Tests that readfile works with absolute paths | |
## Tests that readfile works with absolute paths. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import lit.formats | ||
|
||
config.name = "shtest-readfile" | ||
config.suffixes = [".txt"] | ||
config.test_format = lit.formats.ShTest(execute_external=False) | ||
config.test_source_root = None | ||
config.test_exec_root = None | ||
config.substitutions.append(("%{python}", '"%s"' % (sys.executable))) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,7 @@ | ||||||
## Tests that readfile works with relative paths | ||||||
|
## Tests that readfile works with relative paths | |
## Tests that readfile works with relative paths. |
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 setup correctly. | ||||||
|
## regular expressions are setup correctly. | |
## regular expressions are set up correctly. |
("setup" -> noun; "set up" -> verb or adjective)
/end grammar pedantry
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
## Tests the readfile substitution | ||||||
|
## Tests the readfile substitution | |
## Tests the readfile substitution. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use FileCheck's -D option or similar to allow you to more precisely match the file name mentioned here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging. Looks like I didn't review my PR diff closely enough before requesting review. Sorry for the noise here.