mirror of
				https://github.com/BurntSushi/ripgrep.git
				synced 2025-10-30 23:17:47 +02:00 
			
		
		
		
	ripgrep: use exit code 2 to indicate error
Exit code 1 was shared to indicate both "no results" and "error." Use status code 2 to indicate errors, similar to grep's behavior. Fixes #948 PR #954
This commit is contained in:
		
				
					committed by
					
						 Andrew Gallant
						Andrew Gallant
					
				
			
			
				
	
			
			
			
						parent
						
							223d7d9846
						
					
				
				
					commit
					ca23a170f7
				
			| @@ -60,7 +60,7 @@ fn main() { | |||||||
|         Ok(_) => process::exit(0), |         Ok(_) => process::exit(0), | ||||||
|         Err(err) => { |         Err(err) => { | ||||||
|             eprintln!("{}", err); |             eprintln!("{}", err); | ||||||
|             process::exit(1); |             process::exit(2); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2191,3 +2191,33 @@ fn type_list() { | |||||||
|     // This can change over time, so just make sure we print something. |     // This can change over time, so just make sure we print something. | ||||||
|     assert!(!lines.is_empty()); |     assert!(!lines.is_empty()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // See: https://github.com/BurntSushi/ripgrep/issues/948 | ||||||
|  | sherlock!( | ||||||
|  |     exit_code_match_success, | ||||||
|  |     ".", | ||||||
|  |     ".", | ||||||
|  |     |wd: WorkDir, mut cmd: Command| { | ||||||
|  |         wd.assert_exit_code(0, &mut cmd); | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | // See: https://github.com/BurntSushi/ripgrep/issues/948 | ||||||
|  | sherlock!( | ||||||
|  |     exit_code_no_match, | ||||||
|  |     "6d28e48b5224a42b167e{10}", | ||||||
|  |     ".", | ||||||
|  |     |wd: WorkDir, mut cmd: Command| { | ||||||
|  |         wd.assert_exit_code(1, &mut cmd); | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | // See: https://github.com/BurntSushi/ripgrep/issues/948 | ||||||
|  | sherlock!( | ||||||
|  |     exit_code_error, | ||||||
|  |     "*", | ||||||
|  |     ".", | ||||||
|  |     |wd: WorkDir, mut cmd: Command| { | ||||||
|  |         wd.assert_exit_code(2, &mut cmd); | ||||||
|  |     } | ||||||
|  | ); | ||||||
|   | |||||||
| @@ -261,18 +261,37 @@ impl WorkDir { | |||||||
|     pub fn assert_err(&self, cmd: &mut process::Command) { |     pub fn assert_err(&self, cmd: &mut process::Command) { | ||||||
|         let o = cmd.output().unwrap(); |         let o = cmd.output().unwrap(); | ||||||
|         if o.status.success() { |         if o.status.success() { | ||||||
|             panic!("\n\n===== {:?} =====\n\ |             panic!( | ||||||
|                     command succeeded but expected failure!\ |                 "\n\n===== {:?} =====\n\ | ||||||
|                     \n\ncwd: {}\ |                  command succeeded but expected failure!\ | ||||||
|                     \n\nstatus: {}\ |                  \n\ncwd: {}\ | ||||||
|                     \n\nstdout: {}\n\nstderr: {}\ |                  \n\nstatus: {}\ | ||||||
|                     \n\n=====\n", |                  \n\nstdout: {}\n\nstderr: {}\ | ||||||
|                    cmd, self.dir.display(), o.status, |                  \n\n=====\n", | ||||||
|                    String::from_utf8_lossy(&o.stdout), |                 cmd, | ||||||
|                    String::from_utf8_lossy(&o.stderr)); |                 self.dir.display(), | ||||||
|  |                 o.status, | ||||||
|  |                 String::from_utf8_lossy(&o.stdout), | ||||||
|  |                 String::from_utf8_lossy(&o.stderr) | ||||||
|  |             ); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Runs the given command and asserts that its exit code matches expected exit code. | ||||||
|  |     pub fn assert_exit_code(&self, expected_code: i32, cmd: &mut process::Command) { | ||||||
|  |         let code = cmd.status().unwrap().code().unwrap(); | ||||||
|  |  | ||||||
|  |         assert_eq!( | ||||||
|  |             expected_code, code, | ||||||
|  |             "\n\n===== {:?} =====\n\ | ||||||
|  |              expected exit code did not match\ | ||||||
|  |              \n\nexpected: {}\ | ||||||
|  |              \n\nfound: {}\ | ||||||
|  |              \n\n=====\n", | ||||||
|  |             cmd, expected_code, code | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /// Runs the given command and asserts that something was printed to |     /// Runs the given command and asserts that something was printed to | ||||||
|     /// stderr. |     /// stderr. | ||||||
|     pub fn assert_non_empty_stderr(&self, cmd: &mut process::Command) { |     pub fn assert_non_empty_stderr(&self, cmd: &mut process::Command) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user