@@ -5,6 +5,7 @@ use crate::error::Error;
5
5
use crate :: passes:: { Pass , TestCase } ;
6
6
7
7
use std:: fs;
8
+ use std:: io:: Read ;
8
9
use std:: path:: { Path , PathBuf } ;
9
10
10
11
pub struct RustcDejagnu ;
@@ -18,18 +19,27 @@ impl Pass for RustcDejagnu {
18
19
}
19
20
20
21
fn adapt ( & self , args : & Args , file : & Path ) -> Result < TestCase , Error > {
21
- let test_content = fs:: read_to_string ( file) ?;
22
-
23
- let exit_code = u8:: from ( test_content. contains ( "dg-error" ) ) ;
24
-
25
- // FIXME: This should be removed once we have a proper main shim in gccrs
26
- // This is to make sure that we can't ever get a "success" because a test
27
- // contains a dg-error directive and a `fn main() -> i32` so rustc produces
28
- // the correct exit code
29
- let exit_code = if test_content. contains ( "fn main() -> i32" ) {
30
- 255
31
- } else {
32
- exit_code
22
+ // we have invalid UTF-8 testcases, so we cannot just use `fs::read_to_string`
23
+ let mut test_file = fs:: File :: open ( file) ?;
24
+ let mut bytes = Vec :: new ( ) ;
25
+ test_file. read_to_end ( & mut bytes) ?;
26
+
27
+ let exit_code = match String :: from_utf8 ( bytes) {
28
+ Ok ( content) => {
29
+ let mut exit_code = u8:: from ( content. contains ( "dg-error" ) ) ;
30
+
31
+ // FIXME: This should be removed once we have a proper main shim in gccrs
32
+ // This is to make sure that we can't ever get a "success" because a test
33
+ // contains a dg-error directive and a `fn main() -> i32` so rustc produces
34
+ // the correct exit code
35
+ if content. contains ( "fn main()" ) {
36
+ exit_code = 255 ;
37
+ }
38
+
39
+ exit_code
40
+ }
41
+ // invalid UTF-8 in the file
42
+ Err ( _) => 1 , // Is that stable?
33
43
} ;
34
44
35
45
let test_case = TestCase :: from_compiler ( Compiler :: new ( Kind :: RustcBootstrap , args) )
0 commit comments