2013-08-24 23:16:06 +02:00
|
|
|
#!/usr/bin/env python
|
2018-12-25 08:56:47 -07:00
|
|
|
|
2013-08-24 23:16:06 +02:00
|
|
|
"""
|
|
|
|
This script takes a list of keywords and generates a testcase, that checks
|
|
|
|
if using the keyword as identifier fails, for every keyword. The generate
|
|
|
|
test files are set read-only.
|
2014-06-16 16:07:34 -07:00
|
|
|
Test for https://github.com/rust-lang/rust/issues/2275
|
2013-08-24 23:16:06 +02:00
|
|
|
|
|
|
|
sample usage: src/etc/generate-keyword-tests.py as break
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
|
|
|
|
|
2019-02-15 14:48:21 +01:00
|
|
|
template = """\
|
2013-08-24 23:16:06 +02:00
|
|
|
// This file was auto-generated using 'src/etc/generate-keyword-tests.py %s'
|
|
|
|
|
|
|
|
fn main() {
|
2016-04-24 21:35:50 +03:00
|
|
|
let %s = "foo"; //~ error: expected pattern, found keyword `%s`
|
2013-08-24 23:16:06 +02:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
test_dir = os.path.abspath(
|
2018-10-20 23:43:35 +03:00
|
|
|
os.path.join(os.path.dirname(__file__), '../test/ui/parser')
|
2013-08-24 23:16:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
for kw in sys.argv[1:]:
|
|
|
|
test_file = os.path.join(test_dir, 'keyword-%s-as-identifier.rs' % kw)
|
|
|
|
|
|
|
|
# set write permission if file exists, so it can be changed
|
|
|
|
if os.path.exists(test_file):
|
|
|
|
os.chmod(test_file, stat.S_IWUSR)
|
|
|
|
|
|
|
|
with open(test_file, 'wt') as f:
|
2019-02-15 14:48:21 +01:00
|
|
|
f.write(template % (kw, kw, kw))
|
2013-08-24 23:16:06 +02:00
|
|
|
|
|
|
|
# mark file read-only
|
2015-01-27 01:05:14 -08:00
|
|
|
os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|