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 // This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'
40 let %s = "foo"; //~ error: ident
44 test_dir = os.path.abspath(
45 os.path.join(os.path.dirname(__file__), '../test/compile-fail')
48 for kw in sys.argv[1:]:
49 test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw)
51 # set write permission if file exists, so it can be changed
52 if os.path.exists(test_file):
53 os.chmod(test_file, stat.S_IWUSR)
55 with open(test_file, 'wt') as f:
56 f.write(template % (datetime.datetime.now().year, kw, kw))
59 os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)