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

nordisk/holger

server/lib/tests/a_zero_nobody_counted.rs

//! **The false zero, guarded at its source.**
//!
//! `list(..).map(|v| v.len()).unwrap_or(0)` stamped with a REPOSITORY scope was
//! wrong twice: backends that did not override `list` answered an empty listing,
//! so a full repository read as empty; and `unwrap_or` folded a genuine backend
//! error into the same `0`.
//!
//! The fix is `Caps::listing`, which every backend must state (`caps()` has no
//! default), and an unclaimed `list` answers `Unsupported`, never an empty
//! listing. `traits::backend::conformance::check` holds the claim against the
//! method; this guard makes sure every backend crate runs that check.

use std::path::Path;

#[test]
fn every_backend_crate_holds_its_caps_against_its_methods() {
    let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../repository");
    let mut checked = 0;
    let mut missing = Vec::new();
    for entry in std::fs::read_dir(&dir)
        .expect("server/repository")
        .flatten()
    {
        let src_dir = entry.path().join("src");
        let Ok(files) = std::fs::read_dir(&src_dir) else {
            continue;
        };
        let mut src = String::new();
        for f in files.flatten() {
            src.push_str(&std::fs::read_to_string(f.path()).unwrap_or_default());
        }
        if !src.contains("RepositoryBackendTrait for") {
            continue;
        }
        checked += 1;
        if !src.contains("conformance::check") {
            missing.push(entry.file_name().to_string_lossy().to_string());
        }
    }
    assert!(
        checked >= 15,
        "only {checked} backend crate(s) found — the guard is vacuous"
    );
    assert!(
        missing.is_empty(),
        "these backends never run conformance::check: {missing:?}"
    );
}