foundry_config::inline::conf_parser

Trait InlineConfigParser

Source
pub trait InlineConfigParser
where Self: Clone + Default + Sized + 'static,
{ // Required methods fn config_key() -> String; fn try_merge( &self, configs: &[String], ) -> Result<Option<Self>, InlineConfigParserError>; // Provided methods fn merge( &self, natspec: &NatSpec, ) -> Result<Option<Self>, InlineConfigError> { ... } fn get_config_overrides(config_lines: &[String]) -> Vec<(String, String)> { ... } }
Expand description

This trait is intended to parse configurations from structured text. Foundry users can annotate Solidity test functions, providing special configs just for the execution of a specific test.

An example:

contract MyTest is Test {
/// forge-config: default.fuzz.runs = 100
/// forge-config: ci.fuzz.runs = 500
function test_SimpleFuzzTest(uint256 x) public {...}

/// forge-config: default.fuzz.runs = 500
/// forge-config: ci.fuzz.runs = 10000
function test_ImportantFuzzTest(uint256 x) public {...}
}

Required Methods§

Source

fn config_key() -> String

Returns a config key that is common to all valid configuration lines for the current impl. This helps to extract correct values out of a text.

An example key would be fuzz of invariant.

Source

fn try_merge( &self, configs: &[String], ) -> Result<Option<Self>, InlineConfigParserError>

Tries to override self properties with values specified in the configs parameter.

Returns

  • Some(Self) in case some configurations are merged into self.
  • None in case there are no configurations that can be applied to self.
  • Err(InlineConfigParserError) in case of wrong configuration.

Provided Methods§

Source

fn merge(&self, natspec: &NatSpec) -> Result<Option<Self>, InlineConfigError>

Validates and merges the natspec configs for current profile into the current config.

Source

fn get_config_overrides(config_lines: &[String]) -> Vec<(String, String)>

Given a list of config lines, returns all available pairs (key, value) matching the current config key.

§Examples
assert_eq!(
    get_config_overrides(&[
        "forge-config: default.invariant.runs = 500",
        "forge-config: default.invariant.depth = 500",
        "forge-config: ci.invariant.depth = 500",
        "forge-config: ci.fuzz.runs = 10",
    ]),
    [("runs", "500"), ("depth", "500"), ("depth", "500")]
);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§