From 62cc7026f9ebc76ba195f9f158d29ff76b8d375b Mon Sep 17 00:00:00 2001 From: akash-akya Date: Sat, 21 Sep 2024 21:16:41 +0530 Subject: [PATCH] Update tests to make it work on Windows --- lib/ex_cmd.ex | 6 +++--- lib/ex_cmd/process.ex | 4 ++-- test/ex_cmd/process_test.exs | 14 +++++++------- test/scripts/write_stderr.sh | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/ex_cmd.ex b/lib/ex_cmd.ex index 63c3abb..7b7bbf9 100644 --- a/lib/ex_cmd.ex +++ b/lib/ex_cmd.ex @@ -122,7 +122,7 @@ 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" ``` @@ -130,7 +130,7 @@ defmodule ExCmd do 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"] ``` @@ -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() ``` diff --git a/lib/ex_cmd/process.ex b/lib/ex_cmd/process.ex index ccf7454..db2dd23 100644 --- a/lib/ex_cmd/process.ex +++ b/lib/ex_cmd/process.ex @@ -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 diff --git a/test/ex_cmd/process_test.exs b/test/ex_cmd/process_test.exs index 33c3c23..e935fff 100644 --- a/test/ex_cmd/process_test.exs +++ b/test/ex_cmd/process_test.exs @@ -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) @@ -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 @@ -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 @@ -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 {: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 @@ -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) @@ -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 diff --git a/test/scripts/write_stderr.sh b/test/scripts/write_stderr.sh index 62330df..c341ee8 100755 --- a/test/scripts/write_stderr.sh +++ b/test/scripts/write_stderr.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "$1" >> /dev/stderr +echo "$1" >&2