gleedoc

Types

Configuration for a gleedoc run.

pub type GleedocConfig {
  GleedocConfig(
    extra_imports: List(String),
    source_dir: String,
    output_dir: String,
    preserve_tests: Bool,
  )
}

Constructors

  • GleedocConfig(
      extra_imports: List(String),
      source_dir: String,
      output_dir: String,
      preserve_tests: Bool,
    )

    Arguments

    extra_imports

    A list of imports that will automatically be applied to every generated test file. Example: ["gleam/int", "gleam/otp/actor"]

    source_dir

    Directory to read source files from, typically “src”

    output_dir

    Directory to write generated tests to, typically “test”

    preserve_tests

    Whether to preserve generated test files in output_dir after doc tests finish. If you are running gleedoc.run programmatically, please always set this to True.

Values

pub fn default() -> GleedocConfig

Returns a GleedocConfig populated with sensible defaults:

  • source_dir: "src"
  • output_dir: "test"
  • extra_imports: []
  • preserve_tests: False
pub fn main() -> Nil

CLI entry point

pub fn run(config: GleedocConfig) -> Result(Nil, snag.Snag)

Run gleedoc on a project, extracting doc tests from source files and generating test files in the output directory.

pub fn run_with(
  config: GleedocConfig,
  test_main: fn() -> Nil,
) -> Nil

Run gleedoc and then execute the project’s tests.

Because gleam test does not pick up newly-generated test files within the same compilation, this function uses a two-pass strategy controlled by the GLEEDOC_GENERATION_RUNNING environment variable:

  1. First pass (env var unset): generate the test files, set the env var, then re-invoke gleam test via shellout, forwarding any CLI arguments captured with argv. The original process does not run test_main itself.
  2. Second pass (env var set): skip generation, unset the env var, and invoke test_main directly so the freshly-generated tests run.
Search Document