Skip to content

Commit 9e030a6

Browse files
committed
Improve System module type specifications coverage
1 parent 7c5ce0c commit 9e030a6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/elixir/lib/system.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ defmodule System do
2525
@doc """
2626
Returns Elixir's version as binary.
2727
"""
28+
@spec version() :: String.t
2829
def version, do: "0.7.2.dev"
2930

3031
@doc """
3132
Returns a keywords list with version, git tag info and date.
3233
"""
34+
@spec build_info() :: Keyword.t
3335
def build_info do
3436
[version: version, tag: get_describe, date: get_date]
3537
end
3638

3739
@doc """
3840
Returns the list of command-line arguments passed to the program.
3941
"""
42+
@spec argv() :: [String.t]
4043
def argv do
4144
:gen_server.call(:elixir_code_server, :argv)
4245
end
@@ -61,6 +64,8 @@ defmodule System do
6164
If `command` is a char list, a char list is returned.
6265
Returns a binary otherwise.
6366
"""
67+
@spec cmd(char_list) :: char_list
68+
@spec cmd(String.t) :: String.t
6469
def cmd(command) when is_list(command) do
6570
:os.cmd(command)
6671
end
@@ -77,6 +82,8 @@ defmodule System do
7782
If `command` is a char list, a char list is returned.
7883
Returns a binary otherwise.
7984
"""
85+
@spec find_executable(char_list) :: char_list | nil
86+
@spec find_executable(String.t) :: String.t | nil
8087
def find_executable(command) when is_list(command) do
8188
:os.find_executable(command) || nil
8289
end
@@ -93,6 +100,7 @@ defmodule System do
93100
given as a single string of the format "VarName=Value", where VarName is the
94101
name of the variable and Value its value.
95102
"""
103+
@spec get_env() :: [{String.t, String.t}]
96104
def get_env do
97105
Enum.map :os.getenv, :unicode.characters_to_binary &1
98106
end
@@ -102,6 +110,7 @@ defmodule System do
102110
`varname` as a binary, or nil if the environment
103111
variable is undefined.
104112
"""
113+
@spec get_env(String.t) :: String.t | nil
105114
def get_env(varname) do
106115
case :os.getenv(to_char_list(varname)) do
107116
false -> nil
@@ -115,19 +124,23 @@ defmodule System do
115124
116125
See http://www.erlang.org/doc/man/os.html#getpid-0 for more info.
117126
"""
127+
@spec get_pid() :: String.t
118128
def get_pid, do: list_to_binary(:os.getpid)
119129

120130
@doc """
121131
Sets a new `value` for the environment variable `varname`.
122132
"""
133+
@spec put_env(String.t, String.t | char_list) :: :ok
123134
def put_env(varname, value) when is_binary(value) or is_list(value) do
124135
:os.putenv to_char_list(varname), :unicode.characters_to_list(value)
136+
:ok
125137
end
126138

127139
@doc """
128140
Sets a new value for each environment variable corresponding
129141
to each key in `dict`.
130142
"""
143+
@spec put_env(Dict.t) :: :ok
131144
def put_env(dict) do
132145
Enum.each dict, fn {key, val} -> put_env key, val end
133146
end

0 commit comments

Comments
 (0)