@@ -9,13 +9,16 @@ use predicates::prelude::*;
99use std:: process:: { Command as StdCommand , Stdio } ;
1010#[ cfg( has_executable_sleep) ]
1111use std:: time:: Instant ;
12+ use tempfile:: TempDir ;
1213
1314#[ test]
1415fn test_exit_code_for_empty_arguments ( ) {
1516 // Executing Bear with no arguments should return a non-zero exit code,
1617 // and print usage information.
18+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
1719 Command :: cargo_bin ( BEAR_BIN )
1820 . unwrap ( )
21+ . current_dir ( temp_dir. path ( ) )
1922 . env ( "RUST_LOG" , "debug" )
2023 . env ( "RUST_BACKTRACE" , "1" )
2124 . assert ( )
@@ -27,15 +30,19 @@ fn test_exit_code_for_empty_arguments() {
2730fn test_exit_code_for_help ( ) {
2831 // Executing help and subcommand help should always has zero exit code,
2932 // and print out usage information
33+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
34+
3035 Command :: cargo_bin ( BEAR_BIN )
3136 . unwrap ( )
37+ . current_dir ( temp_dir. path ( ) )
3238 . arg ( "--help" )
3339 . assert ( )
3440 . success ( )
3541 . stdout ( predicate:: str:: contains ( "Usage: bear" ) ) ;
3642
3743 Command :: cargo_bin ( BEAR_BIN )
3844 . unwrap ( )
45+ . current_dir ( temp_dir. path ( ) )
3946 . arg ( "intercept" )
4047 . arg ( "--help" )
4148 . assert ( )
@@ -44,6 +51,7 @@ fn test_exit_code_for_help() {
4451
4552 Command :: cargo_bin ( BEAR_BIN )
4653 . unwrap ( )
54+ . current_dir ( temp_dir. path ( ) )
4755 . arg ( "semantic" )
4856 . arg ( "--help" )
4957 . assert ( )
@@ -55,8 +63,10 @@ fn test_exit_code_for_help() {
5563fn test_exit_code_for_invalid_argument ( ) {
5664 // Executing Bear with an invalid argument should always has non-zero exit code,
5765 // and print relevant information about the reason about the failure.
66+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
5867 Command :: cargo_bin ( BEAR_BIN )
5968 . unwrap ( )
69+ . current_dir ( temp_dir. path ( ) )
6070 . arg ( "invalid_argument" )
6171 . env ( "RUST_LOG" , "debug" )
6272 . env ( "RUST_BACKTRACE" , "1" )
@@ -70,8 +80,10 @@ fn test_exit_code_for_invalid_argument() {
7080fn test_exit_code_for_non_existing_command ( ) {
7181 // Executing a non-existing command should always has non-zero exit code,
7282 // and print relevant information about the reason about the failure.
83+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
7384 Command :: cargo_bin ( BEAR_BIN )
7485 . unwrap ( )
86+ . current_dir ( temp_dir. path ( ) )
7587 . args ( [ "--" , "invalid_command" ] )
7688 . env ( "RUST_LOG" , "debug" )
7789 . env ( "RUST_BACKTRACE" , "1" )
@@ -87,8 +99,10 @@ fn test_exit_code_for_non_existing_command() {
8799#[ cfg( has_executable_true) ]
88100fn test_exit_code_for_true ( ) {
89101 // When the executed command returns successfully, Bear exit code should be zero.
102+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
90103 Command :: cargo_bin ( BEAR_BIN )
91104 . unwrap ( )
105+ . current_dir ( temp_dir. path ( ) )
92106 . arg ( "--" )
93107 . arg ( TRUE_PATH )
94108 . env ( "RUST_LOG" , "debug" )
@@ -101,8 +115,10 @@ fn test_exit_code_for_true() {
101115#[ cfg( has_executable_false) ]
102116fn test_exit_code_for_false ( ) {
103117 // When the executed command returns unsuccessfully, Bear exit code should be non-zero.
118+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
104119 Command :: cargo_bin ( BEAR_BIN )
105120 . unwrap ( )
121+ . current_dir ( temp_dir. path ( ) )
106122 . arg ( "--" )
107123 . arg ( FALSE_PATH )
108124 . env ( "RUST_LOG" , "debug" )
@@ -116,9 +132,11 @@ fn test_exit_code_for_false() {
116132fn test_exit_code_when_signaled ( ) {
117133 // When the bear process is signaled, Bear exit code should be non-zero.
118134 // And should terminate the child process and return immediately.
135+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
119136
120137 let mut cmd = StdCommand :: new ( cargo_bin ( BEAR_BIN ) ) ;
121- cmd. arg ( "--" )
138+ cmd. current_dir ( temp_dir. path ( ) )
139+ . arg ( "--" )
122140 . arg ( SLEEP_PATH )
123141 . arg ( "10" )
124142 . env ( "RUST_LOG" , "debug" )
0 commit comments