Files
carbon-lang/testing/lit_test/merge_output.py
T
Jon Ross-Perkins 735502273b Refactor lit test infra under //testing. (#2829)
- Moves most parts to //testing/lit_test to be consistent with //testing/file_test.
- Separates the autoupdate script out because it's shared between lit_test and file_test now, not lit-specific.
- Renames scripts to autoupdate_testdata (or autoupdate_lit_testdata for explorer's extra) to be more consistent with the non-lit-specific setup.
  - Switches from execv to subprocess.call to head off a subtle issue regarding execution of multiple scripts, which we're likely to want in the future. Mostly in this PR because everything was already being touched.
- Removes autoupdate's dependency on merge_output in order to (a) better support the division of lit and non-lit logic and (b) remove a subprocess, for reasons similar to file_test's removal of subprocesses.
2023-05-18 08:01:03 -07:00

39 lines
990 B
Python

"""Merges stdout and stderr into a single stream with labels."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import subprocess
import sys
def label_output(label: str, output: str) -> None:
"""Prints output with labels.
This mirrors label_output in scripts/autoupdate_testdata_base.py and should
be kept in sync. They're separate in order to avoid a subprocess or import
complexity.
"""
if output:
for line in output.splitlines():
print(" ".join(filter(None, (label, line))))
def main() -> None:
p = subprocess.run(
sys.argv[1:],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
label_output("STDOUT:", p.stdout)
label_output("STDERR:", p.stderr)
exit(p.returncode)
if __name__ == "__main__":
main()