Skip to content

Commit 0b393e0

Browse files
committed
Ignore copyright year when generating deriving span tests
Previously, generate-deriving-span-tests.py would regenerate all the tests anew, even if they hadn't changed. This creates unnecessary diffs that only change the copyright year. Now we check to see if any of the content of the test has changed before generating the new one.
1 parent 4b9b70c commit 0b393e0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: src/etc/generate-deriving-span-tests.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
sample usage: src/etc/generate-deriving-span-tests.py
1919
"""
2020

21-
import sys, os, datetime, stat
21+
import sys, os, datetime, stat, re
2222

2323
TEST_DIR = os.path.abspath(
2424
os.path.join(os.path.dirname(__file__), '../test/compile-fail'))
@@ -87,16 +87,25 @@ def create_test_case(type, trait, super_traits, error_count):
8787
def write_file(name, string):
8888
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)
8989

90+
with open(test_file) as f:
91+
old_str = f.read()
92+
old_str_ignoring_date = re.sub(r'^// Copyright \d+',
93+
'// Copyright {year}'.format(year = YEAR), old_str)
94+
if old_str_ignoring_date == string:
95+
# if all we're doing is updating the copyright year, ignore it
96+
return 0
97+
9098
# set write permission if file exists, so it can be changed
9199
if os.path.exists(test_file):
92100
os.chmod(test_file, stat.S_IWUSR)
93101

94-
with open(test_file, 'wt') as f:
102+
with open(test_file, 'w') as f:
95103
f.write(string)
96104

97105
# mark file read-only
98106
os.chmod(test_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
99107

108+
return 1
100109

101110

102111
ENUM = 1
@@ -120,11 +129,15 @@ def write_file(name, string):
120129
('Hash', [], 1)]:
121130
traits[trait] = (ALL, supers, errs)
122131

132+
files = 0
133+
123134
for (trait, (types, super_traits, error_count)) in traits.items():
124135
mk = lambda ty: create_test_case(ty, trait, super_traits, error_count)
125136
if types & ENUM:
126-
write_file(trait + '-enum', mk(ENUM_TUPLE))
127-
write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT))
137+
files += write_file(trait + '-enum', mk(ENUM_TUPLE))
138+
files += write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT))
128139
if types & STRUCT:
129-
write_file(trait + '-struct', mk(STRUCT_FIELDS))
130-
write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE))
140+
files += write_file(trait + '-struct', mk(STRUCT_FIELDS))
141+
files += write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE))
142+
143+
print('Generated {files} deriving span test{}.'.format('s' if files != 1 else '', files = files))

0 commit comments

Comments
 (0)