Skip to content

Commit f38a490

Browse files
committed
env takes charlist
1 parent cb0a120 commit f38a490

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/gleam/erlang/port.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gleam/dynamic
2+
import gleam/erlang/charlist.{type Charlist}
23

34
/// Ports are how code running on the Erlang virtual machine interacts with
45
/// the outside world. Bytes of data can be sent to and read from ports,
@@ -33,7 +34,7 @@ pub fn spawn_executable(command: String) -> PortCommand {
3334
pub type PortOptions {
3435
Arg0(String)
3536
Args(List(String))
36-
Env(List(#(String, String)))
37+
Env(List(#(Charlist, Charlist)))
3738
Cd(String)
3839
Binary
3940

test/gleam/erlang/port_test.gleam

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gleam/erlang/port
22
import gleam/erlang/port/receive.{Data, ExitStatus}
33
import gleam/erlang/process.{receive, port_open, port_connect, port_subject}
4+
import gleam/erlang/charlist
45

56
@external(erlang, "gleam_erlang_test_ffi", "assert_gleam_panic")
67
fn assert_panic(f: fn() -> t) -> String
@@ -18,6 +19,21 @@ pub fn port_open_test() {
1819
assert Error(Nil) == receive(subject, 100)
1920
}
2021

22+
pub fn port_env_open_test() {
23+
let assert Ok(port) = port.open(
24+
port.spawn_executable("/bin/bash"),
25+
[
26+
port.Args(["-c", "echo $VAR"]),
27+
port.Env([#(charlist.from_string("VAR"), charlist.from_string("test123"))]),
28+
port.UseStdio, port.ExitStatus, port.Binary
29+
]
30+
)
31+
32+
let subject = port_subject(port)
33+
34+
assert Ok(Data(<<"test123\n">>)) == receive(subject, 100)
35+
}
36+
2137
pub fn fail_port_open_test() {
2238
let assert Error(port.Enoent) = port.open(
2339
port.spawn_executable("/bin/doesntexist"),

0 commit comments

Comments
 (0)