clankers-cli 0.1.6

Command-line interface for clankeRS
Documentation
//! `clankers new` must work from the packaged binary alone — no repo checkout.
//!
//! Runs the real binary with a temp working directory (outside the workspace)
//! so any accidental dependence on repo-relative template paths fails loudly.

use std::process::Command;

#[test]
fn scaffolds_every_template_outside_a_checkout() {
    let tmp = tempfile::tempdir().unwrap();

    for (template, project) in [
        ("basic-node", "hello_basic"),
        ("perception-node", "hello_perception"),
        ("ml-inference-node", "hello_ml"),
        ("replay-test-node", "hello_replay"),
    ] {
        let out = Command::new(env!("CARGO_BIN_EXE_clankers"))
            .args(["new", project, "--template", template])
            .current_dir(tmp.path())
            .output()
            .expect("run clankers new");
        assert!(
            out.status.success(),
            "clankers new --template {template} failed:\n{}",
            String::from_utf8_lossy(&out.stderr)
        );

        let root = tmp.path().join(project);
        assert!(
            root.join("Cargo.toml").is_file(),
            "{template}: no Cargo.toml"
        );
        assert!(
            root.join("clankeRS.toml").is_file(),
            "{template}: no clankeRS.toml"
        );
        assert!(
            root.join("src/main.rs").is_file(),
            "{template}: no src/main.rs"
        );

        let manifest = std::fs::read_to_string(root.join("Cargo.toml")).unwrap();
        assert!(
            manifest.contains(&format!("name = \"{project}\"")),
            "{template}: project name not substituted:\n{manifest}"
        );
        assert!(
            !manifest.contains("{{"),
            "{template}: unsubstituted placeholder left in Cargo.toml:\n{manifest}"
        );
        // Outside a clankeRS checkout the dependency must point at crates.io.
        assert!(
            manifest.contains(r#"clankers = "0.1""#),
            "{template}: expected crates.io clankers dependency:\n{manifest}"
        );
    }
}

#[test]
fn unknown_template_lists_available_ones() {
    let tmp = tempfile::tempdir().unwrap();
    let out = Command::new(env!("CARGO_BIN_EXE_clankers"))
        .args(["new", "nope_project", "--template", "does-not-exist"])
        .current_dir(tmp.path())
        .output()
        .expect("run clankers new");
    assert!(!out.status.success());
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("basic-node") && stderr.contains("perception-node"),
        "error should list available templates:\n{stderr}"
    );
}