mod common;
fn hooks_yaml() -> String {
common::without_comments(".pre-commit-hooks.yaml")
}
#[test]
fn no_published_hook_installs_the_python_package() {
let yaml = hooks_yaml();
assert!(
!yaml.contains("language: python"),
"a published hook still installs drep as a Python package"
);
assert!(
yaml.contains("language: rust"),
"the published hooks must build the Rust binary"
);
}
#[test]
fn the_markdown_hook_blocks_only_on_error_severity() {
let yaml = hooks_yaml();
assert!(
yaml.contains("drep lint-docs --fail-on error"),
"the markdown hook must gate at error severity"
);
assert!(
!yaml.contains("--strict"),
"--strict blocks on info findings, which no consumer wants in a hook"
);
}
#[test]
fn the_published_pre_push_hook_uses_pre_commit_refs_not_filenames() {
let yaml = hooks_yaml();
let start = yaml
.find("- id: drep-check-push\n")
.expect("published hooks must declare drep-check-push");
let block = &yaml[start..];
let end = block[1..]
.find("\n- id:")
.map_or(block.len(), |offset| offset + 1);
let block = &block[..end];
assert!(
block.contains("entry: drep check --push-gate --pre-commit-push"),
"the published pre-push hook must ask drep to resolve pre-commit's refs: {block}"
);
assert!(
block.contains("pass_filenames: false"),
"pre-commit filenames would select whole-file review: {block}"
);
}
#[test]
fn the_repository_pre_push_hook_uses_the_push_gate_and_ref_adapter() {
let yaml = common::without_comments(".pre-commit-config.yaml");
assert!(
yaml.contains("entry: ./target/release/drep check --push-gate --pre-commit-push"),
"drep must test the same pre-commit ref adapter it publishes"
);
}