Skip to main content

Module testing

Module testing 

Source
Expand description

A small rule-test harness (#2842).

Run a rule against an annotated fixture and check that its matches line up with inline // ruleid: / // ok: comments — the Semgrep convention, adapted to be language-agnostic:

  // ruleid: no-foo
  foo();              // <- must match `no-foo`
  // ok: no-foo
  bar();              // <- must NOT match `no-foo`
  baz();              // <- no annotation: must NOT match either

An annotation comment sits on its own line and targets the next line. The check is strict: every match must be covered by a // ruleid: (an un-annotated match is a false positive), and every // ruleid: line must match (a missing match is a false negative).

Structs§

InlineTestReport
The outcome of running one rule against one annotated fixture.
TestFailure
One failed expectation in a fixture.

Enums§

Expectation
What an annotation asserts about the line it targets.
FailureKind
Why a fixture line failed its expectation.

Functions§

run_inline_test
Run rule against source and compare its matches with the fixture’s inline // ruleid: / // ok: annotations.