rust/src/etc/generate-keyword-tests.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2018-12-25 08:56:47 -07: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
sample usage: src/etc/generate-keyword-tests.py as break
"""
import sys
import os
import stat
template = """\
// 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`
}
"""
test_dir = os.path.abspath(
2018-10-20 23:43:35 +03:00
os.path.join(os.path.dirname(__file__), '../test/ui/parser')
)
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:
f.write(template % (kw, kw, kw))
# 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)