@@ -26,9 +26,9 @@ use rustfmt::rustfmt_diff::*;
26
26
static DIFF_CONTEXT_SIZE : usize = 3 ;
27
27
28
28
fn get_path_string ( dir_entry : io:: Result < fs:: DirEntry > ) -> String {
29
- let path = dir_entry. ok ( ) . expect ( "Couldn't get DirEntry. " ) . path ( ) ;
29
+ let path = dir_entry. expect ( "Couldn't get DirEntry" ) . path ( ) ;
30
30
31
- path. to_str ( ) . expect ( "Couldn't stringify path. " ) . to_owned ( )
31
+ path. to_str ( ) . expect ( "Couldn't stringify path" ) . to_owned ( )
32
32
}
33
33
34
34
// Integration tests. The files in the tests/source are formatted and compared
@@ -40,7 +40,7 @@ fn get_path_string(dir_entry: io::Result<fs::DirEntry>) -> String {
40
40
#[ test]
41
41
fn system_tests ( ) {
42
42
// Get all files in the tests/source directory.
43
- let files = fs:: read_dir ( "tests/source" ) . ok ( ) . expect ( "Couldn't read source dir. " ) ;
43
+ let files = fs:: read_dir ( "tests/source" ) . expect ( "Couldn't read source dir" ) ;
44
44
// Turn a DirEntry into a String that represents the relative path to the
45
45
// file.
46
46
let files = files. map ( get_path_string) ;
@@ -55,7 +55,7 @@ fn system_tests() {
55
55
// the only difference is the coverage mode
56
56
#[ test]
57
57
fn coverage_tests ( ) {
58
- let files = fs:: read_dir ( "tests/coverage-source" ) . ok ( ) . expect ( "Couldn't read source dir. " ) ;
58
+ let files = fs:: read_dir ( "tests/coverage-source" ) . expect ( "Couldn't read source dir" ) ;
59
59
let files = files. map ( get_path_string) ;
60
60
let ( _reports, count, fails) = check_files ( files, WriteMode :: Coverage ) ;
61
61
@@ -82,13 +82,10 @@ fn assert_output(source: &str, expected_filename: &str, write_mode: WriteMode) {
82
82
let _ = filemap:: write_all_files ( & file_map, & mut out, write_mode, & config) ;
83
83
let output = String :: from_utf8 ( out) . unwrap ( ) ;
84
84
85
- let mut expected_file = fs:: File :: open ( & expected_filename)
86
- . ok ( )
87
- . expect ( "Couldn't open target." ) ;
85
+ let mut expected_file = fs:: File :: open ( & expected_filename) . expect ( "Couldn't open target" ) ;
88
86
let mut expected_text = String :: new ( ) ;
89
87
expected_file. read_to_string ( & mut expected_text)
90
- . ok ( )
91
- . expect ( "Failed reading target." ) ;
88
+ . expect ( "Failed reading target" ) ;
92
89
93
90
let compare = make_diff ( & expected_text, & output, DIFF_CONTEXT_SIZE ) ;
94
91
if compare. len ( ) > 0 {
@@ -105,8 +102,7 @@ fn assert_output(source: &str, expected_filename: &str, write_mode: WriteMode) {
105
102
fn idempotence_tests ( ) {
106
103
// Get all files in the tests/target directory.
107
104
let files = fs:: read_dir ( "tests/target" )
108
- . ok ( )
109
- . expect ( "Couldn't read target dir." )
105
+ . expect ( "Couldn't read target dir" )
110
106
. map ( get_path_string) ;
111
107
let ( _reports, count, fails) = check_files ( files, WriteMode :: Default ) ;
112
108
@@ -120,9 +116,8 @@ fn idempotence_tests() {
120
116
#[ test]
121
117
fn self_tests ( ) {
122
118
let files = fs:: read_dir ( "src/bin" )
123
- . ok ( )
124
- . expect ( "Couldn't read src dir." )
125
- . chain ( fs:: read_dir ( "tests" ) . ok ( ) . expect ( "Couldn't read tests dir." ) )
119
+ . expect ( "Couldn't read src dir" )
120
+ . chain ( fs:: read_dir ( "tests" ) . expect ( "Couldn't read tests dir" ) )
126
121
. map ( get_path_string) ;
127
122
// Hack because there's no `IntoIterator` impl for `[T; N]`.
128
123
let files = files. chain ( Some ( "src/lib.rs" . to_owned ( ) ) . into_iter ( ) ) ;
@@ -236,37 +231,32 @@ fn get_config(config_file: Option<&str>) -> Config {
236
231
}
237
232
} ;
238
233
239
- let mut def_config_file = fs:: File :: open ( config_file_name)
240
- . ok ( )
241
- . expect ( "Couldn't open config." ) ;
234
+ let mut def_config_file = fs:: File :: open ( config_file_name) . expect ( "Couldn't open config" ) ;
242
235
let mut def_config = String :: new ( ) ;
243
- def_config_file. read_to_string ( & mut def_config) . ok ( ) . expect ( "Couldn't read config. " ) ;
236
+ def_config_file. read_to_string ( & mut def_config) . expect ( "Couldn't read config" ) ;
244
237
245
238
Config :: from_toml ( & def_config)
246
239
}
247
240
248
241
// Reads significant comments of the form: // rustfmt-key: value
249
242
// into a hash map.
250
243
fn read_significant_comments ( file_name : & str ) -> HashMap < String , String > {
251
- let file = fs:: File :: open ( file_name)
252
- . ok ( )
253
- . expect ( & format ! ( "Couldn't read file {}." , file_name) ) ;
244
+ let file = fs:: File :: open ( file_name) . expect ( & format ! ( "Couldn't read file {}" , file_name) ) ;
254
245
let reader = BufReader :: new ( file) ;
255
246
let pattern = r"^\s*//\s*rustfmt-([^:]+):\s*(\S+)" ;
256
- let regex = regex:: Regex :: new ( & pattern) . ok ( ) . expect ( "Failed creating pattern 1. " ) ;
247
+ let regex = regex:: Regex :: new ( & pattern) . expect ( "Failed creating pattern 1" ) ;
257
248
258
249
// Matches lines containing significant comments or whitespace.
259
250
let line_regex = regex:: Regex :: new ( r"(^\s*$)|(^\s*//\s*rustfmt-[^:]+:\s*\S+)" )
260
- . ok ( )
261
- . expect ( "Failed creating pattern 2." ) ;
251
+ . expect ( "Failed creating pattern 2" ) ;
262
252
263
253
reader. lines ( )
264
- . map ( |line| line. ok ( ) . expect ( "Failed getting line. " ) )
254
+ . map ( |line| line. expect ( "Failed getting line" ) )
265
255
. take_while ( |line| line_regex. is_match ( & line) )
266
256
. filter_map ( |line| {
267
257
regex. captures_iter ( & line) . next ( ) . map ( |capture| {
268
- ( capture. at ( 1 ) . expect ( "Couldn't unwrap capture. " ) . to_owned ( ) ,
269
- capture. at ( 2 ) . expect ( "Couldn't unwrap capture. " ) . to_owned ( ) )
258
+ ( capture. at ( 1 ) . expect ( "Couldn't unwrap capture" ) . to_owned ( ) ,
259
+ capture. at ( 2 ) . expect ( "Couldn't unwrap capture" ) . to_owned ( ) )
270
260
} )
271
261
} )
272
262
. collect ( )
@@ -283,10 +273,10 @@ fn handle_result(result: HashMap<String, String>,
283
273
for ( file_name, fmt_text) in result {
284
274
// If file is in tests/source, compare to file with same name in tests/target.
285
275
let target = get_target ( & file_name, target, write_mode) ;
286
- let mut f = fs:: File :: open ( & target) . ok ( ) . expect ( "Couldn't open target. " ) ;
276
+ let mut f = fs:: File :: open ( & target) . expect ( "Couldn't open target" ) ;
287
277
288
278
let mut text = String :: new ( ) ;
289
- f. read_to_string ( & mut text) . ok ( ) . expect ( "Failed reading target. " ) ;
279
+ f. read_to_string ( & mut text) . expect ( "Failed reading target" ) ;
290
280
291
281
if fmt_text != text {
292
282
let diff = make_diff ( & text, & fmt_text, DIFF_CONTEXT_SIZE ) ;
0 commit comments