Skip to content
Myr

Store exit codes as Options (and remove unwrapping)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordi Chauzi · committed by David Peter · parent 3fcc6a1 · Browse files · 5 files+95 added−99 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+95 added−99 removed

  • other:+95 added−99 removed

5 files+95 added−99 removed

modified:src/hyperfine/export/asciidoc.rs+6 added-6 removed
97 unmodified lines
98 0.1003342584,99 0.10745223440000001,100 0.10697327940000001,101 ],102 vec![0, 0, 0], // exit codes103 BTreeMap::new(), // param102 vec![Some(0), Some(0), Some(0)], // exit codes103 BTreeMap::new(), // param104 );105106 let expms = format!(107 "| `{}`\n\
43 unmodified lines
151 0.1003342584,152 0.10745223440000001,153 0.10697327940000001,154 ],155 vec![0, 0, 0], // exit codes156 BTreeMap::new(), // param155 vec![Some(0), Some(0), Some(0)], // exit codes156 BTreeMap::new(), // param157 );158 let exps = format!(159 "| `sleep 1\\|`\n\160 | {} ± {}\n\
25 unmodified lines
186 4.0,187 5.0,188 6.0,189 vec![7.0, 8.0, 9.0],190 vec![0, 0, 0],190 vec![Some(0), Some(0), Some(0)],191 {192 let mut params = BTreeMap::new();193 params.insert("foo".into(), "1".into());194 params.insert("bar".into(), "2".into());
9 unmodified lines
204 14.0,205 15.0,206 16.0,207 vec![17.0, 18.0, 19.0],208 vec![0, 0, 0],208 vec![Some(0), Some(0), Some(0)],209 {210 let mut params = BTreeMap::new();211 params.insert("foo".into(), "1".into());212 params.insert("bar".into(), "7".into());
25 unmodified lines
modified:src/hyperfine/export/csv.rs+2 added-2 removed
66 unmodified lines
67 4.0,68 5.0,69 6.0,70 vec![7.0, 8.0, 9.0],71 vec![0, 0, 0],71 vec![Some(0), Some(0), Some(0)],72 {73 let mut params = BTreeMap::new();74 params.insert("foo".into(), "one".into());75 params.insert("bar".into(), "two".into());
9 unmodified lines
85 14.0,86 15.0,87 16.5,88 vec![17.0, 18.0, 19.0],89 vec![0, 0, 0],89 vec![Some(0), Some(0), Some(0)],90 {91 let mut params = BTreeMap::new();92 params.insert("foo".into(), "one".into());93 params.insert("bar".into(), "seven".into());
15 unmodified lines
modified:src/hyperfine/export/markdown.rs+80 added-80 removed
92 unmodified lines
93 let mut timing_results = vec![];9495 timing_results.push(BenchmarkResult::new(96 String::from("sleep 0.1"),97 0.1057, // mean98 0.0016, // std dev99 0.1057, // median100 0.0009, // user_mean101 0.0011, // system_mean102 0.1023, // min103 0.1080, // max104 vec![0.1, 0.1, 0.1], // times105 vec![0, 0, 0], // exit codes106 BTreeMap::new(), // parameter97 0.1057, // mean98 0.0016, // std dev99 0.1057, // median100 0.0009, // user_mean101 0.0011, // system_mean102 0.1023, // min103 0.1080, // max104 vec![0.1, 0.1, 0.1], // times105 vec![Some(0), Some(0), Some(0)], // exit codes106 BTreeMap::new(), // parameter107 ));108109 timing_results.push(BenchmarkResult::new(110 String::from("sleep 2"),111 2.0050, // mean112 0.0020, // std dev113 2.0050, // median114 0.0009, // user_mean115 0.0012, // system_mean116 2.0020, // min117 2.0080, // max118 vec![2.0, 2.0, 2.0], // times119 vec![0, 0, 0], // exit codes120 BTreeMap::new(), // parameter111 2.0050, // mean112 0.0020, // std dev113 2.0050, // median114 0.0009, // user_mean115 0.0012, // system_mean116 2.0020, // min117 2.0080, // max118 vec![2.0, 2.0, 2.0], // times119 vec![Some(0), Some(0), Some(0)], // exit codes120 BTreeMap::new(), // parameter121 ));122123 let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();124
18 unmodified lines
143 let mut timing_results = vec![];144145 timing_results.push(BenchmarkResult::new(146 String::from("sleep 2"),147 2.0050, // mean148 0.0020, // std dev149 2.0050, // median150 0.0009, // user_mean151 0.0012, // system_mean152 2.0020, // min153 2.0080, // max154 vec![2.0, 2.0, 2.0], // times155 vec![0, 0, 0], // exit codes156 BTreeMap::new(), // parameter147 2.0050, // mean148 0.0020, // std dev149 2.0050, // median150 0.0009, // user_mean151 0.0012, // system_mean152 2.0020, // min153 2.0080, // max154 vec![2.0, 2.0, 2.0], // times155 vec![Some(0), Some(0), Some(0)], // exit codes156 BTreeMap::new(), // parameter157 ));158159 timing_results.push(BenchmarkResult::new(160 String::from("sleep 0.1"),161 0.1057, // mean162 0.0016, // std dev163 0.1057, // median164 0.0009, // user_mean165 0.0011, // system_mean166 0.1023, // min167 0.1080, // max168 vec![0.1, 0.1, 0.1], // times169 vec![0, 0, 0], // exit codes170 BTreeMap::new(), // parameter161 0.1057, // mean162 0.0016, // std dev163 0.1057, // median164 0.0009, // user_mean165 0.0011, // system_mean166 0.1023, // min167 0.1080, // max168 vec![0.1, 0.1, 0.1], // times169 vec![Some(0), Some(0), Some(0)], // exit codes170 BTreeMap::new(), // parameter171 ));172173 let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();174
17 unmodified lines
192 let mut timing_results = vec![];193194 timing_results.push(BenchmarkResult::new(195 String::from("sleep 0.1"),196 0.1057, // mean197 0.0016, // std dev198 0.1057, // median199 0.0009, // user_mean200 0.0011, // system_mean201 0.1023, // min202 0.1080, // max203 vec![0.1, 0.1, 0.1], // times204 vec![0, 0, 0], // exit codes205 BTreeMap::new(), // parameter196 0.1057, // mean197 0.0016, // std dev198 0.1057, // median199 0.0009, // user_mean200 0.0011, // system_mean201 0.1023, // min202 0.1080, // max203 vec![0.1, 0.1, 0.1], // times204 vec![Some(0), Some(0), Some(0)], // exit codes205 BTreeMap::new(), // parameter206 ));207208 timing_results.push(BenchmarkResult::new(209 String::from("sleep 2"),210 2.0050, // mean211 0.0020, // std dev212 2.0050, // median213 0.0009, // user_mean214 0.0012, // system_mean215 2.0020, // min216 2.0080, // max217 vec![2.0, 2.0, 2.0], // times218 vec![0, 0, 0], // exit codes219 BTreeMap::new(), // parameter210 2.0050, // mean211 0.0020, // std dev212 2.0050, // median213 0.0009, // user_mean214 0.0012, // system_mean215 2.0020, // min216 2.0080, // max217 vec![2.0, 2.0, 2.0], // times218 vec![Some(0), Some(0), Some(0)], // exit codes219 BTreeMap::new(), // parameter220 ));221222 let formatted = String::from_utf8(223 exporter
23 unmodified lines
247 let mut timing_results = vec![];248249 timing_results.push(BenchmarkResult::new(250 String::from("sleep 2"),251 2.0050, // mean252 0.0020, // std dev253 2.0050, // median254 0.0009, // user_mean255 0.0012, // system_mean256 2.0020, // min257 2.0080, // max258 vec![2.0, 2.0, 2.0], // times259 vec![0, 0, 0], // exit codes260 BTreeMap::new(), // parameter251 2.0050, // mean252 0.0020, // std dev253 2.0050, // median254 0.0009, // user_mean255 0.0012, // system_mean256 2.0020, // min257 2.0080, // max258 vec![2.0, 2.0, 2.0], // times259 vec![Some(0), Some(0), Some(0)], // exit codes260 BTreeMap::new(), // parameter261 ));262263 timing_results.push(BenchmarkResult::new(264 String::from("sleep 0.1"),265 0.1057, // mean266 0.0016, // std dev267 0.1057, // median268 0.0009, // user_mean269 0.0011, // system_mean270 0.1023, // min271 0.1080, // max272 vec![0.1, 0.1, 0.1], // times273 vec![0, 0, 0], // exit codes274 BTreeMap::new(), // parameter265 0.1057, // mean266 0.0016, // std dev267 0.1057, // median268 0.0009, // user_mean269 0.0011, // system_mean270 0.1023, // min271 0.1080, // max272 vec![0.1, 0.1, 0.1], // times273 vec![Some(0), Some(0), Some(0)], // exit codes274 BTreeMap::new(), // parameter275 ));276277 let formatted = String::from_utf8(278 exporter
15 unmodified lines
modified:src/hyperfine/benchmark.rs+5 added-9 removed
200 unmodified lines
201 run_intermediate_command(shell, command, show_output, error_output)202}203204#[cfg(unix)]205fn extract_exit_code(status: ExitStatus) -> i32 {205fn extract_exit_code(status: ExitStatus) -> Option<i32> {206 use std::os::unix::process::ExitStatusExt;207208 /* From the ExitStatus::code documentation:209 "On Unix, this will return None if the process was terminated by a signal."210 In that case, ExitStatusExt::signal should never return None.211 */212 status.code().unwrap_or_else(|| status.signal().unwrap())212 status.code().or_else(|| status.signal())213}214215#[cfg(not(unix))]216fn extract_exit_code(status: ExitStatus) -> i32 {217 /* From the ExitStatus::code documentation:218 "On Unix, this will return None if the process was terminated by a signal."219 On the other configurations, ExitStatus::code should never return None.220 */221 status.code().unwrap()216fn extract_exit_code(status: ExitStatus) -> Option<i32> {217 status.code()218}219220/// Run the benchmark for a single shell command221pub fn run_benchmark(
21 unmodified lines
243244 let mut times_real: Vec<Second> = vec![];245 let mut times_user: Vec<Second> = vec![];246 let mut times_system: Vec<Second> = vec![];251 let mut exit_codes: Vec<i32> = vec![];247 let mut exit_codes: Vec<Option<i32>> = vec![];248 let mut all_succeeded = true;249250 // Run init command251 let prepare_cmd = options.preparation_command.as_ref().map(|values| {
217 unmodified lines
modified:src/hyperfine/types.rs+2 added-2 removed
267 unmodified lines
268 #[serde(skip_serializing_if = "Option::is_none")]269 pub times: Option<Vec<Second>>,270271 /// All run exit codes272 pub exit_codes: Vec<i32>,272 pub exit_codes: Vec<Option<i32>>,273274 /// Any parameter values used275 #[serde(skip_serializing_if = "BTreeMap::is_empty")]276 pub parameters: BTreeMap<String, String>,
10 unmodified lines
287 system: Second,288 min: Second,289 max: Second,290 times: Vec<Second>,291 exit_codes: Vec<i32>,291 exit_codes: Vec<Option<i32>>,292 parameters: BTreeMap<String, String>,293 ) -> Self {294 BenchmarkResult {295 command,
13 unmodified lines