MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / executeScriptInternal

Function executeScriptInternal

tests/lit/lit/TestRunner.py:1034–1157  ·  view source on GitHub ↗
(
    test, litConfig, tmpBase, commands, cwd, debug=True
)

Source from the content-addressed store, hash-verified

1032# function), out contains only stdout from the script, err contains only stderr
1033# from the script, and there is no execution trace.
1034def 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,

Callers 1

runOnceFunction · 0.85

Calls 9

to_stringFunction · 0.90
ScriptFatalClass · 0.85
ShellEnvironmentClass · 0.85
executeShCmdFunction · 0.85
ShellCommandResultClass · 0.85
formatOutputFunction · 0.85
quoteMethod · 0.80
appendMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected