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

eugene-babichenko / fixit / 16602547252

29 Jul 2025 05:00PM UTC coverage: 90.636% (+0.1%) from 90.531%
16602547252

push

github

eugene-babichenko
ci: nix extravaganza

3 of 4 new or added lines in 2 files covered. (75.0%)

784 of 865 relevant lines covered (90.64%)

382.62 hits per line

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

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

3
use crate::get_text::{stdout_to_string, Error};
4

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

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

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

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

NEW
24
    log::warn!("no $SHELL variable was found, using the default shell: {shell}");
×
25

26
    shell
×
27
}
4✔
28

29
fn rerun_command_impl(cmd: &str, shell: &str) -> Result<Option<Vec<String>>, Error> {
6✔
30
    log::debug!("shell in use: {}", &shell);
6✔
31
    log::debug!("re-running command: {}", &cmd);
6✔
32
    let output = Command::new(shell)
6✔
33
        .arg("-c")
6✔
34
        .arg(cmd)
6✔
35
        .output()
6✔
36
        .map_err(Error::ReRun)?;
6✔
37

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

43
    let stderr = stdout_to_string(output.stderr)?;
4✔
44
    let stdout = stdout_to_string(output.stdout)?;
4✔
45

46
    log::debug!("command stderr: {stderr}");
4✔
47
    log::debug!("command stdout: {stdout}");
4✔
48

49
    Ok(Some(vec![stderr, stdout]))
4✔
50
}
6✔
51

52
#[cfg(test)]
53
mod tests {
54
    use super::*;
55

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

65
    #[test]
66
    fn command_ran_successfully() {
1✔
67
        let cmd = "echo hello; echo world 1>&2";
1✔
68
        assert_eq!(None, rerun_command_impl(cmd, "/bin/sh").unwrap());
1✔
69
    }
1✔
70
}
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