Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/monetize

xtask/tests/release_checklist.rs

//! ★ **The release checklist is real** (P5, A27 / A22 §3.7 `release.checklist`): monetize's
//! part of a release is written down in `docs/RELEASING.md` under a "Release checklist"
//! heading, and every `cargo xtask <verb>` it tells the releaser to run is a verb that exists:
//! monetize's own (this crate's `main.rs`), or the named sibling's (dwarves, private-monetize-ops)
//! where that sibling is checked out beside this one. A step that names a verb nobody has is a
//! checklist nobody can follow.

use std::path::{Path, PathBuf};

fn repo() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_path_buf()
}

fn checklist() -> String {
    std::fs::read_to_string(repo().join("docs/RELEASING.md")).expect("docs/RELEASING.md")
}

/// The verbs a repo's xtask dispatches: its `Some("<verb>") =>` arms.
fn verbs(main_rs: &str) -> Vec<String> {
    main_rs.split("Some(\"").skip(1).filter_map(|r| r.split_once("\")")).filter(|(_, rest)| rest.trim_start().starts_with("=>")).map(|(v, _)| v.to_owned()).collect()
}

#[test]
fn the_checklist_has_its_heading_and_names_only_verbs_that_exist() {
    let doc = checklist();
    assert!(doc.lines().any(|l| l.starts_with('#') && l.to_lowercase().contains("release checklist")), "a \"Release checklist\" heading");
    let own = verbs(&std::fs::read_to_string(repo().join("xtask/src/main.rs")).unwrap());
    assert!(own.iter().any(|v| v == "ci") && own.iter().any(|v| v == "score"), "the reader reads this crate's verbs: {own:?}");
    let sibling = |name: &str| std::fs::read_to_string(repo().join("..").join(name).join("xtask/src/main.rs")).ok().map(|s| verbs(&s));
    let mut checked = 0;
    for line in doc.lines() {
        for part in line.split("`cargo xtask ").skip(1) {
            let verb = part.split([' ', '`']).next().unwrap_or_default();
            let whose = if line.contains("(dwarves)") {
                Some("dwarves")
            } else if line.contains("(private-monetize-ops)") {
                Some("private-monetize-ops")
            } else {
                None
            };
            match whose {
                None => assert!(own.contains(&verb.to_owned()), "`cargo xtask {verb}` is not a monetize verb ({own:?}): {line}"),
                Some(repo) => {
                    if let Some(theirs) = sibling(repo) {
                        assert!(theirs.contains(&verb.to_owned()), "`cargo xtask {verb}` is not a {repo} verb ({theirs:?}): {line}");
                    }
                }
            }
            checked += 1;
        }
    }
    assert!(checked >= 6, "the checklist names the verbs a release runs ({checked})");
}

#[test]
fn the_reader_finds_a_repos_verbs() {
    let main = "match a { Some(\"ci\") => ci(), Some(\"score\") => x, _ => {} } // Some(\"not\") here";
    assert_eq!(verbs(main), ["ci", "score"]);
}