1#!/usr/bin/env python23"""4This script takes a list of keywords and generates a testcase, that checks5if using the keyword as identifier fails, for every keyword. The generate6test files are set read-only.7Test for https://github.com/rust-lang/rust/issues/227589sample usage: src/etc/generate-keyword-tests.py as break10"""1112import sys13import os14import stat151617template = """\18// This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'1920fn main() {21 let %s = "foo"; //~ error: expected pattern, found keyword `%s`22}23"""2425test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../test/ui/parser"))2627for kw in sys.argv[1:]:28 test_file = os.path.join(test_dir, "keyword-%s-as-identifier.rs" % kw)2930 # set write permission if file exists, so it can be changed31 if os.path.exists(test_file):32 os.chmod(test_file, stat.S_IWUSR)3334 with open(test_file, "wt") as f:35 f.write(template % (kw, kw, kw))3637 # mark file read-only38 os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
Findings
✓ No findings reported for this file.