• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eugene-babichenko / fixit / 17883635048

20 Sep 2025 06:55PM UTC coverage: 89.787% (-0.4%) from 90.214%
17883635048

push

github

eugene-babichenko
use anyhow instead of thiserror for simpler code

15 of 21 new or added lines in 5 files covered. (71.43%)

800 of 891 relevant lines covered (89.79%)

372.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.05
/src/get_text/rerun_command.rs
1
use std::{env, process::Command};
2

3
use anyhow::{Context, Result};
4

5
use crate::get_text::stdout_to_string;
6

7
pub fn rerun_command(cmd: &str, powershell: bool) -> Result<Option<Vec<String>>> {
4✔
8
    rerun_command_impl(cmd, &get_shell(powershell))
4✔
9
}
4✔
10

11
fn get_shell(powershell: bool) -> String {
4✔
12
    if powershell {
4✔
13
        return "pwsh".to_string();
×
14
    }
4✔
15

16
    if let Ok(shell) = env::var("SHELL") {
4✔
17
        return shell;
4✔
18
    }
×
19

20
    let shell = if cfg!(target_os = "windows") {
×
21
        "cmd.exe".to_string()
×
22
    } else {
23
        "/bin/sh".to_string()
×
24
    };
25

26
    log::warn!(
×
27
        "no $SHELL variable was found, using the default shell: {}",
×
28
        shell
29
    );
30

31
    shell
×
32
}
4✔
33

34
fn rerun_command_impl(cmd: &str, shell: &str) -> Result<Option<Vec<String>>> {
6✔
35
    log::debug!("shell in use: {}", &shell);
6✔
36
    log::debug!("re-running command: {}", &cmd);
6✔
37
    let output = Command::new(shell).arg("-c").arg(cmd).output().context(
6✔
38
        "could not re-run the failing command (might be a problem with the $SHELL variable)",
NEW
39
    )?;
×
40

41
    // if the command is successful we have nothing to do
42
    if output.status.success() {
6✔
43
        return Ok(None);
2✔
44
    }
4✔
45

46
    let stderr = stdout_to_string(output.stderr)?;
4✔
47
    let stdout = stdout_to_string(output.stdout)?;
4✔
48

49
    log::debug!("command stderr: {}", stderr);
4✔
50
    log::debug!("command stdout: {}", stdout);
4✔
51

52
    Ok(Some(vec![stderr, stdout]))
4✔
53
}
6✔
54

55
#[cfg(test)]
56
mod tests {
57
    use super::*;
58

59
    #[test]
60
    fn success() {
1✔
61
        let cmd = "echo hello; echo world 1>&2; exit 1";
1✔
62
        assert_eq!(
1✔
63
            Some(vec!["world\n".to_string(), "hello\n".to_string()]),
1✔
64
            rerun_command_impl(cmd, "/bin/sh").unwrap()
1✔
65
        );
66
    }
1✔
67

68
    #[test]
69
    fn command_ran_successfully() {
1✔
70
        let cmd = "echo hello; echo world 1>&2";
1✔
71
        assert_eq!(None, rerun_command_impl(cmd, "/bin/sh").unwrap());
1✔
72
    }
1✔
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc