Skip to content

Commit 1599e05

Browse files
feedback
Created using spr 1.3.6
1 parent ff3041a commit 1599e05

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
720720
return std_fds
721721

722722

723-
def _expandLateSubstitutions(arguments, cwd):
723+
def _expandLateSubstitutions(cmd, arguments, cwd):
724724
for i, arg in enumerate(arguments):
725725
if not isinstance(arg, str):
726726
continue
@@ -729,8 +729,12 @@ def _replaceReadFile(match):
729729
filePath = match.group(1)
730730
if not os.path.isabs(filePath):
731731
filePath = os.path.join(cwd, filePath)
732-
with open(filePath) as fileHandle:
733-
return fileHandle.read()
732+
try:
733+
with open(filePath) as fileHandle:
734+
return fileHandle.read()
735+
except FileNotFoundError as error:
736+
print(error)
737+
raise InternalShellError(cmd, "File does not exist: %s" % filePath)
734738

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

@@ -852,7 +856,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
852856
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
853857

854858
# Expand all late substitutions.
855-
args = _expandLateSubstitutions(args, cmd_shenv.cwd)
859+
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
856860

857861
inproc_builtin = inproc_builtins.get(args[0], None)
858862
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Test that readfile reports information appropriately when the file specified
2+
## does not exist.
3+
4+
# RUN: echo %{readfile:/file/does/not/exist}

llvm/utils/lit/tests/shtest-readfile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

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

5-
# CHECK: -- Testing: 3 tests{{.*}}
5+
# CHECK: -- Testing: 4 tests{{.*}}
66

77
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
88
# CHECK: echo hello
99
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]/absolute-paths.txt.tmp}'
1010

11+
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}})
12+
# CHECK: # executed command: @echo 'echo %{readfile:/file/does/not/exist}'
13+
# CHECK: # | File does not exist: /file/does/not/exist
14+
1115
# CHECK-LABEL: FAIL: shtest-readfile :: relative-paths.txt ({{[^)]*}})
1216
# CHECK: echo hello
1317
# CHECK: # executed command: echo '%{readfile:rel_path_test_folder/test_file}'

0 commit comments

Comments
 (0)