Testing

Check rules: contracts and tests

Contracts

VCC001 missing-contract

Non-trivial functions with a return type but no in {} or out {} blocks.

Severity: suggestion | Auto-fix: no

# Flagged
def parse_doc(md: Str) -> DocPage {
    let slug = extract_slug(md)
    let title = extract_title(md)
    let body = extract_body(md)
    return DocPage(slug, title, body)
}

# Better
def parse_doc(md: Str) -> DocPage {
    in {
        len(md) > 0
    }
    out (result) {
        result.slug != ""
    }
    let slug = extract_slug(md)
    let title = extract_title(md)
    let body = extract_body(md)
    return DocPage(slug, title, body)
}

Contracts provide validation, documentation, and automatic mutant-kill conditions.

VCC002 trivial-contract

Contracts that are satisfied whatever the function does: a literal True, a comparison whose two sides are the same text (r == r, x <= x), or an out or post clause that names neither a parameter nor the result nor self. The prover's trivial verdict is the semantic version of this check; the rule catches the shapes that need no solver.

Severity: warning | Auto-fix: no

# Flagged
def process(x: Int) -> Int {
    in {
        True
    }
    return x + 1
}

Replace with a condition that expresses a real semantic obligation:

in {
    x > 0
}

VCC009 optional-out-unspecified

A function returning T? whose out block never says when the result is None. Add a clause about the None case so a mutant that returns None too often, or too rarely, is caught.

Severity: suggestion | Auto-fix: no

Testing

VCT001 single-observe

Test blocks with only one observe statement are likely under-asserting.

Severity: suggestion | Auto-fix: no

# Flagged
test "plan has correct fields" {
    let plan = plan_deploy("prod", "/var/www")
    observe plan is not None
}

# Better
test "plan has correct fields" {
    let plan = plan_deploy("prod", "/var/www")
    observe plan.strategy == DeployStrategy.Rsync
    observe plan.source_dir == "build/"
    observe plan.destination == "/var/www"
}

VCT002 no-negative-test

Module has test blocks but none exercise error or failure paths (no observe throws blocks).

Severity: suggestion | Auto-fix: no

Add tests for invalid input, missing data, empty collections, or error cases:

test "rejects empty input" {
    observe throws { parse_doc("") }
}

test "handles missing file" {
    let result = load_doc("/does/not/exist")
    observe result.is_err()
}

Mutation

VCM001 pure-candidate

Function has no apparent side effects but is not marked pure def.

Severity: suggestion | Auto-fix: no

# Before
def classify_change(path: Str) -> ChangeKind {
    if path.ends_with(".css") {
        return ChangeKind.Css
    }
    return ChangeKind.Unknown
}

# After (fixed)
pure def classify_change(path: Str) -> ChangeKind {
    if path.ends_with(".css") {
        return ChangeKind.Css
    }
    return ChangeKind.Unknown
}

Pure functions are easier to test, contract, and mutate. The rule checks for known effectful calls (print, exit, write_text, read_text, run, etc.) and only flags functions that have none.

← Check rules: idioms
Check rules: safety and design →