pub trait InlineConfigParserwhere
    Self: Clone + Default + Sized + 'static,{
    // Required methods
    fn config_key() -> String;
    fn try_merge(
        &self,
        configs: &[String]
    ) -> Result<Option<Self>, InlineConfigParserError>;

    // Provided methods
    fn validate_configs(natspec: &NatSpec) -> Result<(), 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 validate_configs(natspec: &NatSpec) -> Result<(), InlineConfigError>

Validates all configurations contained in a natspec that apply to the current configuration key.

i.e. Given the invariant config key and a natspec comment of the form,

/// forge-config: default.invariant.runs = 500
/// forge-config: default.invariant.depth = 500
/// forge-config: ci.invariant.depth = 500
/// forge-config: ci.fuzz.runs = 10

would validate the whole invariant configuration.

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

i.e. Given the invariant config key and a vector of config lines

let _config_lines = vec![
    "forge-config: default.invariant.runs = 500",
    "forge-config: default.invariant.depth = 500",
    "forge-config: ci.invariant.depth = 500",
    "forge-config: ci.fuzz.runs = 10"
];

would return the whole set of invariant configs.

 let _result = vec![
    ("runs", "500"),
    ("depth", "500"),
    ("depth", "500"),
 ];

Implementors§