8
8
sample usage: src/etc/generate-deriving-span-tests.py
9
9
"""
10
10
11
- import os , datetime , stat , re
11
+ import os , stat
12
12
13
13
TEST_DIR = os .path .abspath (
14
14
os .path .join (os .path .dirname (__file__ ), '../test/ui/derives/' ))
15
15
16
- YEAR = datetime .datetime .now ().year
17
-
18
16
TEMPLATE = """
19
17
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
20
18
@@ -63,19 +61,11 @@ def create_test_case(type, trait, super_traits, error_count):
63
61
64
62
errors = '\n ' .join ('//~%s ERROR' % ('^' * n ) for n in range (error_count ))
65
63
code = string .format (traits = all_traits , errors = errors )
66
- return TEMPLATE .format (year = YEAR , error_deriving = error_deriving , code = code )
64
+ return TEMPLATE .format (error_deriving = error_deriving , code = code )
67
65
68
66
def write_file (name , string ):
69
67
test_file = os .path .join (TEST_DIR , 'derives-span-%s.rs' % name )
70
68
71
- with open (test_file ) as f :
72
- old_str = f .read ()
73
- old_str_ignoring_date = re .sub (r'^// Copyright \d+' ,
74
- '// Copyright {year}' .format (year = YEAR ), old_str )
75
- if old_str_ignoring_date == string :
76
- # if all we're doing is updating the copyright year, ignore it
77
- return 0
78
-
79
69
# set write permission if file exists, so it can be changed
80
70
if os .path .exists (test_file ):
81
71
os .chmod (test_file , stat .S_IWUSR )
@@ -86,8 +76,6 @@ def write_file(name, string):
86
76
# mark file read-only
87
77
os .chmod (test_file , stat .S_IRUSR | stat .S_IRGRP | stat .S_IROTH )
88
78
89
- return 1
90
-
91
79
92
80
ENUM = 1
93
81
STRUCT = 2
@@ -110,15 +98,11 @@ def write_file(name, string):
110
98
('Hash' , [], 1 )]:
111
99
traits [trait ] = (ALL , supers , errs )
112
100
113
- files = 0
114
-
115
101
for (trait , (types , super_traits , error_count )) in traits .items ():
116
102
mk = lambda ty : create_test_case (ty , trait , super_traits , error_count )
117
103
if types & ENUM :
118
- files += write_file (trait + '-enum' , mk (ENUM_TUPLE ))
119
- files += write_file (trait + '-enum-struct-variant' , mk (ENUM_STRUCT ))
104
+ write_file (trait + '-enum' , mk (ENUM_TUPLE ))
105
+ write_file (trait + '-enum-struct-variant' , mk (ENUM_STRUCT ))
120
106
if types & STRUCT :
121
- files += write_file (trait + '-struct' , mk (STRUCT_FIELDS ))
122
- files += write_file (trait + '-tuple-struct' , mk (STRUCT_TUPLE ))
123
-
124
- print ('Generated {files} deriving span test{}.' .format ('s' if files != 1 else '' , files = files ))
107
+ write_file (trait + '-struct' , mk (STRUCT_FIELDS ))
108
+ write_file (trait + '-tuple-struct' , mk (STRUCT_TUPLE ))
0 commit comments