Files
swift-mirror/utils/update-verify-tests.py
Henrik G. Olsson 38620d49b1 [utils] integrate update-verify-tests with lit's --update-tests
This adds a lit plugin wrapping the core of update-verify-tests. When
lit is invoked with --update-tests it will call the plugin, which checks
if the failure is due to a -verify mismatch. If it is, it tries to
repair the test. If the source file was originally created by
split-file, the changes are propagated to the parent file.

No tests are added, because I don't want to run nested llvm-lit tests
in Swift's test suite, but the core functionality is tested through
update-verify-tests.py.
2025-11-11 16:33:43 -08:00

47 lines
1.9 KiB
Python

import sys
import argparse
from update_verify_tests.core import check_expectations
"""
Pipe output from swift-frontend's -verify into this script to have the test case updated to expect the actual diagnostic output.
When inserting new expected-* checks it will place them on the line before the location of the diagnostic, with an @+1,
or @+N for some N if there are multiple diagnostics emitted on the same line. If the current checks are using @-N for
this line, the new check will follow that convention also.
Existing checks will be left untouched as much as possible, including their location and whitespace content, to minimize
diffs. If inaccurate their count will be updated, or the check removed entirely.
Missing features:
- multiple prefixes on the same line (-verify-additional-prefix my-prefix -verify-additional-prefix my-other-prefix)
- multiple prefixes on separate RUN lines (RUN: -verify-additional-prefix my-prefix\nRUN: -verify-additional-prefix my-other-prefix)
- regexes matchers
- multiple checks targeting the same line are supported, but a line may only contain one check
- if multiple checks targeting the same line are failing the script is not guaranteed to produce a minimal diff
- remarks
- expansions
- columns
- fix-its
- doc files
Example usage:
swift-frontend -verify [file] | python3 update-verify-tests.py
swift-frontend -verify -verify-additional-prefix check- [file] | python3 update-verify-tests.py --prefix check-
"""
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--prefix", default="", help="The prefix passed to -verify")
args = parser.parse_args()
(err, updated_files) = check_expectations(sys.stdin.readlines(), args.prefix)
if err:
print(err)
sys.exit(1)
if len(updated_files) > 1:
print("\n\t".join(["updated files:"] + updated_files))
print(f"updated file: {updated_files[0]}")
if __name__ == "__main__":
main()