@@ -38,6 +38,39 @@ use std::str;
38
38
39
39
use extract_gdb_version;
40
40
41
+ #[ cfg( windows) ]
42
+ fn disable_error_reporting < F : FnOnce ( ) -> R , R > ( f : F ) -> R {
43
+ use std:: sync:: Mutex ;
44
+ const SEM_NOGPFAULTERRORBOX : u32 = 0x0002 ;
45
+ extern "system" {
46
+ fn SetErrorMode ( mode : u32 ) -> u32 ;
47
+ }
48
+
49
+ lazy_static ! {
50
+ static ref LOCK : Mutex <( ) > = {
51
+ Mutex :: new( ( ) )
52
+ } ;
53
+ }
54
+ // Error mode is a global variable, so lock it so only one thread will change it
55
+ let _lock = LOCK . lock ( ) . unwrap ( ) ;
56
+
57
+ // Tell Windows to not show any UI on errors (such as terminating abnormally).
58
+ // This is important for running tests, since some of them use abnormal
59
+ // termination by design. This mode is inherited by all child processes.
60
+ unsafe {
61
+ let old_mode = SetErrorMode ( SEM_NOGPFAULTERRORBOX ) ; // read inherited flags
62
+ SetErrorMode ( old_mode | SEM_NOGPFAULTERRORBOX ) ;
63
+ let r = f ( ) ;
64
+ SetErrorMode ( old_mode) ;
65
+ r
66
+ }
67
+ }
68
+
69
+ #[ cfg( not( windows) ) ]
70
+ fn disable_error_reporting < F : FnOnce ( ) -> R , R > ( f : F ) -> R {
71
+ f ( )
72
+ }
73
+
41
74
/// The name of the environment variable that holds dynamic library locations.
42
75
pub fn dylib_env_var ( ) -> & ' static str {
43
76
if cfg ! ( windows) {
@@ -1578,8 +1611,7 @@ impl<'test> TestCx<'test> {
1578
1611
let newpath = env:: join_paths ( & path) . unwrap ( ) ;
1579
1612
command. env ( dylib_env_var ( ) , newpath) ;
1580
1613
1581
- let mut child = command
1582
- . spawn ( )
1614
+ let mut child = disable_error_reporting ( || command. spawn ( ) )
1583
1615
. expect ( & format ! ( "failed to exec `{:?}`" , & command) ) ;
1584
1616
if let Some ( input) = input {
1585
1617
child
0 commit comments