diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d304ff3 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,3 @@ +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore index 10f9531..5cff883 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,24 @@ -/.dialyxir -/_build -/cover -/deps -/doc -/docs +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). *.ez + +# Ignore package tarball (built via "mix hex.build"). +exexec-*.tar + diff --git a/.travis.yml b/.travis.yml index 8aa2cae..a043a54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,14 @@ +dist: xenial +sudo: false language: elixir elixir: - - 1.4.1 -dist: trusty + - 1.8.1 otp_release: - - 18.3 -sudo: false + - 21.3 env: - MIX_ENV=test - MIX_ENV=test ELIXIR_ERL_OPTIONS="+T 9" before_script: - mix compile --warnings-as-errors - - mix dialyzer --plt script: - - mix coveralls.travis - - mix dialyzer --halt-exit-status -after_script: - - mix deps.get --only docs - - MIX_ENV=docs mix inch.report -cache: - directories: - - _build - - deps -addons: - apt: - packages: - - libcap-dev + - mix test \ No newline at end of file diff --git a/README.md b/README.md index 5985cc0..4b4358b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/antipax/exexec.svg?branch=master)](https://travis-ci.org/antipax/exexec) [![Coverage Status](https://coveralls.io/repos/github/antipax/exexec/badge.svg?branch=master)](https://coveralls.io/github/antipax/exexec?branch=master) [![Inline docs](http://inch-ci.org/github/antipax/exexec.svg?branch=master)](http://inch-ci.org/github/antipax/exexec) [![Hex.pm package version](https://img.shields.io/hexpm/v/exexec.svg)](https://hex.pm/packages/exexec) [![Hex.pm package license](https://img.shields.io/hexpm/l/exexec.svg)](https://github.com/antipax/exexec/blob/master/LICENSE) +[![Build Status](https://travis-ci.org/ericentin/exexec.svg?branch=master)](https://travis-ci.org/ericentin/exexec) [![Hex.pm package version](https://img.shields.io/hexpm/v/exexec.svg)](https://hex.pm/packages/exexec) [![Hex.pm package license](https://img.shields.io/hexpm/l/exexec.svg)](https://github.com/ericentin/exexec/blob/master/LICENSE) # Exexec @@ -10,14 +10,17 @@ interface as well as some nice Elixir-y goodies on top. ## Installation - 1. Add exexec to your list of dependencies in `mix.exs`: +The package can be installed +by adding `exexec` to your list of dependencies in `mix.exs`: - def deps do - [{:exexec, "~> 0.1"}] - end +```elixir +def deps do + [ + {:exexec, "~> 0.2"} + ] +end +``` - 2. Ensure exexec and erlexec are started before your application: - - def application do - [applications: [:erlexec, :exexec]] - end +Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) +and published on [HexDocs](https://hexdocs.pm). Once published, the docs can +be found at [https://hexdocs.pm/exexec](https://hexdocs.pm/exexec). diff --git a/lib/exexec.ex b/lib/exexec.ex index 8f2f8e9..7708524 100644 --- a/lib/exexec.ex +++ b/lib/exexec.ex @@ -9,68 +9,69 @@ defmodule Exexec do import Exexec.ToErl - @type command :: String.t | [Path.t | [String.t]] + @type command :: String.t() | [Path.t() | [String.t()]] @type os_pid :: non_neg_integer @type gid :: non_neg_integer @type output_file_option :: - {:append, boolean} | - {:mode, non_neg_integer} + {:append, boolean} + | {:mode, non_neg_integer} @type output_device :: :stdout | :stderr @type output_file_options :: [output_file_option] @type output_device_option :: - boolean | - :null | - :close | - :print | - Path.t | - {Path.t, output_file_options} | - pid | - (output_device, os_pid, binary -> any) + boolean + | :null + | :close + | :print + | Path.t() + | {Path.t(), output_file_options} + | pid + | (output_device, os_pid, binary -> any) @type command_option :: - {:monitor, boolean} | - {:sync, boolean} | - {:executable, Path.t} | - {:cd, Path.t} | - {:env, %{String.t => String.t}} | - {:kill_command, String.t} | - {:kill_timeout, non_neg_integer} | - {:kill_group, boolean} | - {:group, String.t} | - {:user, String.t} | - {:success_exit_code, exit_code} | - {:nice, -20..20} | - {:stdin, boolean | :null | :close | Path.t} | - {:stdout, :stderr | output_device_option} | - {:stderr, :stdout | output_device_option} | - {:pty, boolean} + {:monitor, boolean} + | {:sync, boolean} + | {:executable, Path.t()} + | {:cd, Path.t()} + | {:env, %{String.t() => String.t()}} + | {:kill_command, String.t()} + | {:kill_timeout, non_neg_integer} + | {:kill_group, boolean} + | {:group, String.t()} + | {:user, String.t()} + | {:success_exit_code, exit_code} + | {:nice, -20..20} + | {:stdin, boolean | :null | :close | Path.t()} + | {:stdout, :stderr | output_device_option} + | {:stderr, :stdout | output_device_option} + | {:pty, boolean} @type command_options :: [command_option] @type exec_option :: - {:debug, boolean | non_neg_integer} | - {:verbose, boolean} | - {:args, [String.t]} | - {:alarm, non_neg_integer} | - {:user, String.t} | - {:limit_users, [String.t]} | - {:port_path, Path.t} | - {:env, %{String.t => String.t}} + {:debug, boolean | non_neg_integer} + | {:root, boolean} + | {:verbose, boolean} + | {:args, [String.t()]} + | {:alarm, non_neg_integer} + | {:user, String.t()} + | {:limit_users, [String.t()]} + | {:port_path, Path.t()} + | {:env, %{String.t() => String.t()}} @type exec_options :: [exec_option] @type signal :: pos_integer @type on_run :: - {:ok, pid, os_pid} | - {:ok, [{output_device, [binary]}]} | - {:error, any} + {:ok, pid, os_pid} + | {:ok, [{output_device, [binary]}]} + | {:error, any} @type exit_code :: non_neg_integer @@ -171,7 +172,9 @@ defmodule Exexec do Start `Exexec` with `options`. """ @spec start(exec_options) :: {:ok, pid} | {:error, any} - defdelegate start(options), to: :exec + def start(options) do + :exec.start(exec_options_to_erl(options)) + end @doc """ Start `Exexec` and link to calling process. @@ -183,7 +186,9 @@ defmodule Exexec do Start `Exexec` with `options` and link to calling process. """ @spec start_link(exec_options) :: {:ok, pid} | {:error, any} - defdelegate start_link(options), to: :exec + def start_link(options) do + :exec.start_link(exec_options_to_erl(options)) + end @doc """ Interpret `exit_code`. diff --git a/lib/exexec/to_erl.ex b/lib/exexec/to_erl.ex index 0abf38c..aed04a9 100644 --- a/lib/exexec/to_erl.ex +++ b/lib/exexec/to_erl.ex @@ -2,37 +2,36 @@ defmodule Exexec.ToErl do @moduledoc false def command_to_erl(command) when is_list(command) do - Enum.map(command, &to_char_list/1) + Enum.map(command, &to_charlist/1) end def command_to_erl(command) do - to_char_list(command) + to_charlist(command) end def command_options_to_erl(options) do for {key, value} <- options, option = command_option_to_erl(key, value), - do: option + do: option end @boolean_options [:monitor, :sync, :kill_group, :pty] def command_option_to_erl(boolean_option, value) - when boolean_option in @boolean_options do + when boolean_option in @boolean_options do if value, do: boolean_option end @string_options [:executable, :cd, :kill_command, :group, :user] def command_option_to_erl(string_option, value) - when string_option in @string_options do - string_option = - if string_option == :kill_command, do: :kill, else: string_option + when string_option in @string_options do + string_option = if string_option == :kill_command, do: :kill, else: string_option - {string_option, to_char_list(value)} + {string_option, to_charlist(value)} end @integer_options [:kill_timeout, :success_exit_code, :nice] def command_option_to_erl(integer_option, value) - when integer_option in @integer_options do + when integer_option in @integer_options do {integer_option, value} end @@ -46,7 +45,7 @@ defmodule Exexec.ToErl do if value do case value do true -> :stdin - string when is_binary(string) -> {:stdin, to_char_list(string)} + string when is_binary(string) -> {:stdin, to_charlist(string)} other -> {:stdin, other} end end @@ -54,17 +53,21 @@ defmodule Exexec.ToErl do @output_device_options [:stdout, :stderr] def command_option_to_erl(output_device_option, value) - when output_device_option in @output_device_options do - other_option = List.delete(@output_device_options, output_device_option) + when output_device_option in @output_device_options do + [other_option] = List.delete(@output_device_options, output_device_option) case value do - true -> output_device_option - false -> nil + true -> + output_device_option + + false -> + nil + ^other_option -> {output_device_option, other_option} {filename, output_file_options} -> - filename = to_char_list(filename) + filename = to_charlist(filename) output_file_options = output_file_options_to_erl(output_file_options) {output_device_option, filename, output_file_options} @@ -76,7 +79,7 @@ defmodule Exexec.ToErl do def output_device_option_to_erl(:null), do: :null def output_device_option_to_erl(:close), do: :close def output_device_option_to_erl(:print), do: :print - def output_device_option_to_erl(path) when is_binary(path), do: to_char_list(path) + def output_device_option_to_erl(path) when is_binary(path), do: to_charlist(path) def output_device_option_to_erl(pid) when is_pid(pid), do: pid def output_device_option_to_erl(fun) when is_function(fun, 3), do: fun @@ -86,7 +89,7 @@ defmodule Exexec.ToErl do do: option end - def output_file_option_to_erl(:append, value), do: if value, do: :append + def output_file_option_to_erl(:append, value), do: if(value, do: :append) def output_file_option_to_erl(:mode, value), do: {:mode, value} def exec_options_to_erl(options) do @@ -104,6 +107,10 @@ defmodule Exexec.ToErl do end end + def exec_option_to_erl(:root, value) do + {:root, value} + end + def exec_option_to_erl(:verbose, value) do if value do :verbose @@ -114,18 +121,15 @@ defmodule Exexec.ToErl do {:alarm, value} end - @output_device_string_options [:user, :port_path] def exec_option_to_erl(string_option, value) - when string_option in @output_device_string_options do - string_option = - if string_option == :port_path, do: :portexe, else: string_option - {string_option, to_char_list(value)} + when string_option in [:user, :port_path] do + string_option = if string_option == :port_path, do: :portexe, else: string_option + {string_option, to_charlist(value)} end - @output_device_string_list_options [:args, :limit_users] def exec_option_to_erl(string_list_option, value) - when string_list_option in @output_device_string_list_options do - {string_list_option, Enum.map(value, &to_char_list/1)} + when string_list_option in [:args, :limit_users] do + {string_list_option, Enum.map(value, &to_charlist/1)} end def exec_option_to_erl(:env, value) do @@ -133,5 +137,5 @@ defmodule Exexec.ToErl do end def to_env(value), - do: for {key, value} <- value, do: {to_char_list(key), to_char_list(value)} + do: for({key, value} <- value, do: {to_charlist(key), to_charlist(value)}) end diff --git a/mix.exs b/mix.exs index 03717f0..e2fb937 100644 --- a/mix.exs +++ b/mix.exs @@ -1,45 +1,36 @@ -defmodule Exexec.Mixfile do +defmodule Exexec.MixProject do use Mix.Project - @version "0.1.0" + @version "0.2.0" def project do [ app: :exexec, version: @version, - elixir: "~> 1.2", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - deps: deps(), - description: description(), - package: package(), - dialyzer: [ - plt_add_deps: :project, - plt_add_apps: [:erlexec], - ], - source_url: "https://github.com/antipax/exexec", + elixir: "~> 1.8", + start_permanent: Mix.env() == :prod, + source_url: "https://github.com/ericentin/exexec", docs: [ main: "Exexec", extras: ["README.md"], source_ref: "v#{@version}" ], - test_coverage: [tool: ExCoveralls], - preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test], + deps: deps(), + description: description(), + package: package() ] end def application do - [included_applications: [:erlexec]] + [ + extra_applications: [:logger] + ] end defp deps do [ - {:erlexec, "~> 1.7"}, - {:dialyxir, "~> 0.3", only: [:dev, :test]}, - {:earmark, "~> 0.1", only: :dev}, - {:ex_doc, "~> 0.11", only: :dev}, - {:excoveralls, "~> 0.6.2", only: :test}, - {:inch_ex, ">= 0.0.0", only: :docs} + {:erlexec, "~> 1.10"}, + {:ex_doc, "~> 0.20", only: :dev} ] end @@ -50,10 +41,9 @@ defmodule Exexec.Mixfile do defp package do [ files: ["lib", "mix.exs", "README.md", "LICENSE"], - maintainers: ["Eric Entin"], licenses: ["Apache 2.0"], links: %{ - "GitHub" => "https://github.com/antipax/exexec" + "GitHub" => "https://github.com/ericentin/exexec" } ] end diff --git a/mix.lock b/mix.lock index 0d0a6a5..cb8d84e 100644 --- a/mix.lock +++ b/mix.lock @@ -1,19 +1,8 @@ %{ - "bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []}, - "certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []}, - "credo": {:hex, :credo, "0.3.13", "90d2d2deb9d376bb2a63f81126a320c3920ce65acb1294982ab49a8aacc7d89f", [:mix], [{:bunt, "~> 0.1.4", [hex: :bunt, optional: false]}]}, - "dialyxir": {:hex, :dialyxir, "0.5.0", "5bc543f9c28ecd51b99cc1a685a3c2a1a93216990347f259406a910cf048d1d7", [:mix], []}, - "earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []}, - "erlexec": {:hex, :erlexec, "1.7.1", "6ddbd40fa202084ed0bdaf95a50c334acaa5644ae213b903cd4094a78ae79734", [:rebar3], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.12.0", "b774aabfede4af31c0301aece12371cbd25995a21bb3d71d66f5c2fe074c603f", [:mix], [{:earmark, "~> 0.2", [hex: :earmark, optional: false]}]}, - "excoveralls": {:hex, :excoveralls, "0.6.3", "894bf9254890a4aac1d1165da08145a72700ff42d8cb6ce8195a584cb2a4b374", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]}, - "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]}, - "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, - "idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []}, - "inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]}, - "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, - "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}, + "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, + "erlexec": {:hex, :erlexec, "1.10.0", "cba7924cf526097d2082ceb0ec34e7db6bca2624b8f3867fb3fa89c4cf25d227", [:rebar3], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, } diff --git a/test/exexec/to_erl_test.exs b/test/exexec/to_erl_test.exs index 0e2c971..6d4556e 100644 --- a/test/exexec/to_erl_test.exs +++ b/test/exexec/to_erl_test.exs @@ -11,82 +11,82 @@ defmodule Exexec.ToErlTest do test "converts all command options to erl" do output_fun = fn _, _, _ -> :ok end - assert command_options_to_erl([ - monitor: true, - monitor: false, - sync: true, - sync: false, - executable: "executable", - cd: "cd", - env: %{"hello" => "world", "env" => "var"}, - kill_command: "kill_command", - kill_timeout: 123, - kill_group: true, - kill_group: false, - group: "group", - user: "user", - success_exit_code: 12, - nice: 10, - stdin: true, - stdin: false, - stdin: :null, - stdin: :close, - stdin: "stdin", - stdout: true, - stdout: false, - stdout: :null, - stdout: :close, - stdout: :print, - stdout: "stdout", - stdout: {"stdout", append: true, append: false, mode: 0o123}, - stdout: self(), - stdout: output_fun, - stderr: true, - stderr: false, - stderr: :null, - stderr: :close, - stderr: :print, - stderr: "stderr", - stderr: {"stderr", append: true, append: false, mode: 0o12}, - stderr: self(), - stderr: output_fun, - pty: true, - pty: false - ]) == [ - :monitor, - :sync, - {:executable, 'executable'}, - {:cd, 'cd'}, - {:env, [{'env', 'var'}, {'hello', 'world'}]}, - {:kill, 'kill_command'}, - {:kill_timeout, 123}, - :kill_group, - {:group, 'group'}, - {:user, 'user'}, - {:success_exit_code, 12}, - {:nice, 10}, - :stdin, - {:stdin, :null}, - {:stdin, :close}, - {:stdin, 'stdin'}, - :stdout, - {:stdout, :null}, - {:stdout, :close}, - {:stdout, :print}, - {:stdout, 'stdout'}, - {:stdout, 'stdout', [:append, {:mode, 83}]}, - {:stdout, self()}, - {:stdout, output_fun}, - :stderr, - {:stderr, :null}, - {:stderr, :close}, - {:stderr, :print}, - {:stderr, 'stderr'}, - {:stderr, 'stderr', [:append, {:mode, 10}]}, - {:stderr, self()}, - {:stderr, output_fun}, - :pty - ] + assert command_options_to_erl( + monitor: true, + monitor: false, + sync: true, + sync: false, + executable: "executable", + cd: "cd", + env: %{"hello" => "world", "env" => "var"}, + kill_command: "kill_command", + kill_timeout: 123, + kill_group: true, + kill_group: false, + group: "group", + user: "user", + success_exit_code: 12, + nice: 10, + stdin: true, + stdin: false, + stdin: :null, + stdin: :close, + stdin: "stdin", + stdout: true, + stdout: false, + stdout: :null, + stdout: :close, + stdout: :print, + stdout: "stdout", + stdout: {"stdout", append: true, append: false, mode: 0o123}, + stdout: self(), + stdout: output_fun, + stderr: true, + stderr: false, + stderr: :null, + stderr: :close, + stderr: :print, + stderr: "stderr", + stderr: {"stderr", append: true, append: false, mode: 0o12}, + stderr: self(), + stderr: output_fun, + pty: true, + pty: false + ) == [ + :monitor, + :sync, + {:executable, 'executable'}, + {:cd, 'cd'}, + {:env, [{'env', 'var'}, {'hello', 'world'}]}, + {:kill, 'kill_command'}, + {:kill_timeout, 123}, + :kill_group, + {:group, 'group'}, + {:user, 'user'}, + {:success_exit_code, 12}, + {:nice, 10}, + :stdin, + {:stdin, :null}, + {:stdin, :close}, + {:stdin, 'stdin'}, + :stdout, + {:stdout, :null}, + {:stdout, :close}, + {:stdout, :print}, + {:stdout, 'stdout'}, + {:stdout, 'stdout', [:append, {:mode, 83}]}, + {:stdout, self()}, + {:stdout, output_fun}, + :stderr, + {:stderr, :null}, + {:stderr, :close}, + {:stderr, :print}, + {:stderr, 'stderr'}, + {:stderr, 'stderr', [:append, {:mode, 10}]}, + {:stderr, self()}, + {:stderr, output_fun}, + :pty + ] end # {:debug, boolean | non_neg_integer} | @@ -98,28 +98,28 @@ defmodule Exexec.ToErlTest do # {:port_path, Path.t} | # {:env, %{String.t => String.t}} test "converts all exec options to erl" do - assert exec_options_to_erl([ - debug: true, - debug: false, - debug: 1, - verbose: true, - verbose: false, - args: ["arg1", "arg2"], - alarm: 2, - user: "user", - limit_users: ["user1", "user2"], - port_path: "port_path", - env: %{"hello" => "world", "env" => "var"} - ]) == [ - :debug, - {:debug, 1}, - :verbose, - {:args, ['arg1', 'arg2']}, - {:alarm, 2}, - {:user, 'user'}, - {:limit_users, ['user1', 'user2']}, - {:portexe, 'port_path'}, - {:env, [{'env', 'var'}, {'hello', 'world'}]} - ] + assert exec_options_to_erl( + debug: true, + debug: false, + debug: 1, + verbose: true, + verbose: false, + args: ["arg1", "arg2"], + alarm: 2, + user: "user", + limit_users: ["user1", "user2"], + port_path: "port_path", + env: %{"hello" => "world", "env" => "var"} + ) == [ + :debug, + {:debug, 1}, + :verbose, + {:args, ['arg1', 'arg2']}, + {:alarm, 2}, + {:user, 'user'}, + {:limit_users, ['user1', 'user2']}, + {:portexe, 'port_path'}, + {:env, [{'env', 'var'}, {'hello', 'world'}]} + ] end end diff --git a/test/exexec_test.exs b/test/exexec_test.exs index 5fa5f55..b45518a 100644 --- a/test/exexec_test.exs +++ b/test/exexec_test.exs @@ -2,20 +2,7 @@ defmodule ExexecTest do use ExUnit.Case import Exexec - - setup do - {:ok, pid} = Exexec.start() - - on_exit fn -> - try do - GenServer.stop(pid, :shutdown) - catch - _, _ -> :ok - end - end - - :ok - end + import ExUnit.CaptureLog test "kill" do {:ok, _sleep_pid, sleep_os_pid} = run("sleep 10", monitor: true) @@ -27,7 +14,7 @@ defmodule ExexecTest do test "manage" do bash = System.find_executable("bash") - {:ok, _spawner_pid, spawner_os_pid} = run([bash, "-c" ,"sleep 100 & echo $!"], stdout: true) + {:ok, _spawner_pid, spawner_os_pid} = run([bash, "-c", "sleep 100 & echo $!"], stdout: true) sleep_os_pid = receive do @@ -55,11 +42,12 @@ defmodule ExexecTest do assert os_pid(sleep_pid) == {:ok, sleep_os_pid} - {:ok, pid} = Task.start_link fn -> - receive do - {{pid, ref}, :ospid} -> Kernel.send pid, {ref, {:error, :testing}} - end - end + {:ok, pid} = + Task.start_link(fn -> + receive do + {{pid, ref}, :ospid} -> Kernel.send(pid, {ref, {:error, :testing}}) + end + end) assert os_pid(pid) == {:error, :testing} end @@ -69,7 +57,7 @@ defmodule ExexecTest do assert pid(sleep_os_pid) == {:ok, sleep_pid} - assert pid(123411231231) == {:error, :undefined} + assert pid(123_411_231_231) == {:error, :undefined} end test "run" do @@ -104,11 +92,16 @@ defmodule ExexecTest do {:ok, _sleep_pid, sleep_os_pid} = run_link("sleep 100") - try do - set_gid(sleep_os_pid, 123123) - catch - :exit, reason -> assert reason == {{:exit_status, 139}, {:gen_server, :call, [:exec, {:port, {:setpgid, sleep_os_pid, 123123}}]}} - end + capture_log(fn -> + try do + set_gid(sleep_os_pid, 123_123) + catch + :exit, reason -> + assert reason == + {{:exit_status, 139}, + {:gen_server, :call, [:exec, {:port, {:setpgid, sleep_os_pid, 123_123}}]}} + end + end) end test "status" do @@ -144,6 +137,6 @@ defmodule ExexecTest do test "which_children" do {:ok, _sleep_pid, sleep_os_pid} = run_link("sleep 10") - assert which_children == [sleep_os_pid] + assert sleep_os_pid in which_children() end end