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_dirafter doc tests finish. If you are runninggleedoc.runprogrammatically, please always set this toTrue.
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 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:
- First pass (env var unset): generate the test files, set the env var,
then re-invoke
gleam testviashellout, forwarding any CLI arguments captured withargv. The original process does not runtest_mainitself. - Second pass (env var set): skip generation, unset the env var, and
invoke
test_maindirectly so the freshly-generated tests run.