We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cb0a120 commit f38a490Copy full SHA for f38a490
src/gleam/erlang/port.gleam
@@ -1,4 +1,5 @@
1
import gleam/dynamic
2
+import gleam/erlang/charlist.{type Charlist}
3
4
/// Ports are how code running on the Erlang virtual machine interacts with
5
/// 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 {
33
34
pub type PortOptions {
35
Arg0(String)
36
Args(List(String))
- Env(List(#(String, String)))
37
+ Env(List(#(Charlist, Charlist)))
38
Cd(String)
39
Binary
40
test/gleam/erlang/port_test.gleam
@@ -1,6 +1,7 @@
import gleam/erlang/port
import gleam/erlang/port/receive.{Data, ExitStatus}
import gleam/erlang/process.{receive, port_open, port_connect, port_subject}
+import gleam/erlang/charlist
6
@external(erlang, "gleam_erlang_test_ffi", "assert_gleam_panic")
7
fn assert_panic(f: fn() -> t) -> String
@@ -18,6 +19,21 @@ pub fn port_open_test() {
18
19
assert Error(Nil) == receive(subject, 100)
20
}
21
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)
+ assert Ok(Data(<<"test123\n">>)) == receive(subject, 100)
+}
pub fn fail_port_open_test() {
let assert Error(port.Enoent) = port.open(
port.spawn_executable("/bin/doesntexist"),
0 commit comments