take

Hex.pm][shield-hex]][hexpm] [![Hex Docs][shield-docs] [ Apache 2.0JavaScript CompatibleErlang Compatible

IO capture for Gleam tests. Intercepts stdout, stderr, or both and returns the captured output as a string. Works on both Erlang and JavaScript targets.

If your callback returns a Promise, use take_promise instead.

Usage

gleam add --dev take@1
import take

pub fn prints_greeting_test() {
  let #(result, output) = take.with_stdout(fn() {
    io.println("Hello, world!")
    42
  })

  assert 42 == result
  assert "Hello, world!\n" == output
}

pub fn just_the_output_test() {
  assert "Hello, world!\n" == take.capture_stdout(fn() {
    io.println("Hello, world!")
  })
}

Semantic Versioning

Take follows Semantic Versioning 2.0.