git-ar 1.1.12

Git all remotes. Git cli tool that targets both Github and Gitlab. Brings common development operations such as opening a pull request down to the shell. This is an alternative to both Github https://github.com/cli/cli and Gitlab https://gitlab.com/gitlab-org/cli cli tools.
Documentation
use gr::io::TaskRunner;
use std::fs::File;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use tempfile::tempdir;

#[test]
fn test_execute_shell_cmd_ok() {
    let runner = gr::shell::BlockingCommand;
    let cmd = ["echo", "hello"];
    let response = runner.run(cmd).unwrap();
    assert_eq!(response.status, 0);
    assert_eq!(response.body, "hello");
}

#[test]
fn test_execute_shell_cmd_with_error_cmd_does_not_exist() {
    let runner = gr::shell::BlockingCommand;
    let cmd = ["/bin/doesnotexist", "test"];
    let err = runner.run(cmd).unwrap_err();
    assert_eq!(err.to_string(), "No such file or directory (os error 2)");
}

#[test]
fn test_execute_shell_cmd_with_error_cmd_fails_to_stderr() {
    let runner = gr::shell::BlockingCommand;
    let failure_sh = r#"
    #!/usr/bin/env bash

    # echo msg to stderr and exit with failure
    fail_msg_to_stderr() {
        echo -n "$1" 1>&2
        exit 2
    }

    fail_msg_to_stderr "This is a failure message"
    "#;

    let dir = tempdir().unwrap();
    let file_path = dir.path().join("fail_msg_to_stderr.sh");
    let mut file = File::create(&file_path).unwrap();
    let mut perms = std::fs::metadata(&file_path).unwrap().permissions();

    file.write_all(failure_sh.as_bytes()).unwrap();
    perms.set_mode(0o755);
    file.set_permissions(perms).unwrap();
    // flush and close file
    drop(file);
    let cmd = ["bash", "-c", &file_path.to_string_lossy()];
    let err = runner.run(cmd).unwrap_err();
    assert_eq!(err.to_string(), "This is a failure message");
}