Skip to main content

TestCase

Struct TestCase 

Source
pub struct TestCase { /* private fields */ }
Expand description

Declarative test builder for inline plugin tests.

Chain expectations and then call run() to execute:

use nginx_lint_plugin::prelude::*;
use nginx_lint_plugin::testing::TestCase;

TestCase::new("http {\n    autoindex on;\n}")
    .expect_error_count(1)
    .expect_error_on_line(2)
    .expect_message_contains("autoindex")
    .expect_has_fix()
    .expect_fix_produces("http {\n    autoindex off;\n}")
    .run(&MyPlugin);

§Available Expectations

MethodDescription
expect_error_count(n)Exact error count
expect_no_errors()No errors
expect_error_on_line(n)Error on specific line
expect_message_contains(s)Error message substring
expect_has_fix()At least one error has a fix
expect_fix_on_line(n)Fix targets specific line
expect_fix_produces(s)Verify fix output

Implementations§

Source§

impl TestCase

Source

pub fn new(content: impl Into<String>) -> Self

Create a new test case with the given config content

Source

pub fn expect_error_count(self, count: usize) -> Self

Expect a specific number of errors

Source

pub fn expect_no_errors(self) -> Self

Expect no errors

Source

pub fn expect_error_on_line(self, line: usize) -> Self

Expect at least one error on the given line

Source

pub fn expect_message_contains(self, substring: impl Into<String>) -> Self

Expect error messages to contain the given substring

Source

pub fn expect_has_fix(self) -> Self

Expect at least one error to have a fix

Source

pub fn expect_fix_on_line(self, line: usize) -> Self

Expect a fix on a specific line

Source

pub fn expect_fix_produces(self, expected: impl Into<String>) -> Self

Expect that applying all fixes produces the given output

Source

pub fn run<P: Plugin>(self, plugin: &P)

Run the test case with the given plugin

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.