wsb 0.275.7622

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": ".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(".build"));
}

/// TEST20108: a build root inside `.wsb/` is refused, naming the file.
///
/// Everything in `.wsb/` is committed. A build there was hidden by an exclude
/// file while `.wsb/` held local state too; with that gone, it would turn up
/// in every `git status` and be committed by the first `git add -A`.
#[test]
fn test20108_a_build_root_inside_the_committed_folder_is_refused() {
    let root = with_config(Some(r#"{"build_root": ".wsb/disposable/build"}"#));
    let said = format!("{:#}", StampConfig::build_root(root.path()).unwrap_err());
    assert!(said.contains("stamp.json") && said.contains("committed"), "{said}");
}

#[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}");
}