wsb 0.258.6441

Workspace tools for every project under $PRJ: git across submodules, template stamping, GitHub, and the workbench
Documentation
use super::*;
use tempfile::TempDir;

fn with_config(text: Option<&str>) -> TempDir {
    let root = TempDir::new().unwrap();
    if let Some(text) = text {
        std::fs::create_dir_all(root.path().join(".wsb")).unwrap();
        std::fs::write(root.path().join(FILE), text).unwrap();
    }
    root
}

#[test]
fn named_paths_are_relative_to_the_scan_root() {
    let root = with_config(Some(r#"{"declared": "workspace.json", "build_root": ".wsb/disposable/build"}"#));
    assert_eq!(
        StampConfig::declared_file(root.path()).unwrap(),
        root.path().join("workspace.json")
    );
    assert_eq!(
        StampConfig::build_root(root.path()).unwrap(),
        root.path().join(".wsb/disposable/build")
    );
}

#[test]
fn asking_without_a_configuration_names_the_file() {
    let root = with_config(None);
    let said = format!("{:#}", StampConfig::declared_file(root.path()).unwrap_err());
    assert!(said.contains(".wsb/stamp.json"), "{said}");
    assert!(said.contains("there is no"), "{said}");
}

#[test]
fn asking_for_what_the_configuration_does_not_name_says_so() {
    let root = with_config(Some(r#"{"declared": "workspace.json"}"#));
    let said = format!("{:#}", StampConfig::build_root(root.path()).unwrap_err());
    assert!(said.contains("\"build_root\""), "{said}");
    assert!(said.contains("names none"), "{said}");
}

#[test]
fn an_unknown_key_is_refused_rather_than_ignored() {
    let root = with_config(Some(r#"{"declared": "workspace.json", "build": "b"}"#));
    let said = format!("{:#}", StampConfig::load(root.path()).unwrap_err());
    assert!(said.contains("unknown field"), "{said}");
}