(
test, litConfig, tmpBase, commands, cwd, debug=True
)
| 1032 | # function), out contains only stdout from the script, err contains only stderr |
| 1033 | # from the script, and there is no execution trace. |
| 1034 | def executeScriptInternal( |
| 1035 | test, litConfig, tmpBase, commands, cwd, debug=True |
| 1036 | ) -> Tuple[str, str, int, Optional[str]]: |
| 1037 | cmds = [] |
| 1038 | for i, ln in enumerate(commands): |
| 1039 | # Within lit, we try to always add '%dbg(...)' to command lines in order |
| 1040 | # to maximize debuggability. However, custom lit test formats might not |
| 1041 | # always add it, so add a generic debug message in that case. |
| 1042 | match = re.fullmatch(kPdbgRegex, ln) |
| 1043 | if match: |
| 1044 | dbg = match.group(1) |
| 1045 | command = match.group(2) |
| 1046 | else: |
| 1047 | dbg = "command line" |
| 1048 | command = ln |
| 1049 | if debug: |
| 1050 | ln = f"@echo '# {dbg}' " |
| 1051 | if command: |
| 1052 | ln += f"&& @echo {shlex.quote(command.lstrip())} && {command}" |
| 1053 | else: |
| 1054 | ln += "has no command after substitutions" |
| 1055 | else: |
| 1056 | ln = command |
| 1057 | try: |
| 1058 | cmds.append( |
| 1059 | ShUtil.ShParser(ln, litConfig.isWindows, test.config.pipefail).parse() |
| 1060 | ) |
| 1061 | except: |
| 1062 | raise ScriptFatal( |
| 1063 | f"shell parser error on {dbg}: {command.lstrip()}\n" |
| 1064 | ) from None |
| 1065 | |
| 1066 | cmd = cmds[0] |
| 1067 | for c in cmds[1:]: |
| 1068 | cmd = ShUtil.Seq(cmd, "&&", c) |
| 1069 | |
| 1070 | results = [] |
| 1071 | timeoutInfo = None |
| 1072 | try: |
| 1073 | shenv = ShellEnvironment(cwd, test.config.environment) |
| 1074 | exitCode, timeoutInfo = executeShCmd( |
| 1075 | cmd, shenv, results, timeout=litConfig.maxIndividualTestTime |
| 1076 | ) |
| 1077 | except InternalShellError: |
| 1078 | e = sys.exc_info()[1] |
| 1079 | exitCode = 127 |
| 1080 | results.append(ShellCommandResult(e.command, "", e.message, exitCode, False)) |
| 1081 | |
| 1082 | out = err = "" |
| 1083 | for i, result in enumerate(results): |
| 1084 | if not debug: |
| 1085 | out += result.stdout |
| 1086 | err += result.stderr |
| 1087 | continue |
| 1088 | |
| 1089 | # The purpose of an "@echo" command is merely to add a debugging message |
| 1090 | # directly to lit's output. It is used internally by lit's internal |
| 1091 | # shell and is not currently documented for use in lit tests. However, |
no test coverage detected