Skip to main content

asserts_something

Function asserts_something 

Source
pub fn asserts_something(code: &str) -> bool
Expand description

Does the code assert anything that could be false?

An assert!/assert_eq!/assert_ne! whose arguments are all literals is true of every program and is not one; ? and unwrap/expect are assertions, because a failure of either fails the doctest. A block with none of those documents a shape and proves nothing about behaviour.

use majordomus_cli::quality::policy::asserts_something;
assert!(!asserts_something("assert!(true);"));
assert!(!asserts_something("assert_eq!(1, 1);"));
assert!(asserts_something("assert_eq!(thing.len(), 3);"));
assert!(asserts_something("let v = parse(\"x\")?;"));
assert!(asserts_something("let v = parse(\"x\").unwrap();"));