bbcloud 0.22.0

Bitbucket Cloud CLI — open pull requests, read every comment, write replies, from the shell
Documentation
#![allow(clippy::unwrap_used)] // test code is exempt from the unwrap/expect ban

use assert_cmd::Command;
use predicates::str::contains;

#[test]
fn prints_version() {
    Command::cargo_bin("bb")
        .unwrap()
        .env("BB_NO_UPDATE_CHECK", "1")
        .arg("--version")
        .assert()
        .success()
        .stdout(contains(env!("CARGO_PKG_VERSION")));
}

#[test]
fn help_lists_every_top_level_command() {
    let out = Command::cargo_bin("bb")
        .unwrap()
        .env("BB_NO_UPDATE_CHECK", "1")
        .arg("--help")
        .output()
        .unwrap();
    let text = String::from_utf8_lossy(&out.stdout);
    for expected in [
        "auth",
        "pr",
        "branch",
        "repo",
        "project",
        "browse",
        "completions",
    ] {
        assert!(
            text.contains(expected),
            "missing `{expected}` in help:\n{text}"
        );
    }
}

#[test]
fn repo_help_documents_that_private_is_the_default() {
    let out = Command::cargo_bin("bb")
        .unwrap()
        .env("BB_NO_UPDATE_CHECK", "1")
        .args(["repo", "create", "--help"])
        .output()
        .unwrap();
    let text = String::from_utf8_lossy(&out.stdout);
    assert!(
        text.contains("private is the default"),
        "help must state the privacy default, since getting it wrong publishes code:\n{text}"
    );
}

#[test]
fn pr_help_lists_read_and_write_commands() {
    let out = Command::cargo_bin("bb")
        .unwrap()
        .env("BB_NO_UPDATE_CHECK", "1")
        .args(["pr", "--help"])
        .output()
        .unwrap();
    let text = String::from_utf8_lossy(&out.stdout);
    for expected in [
        "list",
        "view",
        "create",
        "comment",
        "resolve",
        "unresolve",
        "diff",
        "files",
        "commits",
    ] {
        assert!(
            text.contains(expected),
            "missing `pr {expected}` in help:\n{text}"
        );
    }
}

#[test]
fn no_php_sources_remain() {
    let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
    for stale in [
        "bin/bb",
        "src/Base.php",
        "src/Actions",
        "create-phar.php",
        "config/app.php",
    ] {
        assert!(
            !root.join(stale).exists(),
            "{stale} should have been deleted"
        );
    }
}

#[test]
fn help_does_not_mention_app_passwords() {
    let out = Command::cargo_bin("bb")
        .unwrap()
        .env("BB_NO_UPDATE_CHECK", "1")
        .arg("--help")
        .output()
        .unwrap();
    let text = String::from_utf8_lossy(&out.stdout).to_lowercase();
    assert!(
        !text.contains("app password"),
        "help must not advertise removed app passwords"
    );
}