@@ -54,25 +54,34 @@ fn main() -> anyhow::Result<()> {
54
54
. filter_module ( "test_with_generated_opts" , LevelFilter :: Info )
55
55
. init ( ) ;
56
56
57
- let Tests { tests } = fs:: read_to_string ( & config)
57
+ let Config { examples } = fs:: read_to_string ( & config)
58
58
. map_err ( anyhow:: Error :: from)
59
59
. and_then ( |s| toml:: from_str ( & s) . map_err ( Into :: into) )
60
60
. with_context ( || format ! ( "Failed to read {}" , config. display( ) ) ) ?;
61
61
62
62
let tempdir = TempDir :: new ( "atcoder-rust-base-test-with-generated-opts" ) ?;
63
63
64
- let tests = tests
64
+ let tests = examples
65
65
. into_iter ( )
66
- . map ( |( slug, Test { name, matching } ) | {
67
- let src = Path :: new ( "./examples" ) . join ( & slug) . with_extension ( "rs" ) ;
68
- let testsets = Path :: new ( "./examples/testsets" ) . join ( & slug) ;
69
- let binary = compile ( & src, tempdir. path ( ) , & slug) ?;
70
- Ok ( ( name, matching, testsets, binary) )
71
- } )
66
+ . map (
67
+ |(
68
+ slug,
69
+ Example {
70
+ name,
71
+ url,
72
+ matching,
73
+ } ,
74
+ ) | {
75
+ let src = Path :: new ( "./examples" ) . join ( & slug) . with_extension ( "rs" ) ;
76
+ let testsets = Path :: new ( "./examples/testsets" ) . join ( & slug) ;
77
+ let binary = compile ( & src, tempdir. path ( ) , & slug) ?;
78
+ Ok ( ( name, url, matching, testsets, binary) )
79
+ } ,
80
+ )
72
81
. collect :: < anyhow:: Result < Vec < _ > > > ( ) ?;
73
82
74
- for ( name, matching, testsets, binary) in tests {
75
- test ( & name, matching, & testsets, & binary) ?;
83
+ for ( name, url , matching, testsets, binary) in tests {
84
+ test ( & name, & url , matching, & testsets, & binary) ?;
76
85
}
77
86
Ok ( ( ) )
78
87
}
@@ -142,20 +151,31 @@ fn compile(src: &Path, tempdir: &Path, dir_name: &str) -> anyhow::Result<PathBuf
142
151
Ok ( out)
143
152
}
144
153
145
- fn test ( task_name : & str , matching : Matching , testsets : & Path , binary : & Path ) -> anyhow:: Result < ( ) > {
154
+ fn test (
155
+ task_name : & str ,
156
+ url : & str ,
157
+ matching : Matching ,
158
+ testsets : & Path ,
159
+ binary : & Path ,
160
+ ) -> anyhow:: Result < ( ) > {
146
161
let testsets = {
147
- let find_files = |dir : & str | -> _ {
148
- fs:: read_dir ( testsets. join ( dir) ) ?
149
- . map ( |entry| {
150
- let path = entry?. path ( ) ;
151
- let name = path
152
- . file_stem ( )
153
- . unwrap_or_default ( )
154
- . to_string_lossy ( )
155
- . into_owned ( ) ;
156
- Ok ( ( name, path) )
162
+ let find_files = |dir_file_name : & str | -> _ {
163
+ let dir = testsets. join ( dir_file_name) ;
164
+ fs:: read_dir ( & dir)
165
+ . and_then ( |read_dir| {
166
+ read_dir
167
+ . map ( |entry| {
168
+ let path = entry?. path ( ) ;
169
+ let name = path
170
+ . file_stem ( )
171
+ . unwrap_or_default ( )
172
+ . to_string_lossy ( )
173
+ . into_owned ( ) ;
174
+ Ok ( ( name, path) )
175
+ } )
176
+ . collect :: < io:: Result < HashMap < _ , _ > > > ( )
157
177
} )
158
- . collect :: < io :: Result < HashMap < _ , _ > > > ( )
178
+ . with_context ( || format ! ( "Failed to read {}" , dir . display ( ) ) )
159
179
} ;
160
180
161
181
let ( ins, outs) = ( find_files ( "in" ) ?, find_files ( "out" ) ?) ;
@@ -168,7 +188,9 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
168
188
. collect :: < BTreeMap < _ , _ > > ( )
169
189
} ;
170
190
171
- info ! ( "Testing {} for {:?}" , binary. display( ) , task_name) ;
191
+ info ! ( "Testing {}" , binary. display( ) ) ;
192
+ info ! ( " Name: {:?}" , task_name) ;
193
+ info ! ( " URL: {}" , url) ;
172
194
173
195
for ( test_name, ( path_in, path_out) ) in testsets {
174
196
fn read_to_string ( path : & Path ) -> anyhow:: Result < String > {
@@ -218,13 +240,14 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
218
240
}
219
241
220
242
#[ derive( Debug , Deserialize ) ]
221
- struct Tests {
222
- tests : IndexMap < String , Test > ,
243
+ struct Config {
244
+ examples : IndexMap < String , Example > ,
223
245
}
224
246
225
247
#[ derive( Debug , Deserialize ) ]
226
- struct Test {
248
+ struct Example {
227
249
name : String ,
250
+ url : String ,
228
251
matching : Matching ,
229
252
}
230
253
0 commit comments