3 # Copyright 2013 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
13 This script takes a list of keywords and generates a testcase, that checks
14 if using the keyword as identifier fails, for every keyword. The generate
15 test files are set read-only.
16 Test for https://github.com/rust-lang/rust/issues/2275
18 sample usage: src/etc/generate-keyword-tests.py as break
27 template = """// Copyright %d The Rust Project Developers. See the COPYRIGHT
28 // file at the top-level directory of this distribution and at
29 // http://rust-lang.org/COPYRIGHT.
31 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
32 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
33 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
34 // option. This file may not be copied, modified, or distributed
35 // except according to those terms.
37 // compile-flags: -Z parse-only
39 // This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'
42 let %s = "foo"; //~ error: expected pattern, found keyword `%s`
46 test_dir = os.path.abspath(
47 os.path.join(os.path.dirname(__file__), '../test/ui/parser')
50 for kw in sys.argv[1:]:
51 test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw)
53 # set write permission if file exists, so it can be changed
54 if os.path.exists(test_file):
55 os.chmod(test_file, stat.S_IWUSR)
57 with open(test_file, 'wt') as f:
58 f.write(template % (datetime.datetime.now().year, kw, kw, kw))
61 os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)