Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.layout.project

Requirements index · View definition

evidence Valid

Requirement

The Habeas Codicem project MUST keep its mdBook Markdown in md/ and Rust source in src/, and its own book MUST use the Habeas preprocessor.

Rationale

The tests adequately cover requirements.layout.project. I derived three obligations from its text and mapped each to a test.

  • Markdown in md/: tests/repository.rs#fn[project_book_uses_the_repository_local_preprocessor_alias] asserts that book.toml sets book.src to md. It also asserts that md/SUMMARY.md exists as a file.
  • Rust source in src/: tests/repository.rs#fn[crate_targets_are_declared_in_src] asserts that the Cargo.toml lib path is src/lib.rs. It also asserts that the manifest has exactly one bin, named habeas, with path src/main.rs. The first test additionally checks that src/lib.rs and src/main.rs exist.
  • The book uses the Habeas preprocessor: The first test asserts that preprocessor.habeas in book.toml has the command cargo habeas mdbook and the renderer list ["html"]. It also asserts that .cargo/config.toml defines the habeas alias as run --release -p habeas --. Together these show the book is wired to the project’s own preprocessor.

The helper repository_toml parses the file and returns the table, so the assertions run against the real repository files.

The tests check only the lib and bin targets, not every .rs file. I don’t count that as a gap, because the text doesn’t name any other Rust source and the target declarations are the natural check for “Rust source in src/”.

Inputs

Tests

Input 2: outline tests/repository.rs fn[project_book_uses_the_repository_local_preprocessor_alias]
// {test}`requirements.cli.mdbook`
// {test}`requirements.layout.project`
#[test]
fn project_book_uses_the_repository_local_preprocessor_alias() {
    let book = repository_toml("book.toml");
    assert_eq!(book["book"]["src"].as_str(), Some("md"));
    let preprocessor = &book["preprocessor"]["habeas"];
    assert_eq!(
        preprocessor["command"].as_str(),
        Some("cargo habeas mdbook")
    );
    assert_eq!(
        preprocessor["renderers"],
        toml::Value::Array(vec!["html".into()])
    );
    let cargo = repository_toml(".cargo/config.toml");
    assert_eq!(
        cargo["alias"]["habeas"].as_str(),
        Some("run --release -p habeas --")
    );

    let root = Path::new(env!("CARGO_MANIFEST_DIR"));
    assert!(root.join("md/SUMMARY.md").is_file());
    assert!(root.join("src/lib.rs").is_file());
    assert!(root.join("src/main.rs").is_file());
}
Input 3: outline tests/repository.rs fn[crate_targets_are_declared_in_src]
// {test}`requirements.layout.project`
#[test]
fn crate_targets_are_declared_in_src() {
    let manifest = repository_toml("Cargo.toml");
    assert_eq!(manifest["lib"]["path"].as_str(), Some("src/lib.rs"));
    let bins = manifest["bin"].as_array().unwrap();
    assert_eq!(bins.len(), 1);
    assert_eq!(bins[0]["name"].as_str(), Some("habeas"));
    assert_eq!(bins[0]["path"].as_str(), Some("src/main.rs"));
}

Other sources

Input 1: requirements selection requirements.layout.project
:::{req} project
The Habeas Codicem project MUST keep its mdBook Markdown in `md/` and Rust source in `src/`, and its own book MUST use the Habeas preprocessor.
:::
Input 4: outline tests/repository.rs fn[repository_toml]
// {cite}`habeas:util`
fn repository_toml(path: &str) -> toml::Table {
    repository_file(path).parse().unwrap()
}