13
13
14
14
// You should have received a copy of the GNU General Public License
15
15
// along with Open Ethereum. If not, see <http://www.gnu.org/licenses/>.
16
+ #![ allow( dead_code) ]
16
17
17
18
use ethjson:: test_helpers:: ethspec:: {
18
19
ChainTests , DifficultyTests , EthereumTestSuite , ExecutiveTests , StateTests , TestChainSpec ,
19
20
TestTrieSpec , TransactionTests , TrieTests ,
20
21
} ;
21
22
use globset:: Glob ;
22
- use log:: { info, warn } ;
23
+ use log:: info;
23
24
use rayon:: prelude:: * ;
24
25
use std:: path:: { Path , PathBuf } ;
25
26
use tempfile:: tempdir;
26
27
use trie:: TrieSpec ;
27
28
use walkdir:: { DirEntry , WalkDir } ;
28
29
30
+ /// Result of tests execution
29
31
pub struct TestResult {
32
+ /// Number of success execution
30
33
pub success : usize ,
34
+ /// Number of success execution
31
35
pub failed : Vec < String > ,
32
36
}
33
37
34
38
impl TestResult {
39
+ /// Creates a new TestResult without results
35
40
pub fn zero ( ) -> Self {
36
41
TestResult {
37
42
success : 0 ,
38
43
failed : Vec :: new ( ) ,
39
44
}
40
45
}
46
+ /// Creates a new success TestResult
41
47
pub fn success ( ) -> Self {
42
48
TestResult {
43
49
success : 1 ,
44
50
failed : Vec :: new ( ) ,
45
51
}
46
52
}
53
+ /// Creates a new failed TestResult
47
54
pub fn failed ( name : & str ) -> Self {
48
55
TestResult {
49
56
success : 0 ,
@@ -73,13 +80,15 @@ impl std::ops::AddAssign for TestResult {
73
80
pub struct TestRunner ( EthereumTestSuite ) ;
74
81
75
82
impl TestRunner {
83
+ /// Loads a new JSON Test suite
76
84
pub fn load < R > ( reader : R ) -> Result < Self , serde_json:: Error >
77
85
where
78
86
R : std:: io:: Read ,
79
87
{
80
88
Ok ( TestRunner ( serde_json:: from_reader ( reader) ?) )
81
89
}
82
90
91
+ /// Run the tests with one thread
83
92
pub fn run_without_par ( & self ) -> TestResult {
84
93
let pool = rayon:: ThreadPoolBuilder :: new ( )
85
94
. num_threads ( 1 )
@@ -88,6 +97,7 @@ impl TestRunner {
88
97
pool. install ( || self . run ( ) )
89
98
}
90
99
100
+ /// Run the tests
91
101
pub fn run ( & self ) -> TestResult {
92
102
let mut res = TestResult :: zero ( ) ;
93
103
for t in & self . 0 . chain {
@@ -120,10 +130,6 @@ impl TestRunner {
120
130
. collect :: < Vec < PathBuf > > ( )
121
131
}
122
132
123
- fn report_failed_tests ( path : & Path , list : & Vec < String > ) {
124
- warn ! ( "FAILED TESTS FOR {:?}: {:?} " , path, list) ;
125
- }
126
-
127
133
fn run1 < T , F > ( test : & T , base_path : & str , f : F ) -> TestResult
128
134
where
129
135
T : Send + Sync ,
@@ -149,7 +155,7 @@ impl TestRunner {
149
155
result
150
156
}
151
157
152
- pub fn in_set ( path : & Path , exprs : & [ String ] ) -> bool {
158
+ fn in_set ( path : & Path , exprs : & [ String ] ) -> bool {
153
159
for pathexp in exprs {
154
160
let glob = Glob :: new ( & pathexp)
155
161
. expect ( & format ! ( "cannot parse expression {}" , pathexp) )
@@ -161,7 +167,7 @@ impl TestRunner {
161
167
false
162
168
}
163
169
164
- pub fn run_chain_tests ( test : & ChainTests ) -> TestResult {
170
+ fn run_chain_tests ( test : & ChainTests ) -> TestResult {
165
171
Self :: run1 (
166
172
test,
167
173
& test. path ,
@@ -176,7 +182,8 @@ impl TestRunner {
176
182
} ,
177
183
)
178
184
}
179
- pub fn run_state_tests ( test : & StateTests ) -> TestResult {
185
+
186
+ fn run_state_tests ( test : & StateTests ) -> TestResult {
180
187
Self :: run1 (
181
188
test,
182
189
& test. path ,
@@ -191,7 +198,8 @@ impl TestRunner {
191
198
} ,
192
199
)
193
200
}
194
- pub fn run_difficuly_tests ( test : & DifficultyTests ) -> TestResult {
201
+
202
+ fn run_difficuly_tests ( test : & DifficultyTests ) -> TestResult {
195
203
let mut acc = TestResult :: zero ( ) ;
196
204
for path in & test. path {
197
205
acc += Self :: run1 (
@@ -213,7 +221,7 @@ impl TestRunner {
213
221
acc
214
222
}
215
223
216
- pub fn run_executive_tests ( test : & ExecutiveTests ) -> TestResult {
224
+ fn run_executive_tests ( test : & ExecutiveTests ) -> TestResult {
217
225
Self :: run1 (
218
226
test,
219
227
& test. path ,
@@ -222,16 +230,18 @@ impl TestRunner {
222
230
} ,
223
231
)
224
232
}
225
- pub fn run_transaction_tests ( test : & TransactionTests ) -> TestResult {
233
+
234
+ fn run_transaction_tests ( test : & TransactionTests ) -> TestResult {
226
235
Self :: run1 (
227
236
test,
228
237
& test. path ,
229
- |test : & TransactionTests , path : & Path , json : & [ u8 ] | {
238
+ |_ : & TransactionTests , path : & Path , json : & [ u8 ] | {
230
239
super :: transaction:: do_json_test ( & path, & json, & mut |_, _| { } )
231
240
} ,
232
241
)
233
242
}
234
- pub fn run_trie_tests ( test : & TrieTests ) -> TestResult {
243
+
244
+ fn run_trie_tests ( test : & TrieTests ) -> TestResult {
235
245
let mut acc = TestResult :: zero ( ) ;
236
246
for path in & test. path {
237
247
acc += Self :: run1 ( test, & path, |test : & TrieTests , path : & Path , json : & [ u8 ] | {
0 commit comments