fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #69444 - pietroalbini:stable-next-final-v2-new, r=pietroalbinif3e1a954d2e

1.41.1
1.0 KiB41 linesraw
1#!/usr/bin/env python
2
3"""
4This script takes a list of keywords and generates a testcase, that checks
5if using the keyword as identifier fails, for every keyword. The generate
6test files are set read-only.
7Test for https://github.com/rust-lang/rust/issues/2275
8
9sample usage: src/etc/generate-keyword-tests.py as break
10"""
11
12import sys
13import os
14import datetime
15import stat
16
17
18template = """\
19// This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'
20
21fn main() {
22    let %s = "foo"; //~ error: expected pattern, found keyword `%s`
23}
24"""
25
26test_dir = os.path.abspath(
27    os.path.join(os.path.dirname(__file__), '../test/ui/parser')
28)
29
30for kw in sys.argv[1:]:
31    test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw)
32
33    # set write permission if file exists, so it can be changed
34    if os.path.exists(test_file):
35        os.chmod(test_file, stat.S_IWUSR)
36
37    with open(test_file, 'wt') as f:
38        f.write(template % (kw, kw, kw))
39
40    # mark file read-only
41    os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)