]> git.lizzy.rs Git - rust.git/blob - src/etc/generate-keyword-tests.py
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / etc / generate-keyword-tests.py
1 #!/usr/bin/env python
2 #
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.
6 #
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.
12 """
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
17
18 sample usage: src/etc/generate-keyword-tests.py as break
19 """
20
21 import sys
22 import os
23 import datetime
24 import stat
25
26
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.
30 //
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.
36
37 // This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'
38
39 fn main() {
40     let %s = "foo"; //~ error: ident
41 }
42 """
43
44 test_dir = os.path.abspath(
45     os.path.join(os.path.dirname(__file__), '../test/compile-fail')
46 )
47
48 for kw in sys.argv[1:]:
49     test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw)
50
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)
54
55     with open(test_file, 'wt') as f:
56         f.write(template % (datetime.datetime.now().year, kw, kw))
57
58     # mark file read-only
59     os.chmod(test_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)