Skip to content

Commit

Permalink
Rollup merge of rust-lang#58293 - xfix:patch-16, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Remove code for updating copyright years in generate-deriving-span-tests

It's no longer necessary, as there is no license header anymore.
  • Loading branch information
kennytm committed Feb 16, 2019
2 parents 49107c3 + df420aa commit 9472f0c
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
sample usage: src/etc/generate-deriving-span-tests.py
"""

import os, datetime, stat, re
import os, stat

TEST_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))

YEAR = datetime.datetime.now().year

TEMPLATE = """
TEMPLATE = """\
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
{error_deriving}
Expand Down Expand Up @@ -63,19 +61,11 @@ def create_test_case(type, trait, super_traits, error_count):

errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
code = string.format(traits = all_traits, errors = errors)
return TEMPLATE.format(year = YEAR, error_deriving=error_deriving, code = code)
return TEMPLATE.format(error_deriving=error_deriving, code = code)

def write_file(name, string):
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)

with open(test_file) as f:
old_str = f.read()
old_str_ignoring_date = re.sub(r'^// Copyright \d+',
'// Copyright {year}'.format(year = YEAR), old_str)
if old_str_ignoring_date == string:
# if all we're doing is updating the copyright year, ignore it
return 0

# set write permission if file exists, so it can be changed
if os.path.exists(test_file):
os.chmod(test_file, stat.S_IWUSR)
Expand All @@ -86,8 +76,6 @@ def write_file(name, string):
# mark file read-only
os.chmod(test_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)

return 1


ENUM = 1
STRUCT = 2
Expand All @@ -110,15 +98,11 @@ def write_file(name, string):
('Hash', [], 1)]:
traits[trait] = (ALL, supers, errs)

files = 0

for (trait, (types, super_traits, error_count)) in traits.items():
mk = lambda ty: create_test_case(ty, trait, super_traits, error_count)
if types & ENUM:
files += write_file(trait + '-enum', mk(ENUM_TUPLE))
files += write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT))
write_file(trait + '-enum', mk(ENUM_TUPLE))
write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT))
if types & STRUCT:
files += write_file(trait + '-struct', mk(STRUCT_FIELDS))
files += write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE))

print('Generated {files} deriving span test{}.'.format('s' if files != 1 else '', files = files))
write_file(trait + '-struct', mk(STRUCT_FIELDS))
write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE))

0 comments on commit 9472f0c

Please sign in to comment.