Repository: carbon-language/carbon-lang
File: toolchain/autoupdate_testdata.py (Python)

Code before:
    parser.add_argument("--threads", help="Forwarded to file_test")
    parser.add_argument("files", nargs="*")
    args = parser.parse_args()

    if args.non_fatal_checks:
        if build_mode == "opt":
            exit(
                "`--non-fatal-checks` is incompatible with inferred "
                "`-c opt` build mode"
            )
        configs.append("--config=non-fatal-checks")

    argv = [
        bazel,
        "run",
        "-c",
        build_mode,
        *configs,
        "--experimental_convenience_symlinks=ignore",
        "--ui_event_filters=-info,-stdout,-stderr,-finish",
        "//toolchain/testing:file_test",
        "--",
        "--autoupdate",
    ]
    if args.print_slowest_tests:
        argv += ["--print_slowest_tests", args.print_slowest_tests]
    if args.threads:
        argv += ["--threads", args.threads]
    # Support specifying tests to update, such as:
    # ./autoupdate_testdata.py lex/**/*
    if args.files:
        repo_root = Path(__file__).parents[1]
        file_tests = []
        # Filter down to just test files.
        for f in args.files:
            if f.endswith(".carbon"):
                path = str(Path(f).resolve().relative_to(repo_root))
                if path.count("/testdata/"):
                    file_tests.append(path)
        if not file_tests:
            sys.exit(
                "Args do not seem to be test files; for example, "
                f"{args.files[0]}"
            )
        argv.append("--file_tests=" + ",".join(file_tests))
    # Provide an empty stdin so that the driver tests that read from stdin
    # don't block waiting for input. This matches the behavior of `bazel test`.
    subprocess.run(argv, check=True)


if __name__ == "__main__":

Review comment (bug):
I think we should turn this off by default for `autoupdate_testdata.py`. We've worked to keep the output produced by that script minimal when updates failed, and when that script is used as part of a regular development workflow I don't think this is going to be interesting information most of the time.

Code after:
        "--print_slowest_tests", default=0, help="Forwarded to file_test"
    )
    parser.add_argument("--threads", help="Forwarded to file_test")
    parser.add_argument("files", nargs="*")
    args = parser.parse_args()

    if args.non_fatal_checks:
        if build_mode == "opt":
            exit(
                "`--non-fatal-checks` is incompatible with inferred "
                "`-c opt` build mode"
            )
        configs.append("--config=non-fatal-checks")

    argv = [
        bazel,
        "run",
        "-c",
        build_mode,
        *configs,
        "--experimental_convenience_symlinks=ignore",
        "--ui_event_filters=-info,-stdout,-stderr,-finish",
        "//toolchain/testing:file_test",
        "--",
        "--autoupdate",
        "--print_slowest_tests",
        str(args.print_slowest_tests),
    ]
    if args.threads:
        argv += ["--threads", args.threads]
    # Support specifying tests to update, such as:
    # ./autoupdate_testdata.py lex/**/*
    if args.files:
        repo_root = Path(__file__).parents[1]
        file_tests = []
        # Filter down to just test files.
        for f in args.files:
            if f.endswith(".carbon"):
                path = str(Path(f).resolve().relative_to(repo_root))
                if path.count("/testdata/"):
                    file_tests.append(path)
        if not file_tests:
            sys.exit(
                "Args do not seem to be test files; for example, "
                f"{args.files[0]}"
            )
        argv.append("--file_tests=" + ",".join(file_tests))
    # Provide an empty stdin so that the driver tests that read from stdin
    # don't block waiting for input. This matches the behavior of `bazel test`.
    subprocess.run(argv, check=True)