requirements.cli.setup_css
Requirements index · View definition
Requirement
habeas setupMUST preserve existing entries inoutput.html.additional-csswhile adding the Habeas stylesheet at most once. It MUST report an error ifadditional-cssis not an array.
Rationale
The tests cover all three obligations in requirements.cli.setup_css.
- Preserve existing entries. The
fixturehelper intests/setup.rswrites abook.tomlwithadditional-css = ["md/custom.css"].setup_is_repeatablerunshabeas setupand then asserts that the resultingbook.tomlstill containsmd/custom.css. It also asserts thatmd/habeas.csswas added. - Add the stylesheet at most once.
setup_is_repeatableruns setup twice. It then assertsbook.matches("md/habeas.css").count() == 1. The second run starts with the stylesheet already present, so this is the case where a duplicate could appear. - Error when
additional-cssis not an array.setup_rejects_invalid_book_configurationincludes a case withadditional-css = "wrong". It asserts that the command fails and that stderr containsoutput.html.additional-css must be an array.
Both tests carry {test} references to the requirement.
I found no further obligation or boundary in the requirement text that needs its own test.
Inputs
Tests
Input 2: outline tests/setup.rs fn[setup_is_repeatable]
- File:
tests/setup.rs - Selector:
fn[setup_is_repeatable] - Kind:
fn tests/setup.rs:335–371
// {test}`requirements.cli.setup`
// {test}`requirements.cli.setup_css`
// {test}`requirements.cli.setup_local_path`
// {test}`requirements.cli.mdbook`
// {test}`requirements.index.detail_pages`
#[test]
fn setup_is_repeatable() {
let temp = fixture();
let project = temp.path();
let local_crate = env!("CARGO_MANIFEST_DIR");
run(project, &["setup", "--path", local_crate]);
assert!(!project.join(".agents/skills").exists());
run(project, &["setup", "--path", local_crate]);
let cargo = fs::read_to_string(project.join("Cargo.toml")).unwrap();
assert!(cargo.contains("[dev-dependencies]"));
assert!(cargo.contains("habeas"));
assert!(cargo.contains("path = "));
let book = fs::read_to_string(project.join("book.toml")).unwrap();
assert!(book.contains("command = \"habeas mdbook\""));
assert!(book.contains("md/habeas.css"));
assert!(book.contains("md/custom.css"));
assert_eq!(book.matches("md/habeas.css").count(), 1);
assert_eq!(
fs::read_to_string(project.join("tests/habeas.rs")).unwrap(),
"#[test]\nfn habeas() {\n habeas::validate();\n}\n"
);
assert!(project.join("md/habeas.css").is_file());
assert!(!project.join(".agents/skills").exists());
let book: toml_edit::DocumentMut = book.parse().unwrap();
assert_eq!(
book["output"]["html"]["fold"]["enable"].as_bool(),
Some(true)
);
assert_eq!(book.to_string().matches("enable").count(), 1, "{book}");
}
Input 3: outline tests/setup.rs fn[setup_rejects_invalid_book_configuration]
- File:
tests/setup.rs - Selector:
fn[setup_rejects_invalid_book_configuration] - Kind:
fn tests/setup.rs:448–505
// {test}`requirements.cli.setup_project`
// {test}`requirements.cli.setup_css`
// {test}`requirements.cli.setup`
#[test]
fn setup_rejects_invalid_book_configuration() {
let temp = fixture();
let project = temp.path();
let binary = env!("CARGO_BIN_EXE_habeas");
for (book, expected) in [
("book = 'wrong'\n", "book must be a table"),
("[book]\nsrc = 7\n", "book.src must be a string"),
("[book]\nsrc = ''\n", "book.src must be a directory"),
("[book]\nsrc = '/outside'\n", "book.src must be a directory"),
(
"[book]\nsrc = \"../outside\"\n",
"book.src must be a directory",
),
(
"[book]\nsrc = 'md/../outside'\n",
"book.src must be a directory",
),
(
"[book]\nsrc = \"md\"\n\n[output.html]\nadditional-css = \"wrong\"\n",
"output.html.additional-css must be an array",
),
(
"[book]\nsrc = \"md\"\n\n[output.html]\nfold = true\n",
"output.html.fold must be a table",
),
] {
fs::write(project.join("book.toml"), book).unwrap();
let output = Command::new(binary)
.args(["setup", "--path", env!("CARGO_MANIFEST_DIR")])
.current_dir(project)
.env("CARGO_NET_OFFLINE", "true")
.output()
.unwrap();
assert!(!output.status.success());
assert!(
String::from_utf8_lossy(&output.stderr).contains(expected),
"{:?}: {}",
book,
String::from_utf8_lossy(&output.stderr)
);
}
fs::write(project.join("book.toml"), "[book]\nsrc = \"md\"\n").unwrap();
fs::remove_file(project.join("md/SUMMARY.md")).unwrap();
let output = Command::new(binary)
.args(["setup", "--path", env!("CARGO_MANIFEST_DIR")])
.current_dir(project)
.env("CARGO_NET_OFFLINE", "true")
.output()
.unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr).contains("cannot find mdBook SUMMARY.md"));
}
Other sources
Input 1: requirements selection requirements.cli.setup_css
requirements.cli.setup_css:md/requirements/cli.md:569–571
:::{req} setup_css
`habeas setup` MUST preserve existing entries in `output.html.additional-css` while adding the Habeas stylesheet at most once. It MUST report an error if `additional-css` is not an array.
:::
Input 4: outline tests/setup.rs fn[fixture]
- File:
tests/setup.rs - Selector:
fn[fixture] - Kind:
fn tests/setup.rs:9–27
// {cite}`habeas:util`
fn fixture() -> TempDir {
let temp = TempDir::new().unwrap();
fs::create_dir_all(temp.path().join("src")).unwrap();
fs::create_dir_all(temp.path().join("md")).unwrap();
fs::write(
temp.path().join("Cargo.toml"),
"[package]\nname = \"sample-project\"\nversion = \"0.1.0\"\nedition = \"2024\"\n",
)
.unwrap();
fs::write(temp.path().join("src/main.rs"), "fn main() {}\n").unwrap();
fs::write(
temp.path().join("book.toml"),
"[book]\nsrc = \"md\"\n\n[output.html]\nadditional-css = [\"md/custom.css\"]\n",
)
.unwrap();
fs::write(temp.path().join("md/SUMMARY.md"), "# Summary\n").unwrap();
temp
}