Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions llvm/utils/lit/lit/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
return std_fds


def _expandLateSubstitutions(arguments, cwd):
def _expandLateSubstitutions(cmd, arguments, cwd):
for i, arg in enumerate(arguments):
if not isinstance(arg, str):
continue
Expand All @@ -729,8 +729,11 @@ 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()
try:
with open(filePath) as fileHandle:
return fileHandle.read()
except FileNotFoundError:
raise InternalShellError(cmd, "File does not exist: %s" % filePath)

arguments[i] = re.sub(r"%{readfile:([^}]*)}", _replaceReadFile, arg)

Expand Down Expand Up @@ -852,7 +855,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]

# Expand all late substitutions.
args = _expandLateSubstitutions(args, cmd_shenv.cwd)
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)

inproc_builtin = inproc_builtins.get(args[0], None)
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
Expand Down
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}
6 changes: 5 additions & 1 deletion llvm/utils/lit/tests/shtest-readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

# RUN: not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S/Inputs/shtest-readfile/Output %s

# CHECK: -- Testing: 3 tests{{.*}}
# 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}'
Expand Down
Loading