Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
[WIP] cli: Migrate example tests for `rad issue`
✗ CI failure Erik Kundt committed 7 months ago
commit 87a865a5960086fa9669be969d83ca0a81be8fbc
parent d6a0c5d8eebf45b47687d43034300df877b62354
2 failed 1 pending (3 total) View logs
4 files changed +79 -2
modified crates/radicle-cli/src/commands/issue.rs
@@ -1,6 +1,8 @@
mod args;
mod cache;

+
use std::sync::LazyLock;
+

use anyhow::Context as _;

use radicle::cob::common::Label;
@@ -31,6 +33,33 @@ use crate::terminal::issue::Format;
use crate::terminal::patch::Message;
use crate::terminal::Element;

+
const EXAMPLES: &[term::Example] = &[term::Example {
+
    args: &[
+
        "rad",
+
        "issue",
+
        "open",
+
        "--title",
+
        "\"My first issue\"",
+
        "--description",
+
        "\"Hello Radicle!\"",
+
    ],
+
}];
+

+
pub static HELP_EXAMPLES: LazyLock<String> = LazyLock::new(|| {
+
    let examples = EXAMPLES
+
        .iter()
+
        .map(|example| example.args.join(" "))
+
        .collect::<Vec<_>>()
+
        .join("\n");
+

+
    format!(
+
        "{}
+
  {}",
+
        term::HEADER_EXAMPLES,
+
        examples
+
    )
+
});
+

pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let rid = if let Some(rid) = args.repo {
@@ -576,3 +605,19 @@ fn comment_quoted(comment: &thread::Comment, buffer: &mut String) {
        buffer.push('\n');
    }
}
+

+
#[cfg(test)]
+
mod tests {
+
    use super::*;
+
    use clap::Parser;
+

+
    #[test]
+
    fn examples_should_be_parsed() {
+
        for example in EXAMPLES.iter() {
+
            assert!(
+
                Args::try_parse_from(&example.args[1..]).is_ok(),
+
                "Invalid example in help text"
+
            );
+
        }
+
    }
+
}
modified crates/radicle-cli/src/main.rs
@@ -47,6 +47,7 @@ struct CliArgs {
#[derive(Subcommand, Debug)]
enum Commands {
    /// Manage issues by using operations to list, create or edit them.
+
    #[command(after_help = issue::HELP_EXAMPLES.as_str())]
    Issue(issue::Args),
}

modified crates/radicle-cli/src/terminal.rs
@@ -16,12 +16,18 @@ use std::process;

use clap::Parser;

-
pub use radicle_term::*;
-

use radicle::profile::{Home, Profile};
+
pub use radicle_term::*;

use crate::terminal;

+
pub const HEADER_EXAMPLES: &str = "\x1b[1;33mExamples:\x1b[0m";
+

+
#[derive(Debug)]
+
pub struct Example {
+
    pub(crate) args: &'static [&'static str],
+
}
+

/// Context passed to all commands.
pub trait Context {
    /// Return the currently active profile, or an error if no profile is active.
modified crates/radicle-cli/tests/commands.rs
@@ -2662,3 +2662,28 @@ fn rad_workflow() {
    )
    .unwrap();
}
+

+
#[test]
+
fn issue_open_should_succeed() {
+
    use clap::Parser;
+
    use radicle_cli::commands::issue;
+

+
    let mut environment = Environment::new();
+
    let profile = environment.profile("alice");
+
    let working = environment.work(&profile);
+
    let (rid, _, _, _) =
+
        fixtures::project(working, &profile.storage, &profile.signer().unwrap()).unwrap();
+

+
    let args = issue::Args::parse_from(&[
+
        "issue",
+
        "open",
+
        "--title",
+
        "My first issue",
+
        "--description",
+
        "Hello World!",
+
        "--repo",
+
        &rid.to_string(),
+
    ]);
+

+
    assert!(issue::run(args, profile).is_ok());
+
}