Skip to content

Commit

Permalink
Update tests to make it work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-akya committed Sep 21, 2024
1 parent 11d6849 commit 62cc702
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/ex_cmd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ defmodule ExCmd do
With stderr set to :redirect_to_stdout
```
iex> ExCmd.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :redirect_to_stdout)
iex> ExCmd.stream!(["sh", "-c", "echo foo; echo bar >&2"], stderr: :redirect_to_stdout)
...> |> Enum.into("")
"foo\nbar\n"
```
With stderr set to :disable
```
iex> ExCmd.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :disable)
iex> ExCmd.stream!(["sh", "-c", "echo foo; echo bar >&2"], stderr: :disable)
...> |> Enum.to_list()
["foo\n"]
```
Expand Down Expand Up @@ -224,7 +224,7 @@ defmodule ExCmd do
Stream with stderr redirected to stdout
```
ExCmd.stream!(["sh", "-c", "echo foo; echo bar >> /dev/stderr"], stderr: :redirect_to_stdout)
ExCmd.stream!(["sh", "-c", "echo foo; echo bar >&2"], stderr: :redirect_to_stdout)
|> Stream.map(&IO.write/1)
|> Stream.run()
```
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_cmd/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ defmodule ExCmd.Process do
Run a command without any input or output
```
iex> {:ok, p} = Process.start_link(["sh", "-c", "exit 1"])
iex> {:ok, p} = Process.start_link(["sh", "-c", "exit 2"])
iex> Process.await_exit(p)
{:ok, 1}
{:ok, 2}
```
Single process reading and writing to the command
Expand Down
14 changes: 7 additions & 7 deletions test/ex_cmd/process_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule ExCmd.ProcessTest do
assert :ok == Process.close_stdin(s)
assert :eof == Process.read(s)

assert {:ok, 0} == Process.await_exit(s, 150)
assert {:ok, 0} == Process.await_exit(s, 200)

:timer.sleep(100)
refute Elixir.Process.alive?(s.pid)
Expand Down Expand Up @@ -88,7 +88,7 @@ defmodule ExCmd.ProcessTest do

assert {:ok, "==foo==\n"} = Process.read(s, 100)
assert :eof = Process.read(s, 100)
assert {:ok, 0} = Process.await_exit(s, 150)
assert {:ok, 0} = Process.await_exit(s, 200)
end

test "stderr redirect_to_stdout" do
Expand All @@ -103,7 +103,7 @@ defmodule ExCmd.ProcessTest do

assert {:ok, "==foo==\n==bar==\n"} = Process.read(s, 100)
assert :eof = Process.read(s, 100)
assert {:ok, 0} = Process.await_exit(s, 150)
assert {:ok, 0} = Process.await_exit(s, 200)
end

test "if pipe gets closed on pipe owner exit normally" do
Expand Down Expand Up @@ -195,12 +195,12 @@ defmodule ExCmd.ProcessTest do

test "if await_exit closes stdin implicitly" do
{:ok, s} = Process.start_link(~w(cat))
assert {:ok, 0} = Process.await_exit(s, 150)
assert {:ok, 0} = Process.await_exit(s, 200)
end

test "if await_exit kills the program" do

Check failure on line 201 in test/ex_cmd/process_test.exs

View workflow job for this annotation

GitHub Actions / Windows OTP 27 / Elixir 1.17

test process termination if await_exit kills the program (ExCmd.ProcessTest)
{:ok, s} = Process.start_link(~w(sleep 1000))
assert {:error, :killed} = Process.await_exit(s, 150)
assert {:error, :killed} = Process.await_exit(s, 200)
end

test "if external program terminates on process exit" do
Expand Down Expand Up @@ -361,7 +361,7 @@ defmodule ExCmd.ProcessTest do
end

# external process will be killed with SIGTERM (143)
assert {:error, :killed} = Process.await_exit(s, 150)
assert {:error, :killed} = Process.await_exit(s, 200)

# wait for messages to propagate, if there are any
:timer.sleep(100)
Expand Down Expand Up @@ -560,7 +560,7 @@ defmodule ExCmd.ProcessTest do
{:ok, s} = Process.start_link(~w(sh -c pwd), cd: parent)
{:ok, dir} = Process.read(s)

assert String.trim(dir) == parent
assert Path.dirname(dir) == Path.dirname(parent)
assert {:ok, 0} = Process.await_exit(s)
end

Expand Down
2 changes: 1 addition & 1 deletion test/scripts/write_stderr.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

echo "$1" >> /dev/stderr
echo "$1" >&2

0 comments on commit 62cc702

Please sign in to comment.