verctl-core 0.9.7

Core configuration, manifest, fragment, changelog, and version domain logic for verctl
Documentation
use indoc::indoc;

use super::cooldown_rejections;

const CTL_TEXT: &str = indoc! {r#"
    error: `cargo metadata` exited with an error:     Updating crates.io index
    error: failed to select a version for the requirement `ctl-text = "=0.7.4"`
      version 0.7.4 is too new (published 36 hours ago, minimum age 3 days)
    location searched: crates.io index
    required by package `ctl-core v0.7.4 (/home/runner/work/ctl-core/ctl-core/ctl-core)`
    help: to preserve the min-publish-age, downgrade the requirement to "0.7.0"
    help: to use too-new packages anyways, re-resolve with `CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow`
"#};

const YAMLED: &str = indoc! {r#"
    error: `cargo metadata` exited with an error:     Updating crates.io index
    error: failed to select a version for the requirement `yamled = "=0.0.13"`
      version 0.0.13 is too new (published 39 hours ago, minimum age 3 days)
    location searched: crates.io index
    required by package `ctl-core v0.7.4 (/home/runner/work/ctl-core/ctl-core/ctl-core)`
    help: to preserve the min-publish-age, downgrade the requirement to "0.0.12"
    help: to use too-new packages anyways, re-resolve with `CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow`
"#};

const QCTL: &str = indoc! {r#"
    error: `cargo metadata` exited with an error:     Updating crates.io index
    error: failed to select a version for the requirement `qctl = "=0.7.0"`
      version 0.7.0 is too new (published 3 days ago, minimum age 3 days)
    location searched: crates.io index
    required by package `qctl v0.7.1 (/home/runner/work/qctl/qctl)`
    help: to preserve the min-publish-age, downgrade the requirement to "0.6.0"
    help: to use too-new packages anyways, re-resolve with `CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow`
"#};

/// What cargo 1.100 prints when a workspace member's package step meets a
/// sibling released seconds earlier.
const MEMBER: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/testdata/cooldown/member-requirement.stderr"
));

#[test]
fn a_member_requirement_on_a_release_candidate_is_rejected() {
    assert_eq!(cooldown_rejections(MEMBER), ["ctl-text"]);
}

#[test]
fn the_cooldown_names_the_crate_it_rejected() {
    assert_eq!(cooldown_rejections(CTL_TEXT), ["ctl-text"]);
    assert_eq!(cooldown_rejections(QCTL), ["qctl"]);
}

#[test]
fn several_rejections_are_sorted_and_listed_once() {
    let output = format!("{YAMLED}{CTL_TEXT}{YAMLED}");
    assert_eq!(cooldown_rejections(&output), ["ctl-text", "yamled"]);
}

#[test]
fn ansi_colour_codes_do_not_hide_a_rejection() {
    let output = indoc! {"
        \u{1b}[1m\u{1b}[31merror\u{1b}[0m: failed to select a version for the requirement `ctl-text = \"=0.7.4\"`
        \u{1b}[1m\u{1b}[33m  version 0.7.4 is too new (published 36 hours ago, minimum age 3 days)\u{1b}[0m
    "};
    assert_eq!(cooldown_rejections(output), ["ctl-text"]);
}

#[test]
fn another_resolution_error_names_no_crate() {
    let output = indoc! {r#"
        error: failed to select a version for the requirement `demo = "^9.0.0"`
        candidate versions found which didn't match: 0.1.0
        location searched: crates.io index
        required by package `ctl-core v0.7.4 (/work/ctl-core)`
        help: version 0.9.0 is too new (published 1 hour ago, minimum age 3 days)
    "#};
    assert_eq!(cooldown_rejections(output), Vec::<String>::new());
    assert_eq!(
        cooldown_rejections("error: could not compile `demo`"),
        Vec::<String>::new()
    );
}

#[test]
fn detects_cooldown_past_many_yanked_versions() {
    let output = indoc! {r#"
        error: failed to select a version for the requirement `pin-project-lite = "^0.2.11"`
          version 0.2.11 is yanked
          version 0.2.12 is yanked
          version 0.2.13 is yanked
          version 0.2.14 is yanked
          version 0.2.15 is yanked
          version 0.2.16 is yanked
          version 0.2.17 is yanked
          version 0.2.18 is yanked
          version 0.2.19 is too new (published 2 hours ago, minimum age 3 days)
        location searched: crates.io index
    "#};
    assert_eq!(cooldown_rejections(output), ["pin-project-lite"]);
}