Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sudo: false
language: elixir
elixir:
- 1.3
- 1.4
- 1.8
- 1.9
otp_release:
- 18.3
- 19.2
- 21.0
- 22.0
notifications:
email:
- paulschoenfelder@gmail.com
2 changes: 1 addition & 1 deletion lib/conform/releases/plugin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule Conform.ReleasePlugin do
def after_package(_release), do: nil
def after_cleanup(_args), do: nil

defp debug(message), do: apply(Mix.Releases.Logger, :debug, ["conform: " <> message])
defp debug(message), do: apply(Conform.Logger, :debug, ["conform: " <> message])

defp add_archive(conform_overlays, release, schema_src) do
# generate archive
Expand Down
8 changes: 4 additions & 4 deletions lib/conform/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ defmodule Conform.Schema do
def coalesce do
# Get schemas from all dependencies
# Merge schemas for all deps
Mix.Dep.loaded([])
Mix.Dep.load_on_environment([env: Mix.env])
|> Enum.map(fn %Mix.Dep{app: app, opts: opts} ->
Mix.Project.in_project(app, opts[:dest], opts, fn _ -> load!(app) end)
end)
Expand Down Expand Up @@ -430,7 +430,7 @@ defmodule Conform.Schema do
defp get_extends_schema(app_name, src_schema_path) do
# Attempt loading from deps if Mix is available
schema_path = try do
paths = Mix.Dep.loaded(env: Mix.env)
paths = Mix.Dep.load_on_environment([env: Mix.env])
|> Enum.filter(fn %Mix.Dep{app: app} -> app == app_name end)
|> Enum.map(fn %Mix.Dep{opts: opts} ->
Keyword.get(opts, :dest, Keyword.get(opts, :path))
Expand All @@ -440,10 +440,10 @@ defmodule Conform.Schema do
[] -> nil
[app_path] -> Path.join([app_path, "config", "#{app_name}.schema.exs"])
end
catch
_,_ -> nil
rescue
_ -> nil
catch
_,_ -> nil
end
# Next try locating by application
schema_path = case schema_path do
Expand Down
2 changes: 1 addition & 1 deletion lib/conform/translate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule Conform.Translate do
val -> parse_datatype(datatype, [val], mapping)
end
end
for {conf_key, value} <- results, not datatype in [:complex, [list: :complex]] do
for {conf_key, value} <- results, datatype not in [:complex, [list: :complex]] do
parsed = case value do
nil -> default
_ -> parse_datatype(datatype, List.wrap(value), mapping)
Expand Down
3 changes: 1 addition & 2 deletions lib/mix/tasks/conform.archive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ defmodule Mix.Tasks.Conform.Archive do
"""

def run([schema_path]) do
Mix.Tasks.Loadpaths.run([])
curr_path = File.cwd!
schema_dir = Path.dirname(schema_path) |> Path.expand
[release_name|_] = String.split(Path.basename(schema_path), ".")
Expand All @@ -22,7 +21,7 @@ defmodule Mix.Tasks.Conform.Archive do
{[], []} ->
{:ok, "", []}
{_, _} ->
specified_deps = Mix.Dep.loaded(env: Mix.env)
specified_deps = Mix.Dep.load_on_environment([env: Mix.env])
# collect deps which are specifed outside of deps,
# like: [:name, path: "path_to_lib"]
deps_paths =
Expand Down
Binary file modified priv/bin/conform
Binary file not shown.
49 changes: 30 additions & 19 deletions test/conf_translate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ defmodule ConfTranslateTest do
assert expected == conf
end

# Something was changed in Elixir 1.9 dependencies handling and now
# it uses top-level dependencies of conform instead of fixtures applications
# in this test. That's why Mix.Task.run/1 was replaced with System.cmd/2
# and only mix conform.archive task is only called in Mix.project.in_project
# context. Otherwise Elixir 1.9 will not find fake_app dependency, but instead of
# this top-level dependencies will be used (dependencies of conform itself).
test "can generate config as Elixir terms from .conf and schema with imports" do
# Application.load :example_app
# Application.load :fake_app
cwd = File.cwd!
script = Path.join([cwd, "priv", "bin", "conform"])
example_app_path = Path.join([cwd, "test", "fixtures", "example_app"])
Expand All @@ -68,26 +76,29 @@ defmodule ConfTranslateTest do

File.touch(sys_config_path)
capture_io(fn ->
{:ok, zip_path, _build_files} =
Mix.Project.in_project(:example_app, example_app_path,
File.cd(example_app_path)
System.put_env("MIX_ENV", "test")
System.cmd("mix", ["deps.get"])
System.cmd("mix", ["deps.compile"])
System.cmd("mix", ["compile"])

{:ok, zip_path, _build_files} = Mix.Project.in_project(:example_app, example_app_path,
fn _ ->
Mix.Task.run("deps.get")
Mix.Task.run("deps.compile")
Mix.Task.run("compile")
Mix.Task.run("conform.archive", [schema_path])
Mix.Tasks.Conform.Archive.run([schema_path])
end)

expected = [
fake_app: [greeting: "hi!"],
test: [another_val: 3, debug_level: :info, env: :prod]
]

_ = Mix.Task.run("escript.build", ["--force"])
{_output, 0} = System.cmd(script, ["--schema", schema_path, "--conf", conf_path, "--output-dir", sys_config_dir])
{:ok, [sysconfig]} = :file.consult(sys_config_path)
assert "test.schema.ez" = Path.basename(zip_path)
assert ^expected = Conform.Utils.sort_kwlist(sysconfig)
File.rm(sys_config_path)
File.cd(cwd)

expected = [
fake_app: [greeting: "hi!"],
test: [another_val: 3, debug_level: :info, env: :prod]
]

_ = Mix.Task.run("escript.build", ["--force"])
{_output, 0} = System.cmd(script, ["--schema", schema_path, "--conf", conf_path, "--output-dir", sys_config_dir])
{:ok, [sysconfig]} = :file.consult(sys_config_path)
assert "test.schema.ez" = Path.basename(zip_path)
assert ^expected = Conform.Utils.sort_kwlist(sysconfig)
File.rm(sys_config_path)
end)
end

Expand Down Expand Up @@ -189,7 +200,7 @@ defmodule ConfTranslateTest do

config_path = Path.join(System.tmp_dir!, "conform_test.config")
:ok = config_path |> Conform.SysConfig.write(config)
result = config_path |> String.to_char_list |> :file.consult
result = config_path |> String.to_charlist |> :file.consult
config_path |> File.rm!
assert {:ok, [^config]} = result
end
Expand Down
2 changes: 1 addition & 1 deletion test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule ConfigTest do
second: [age: 40, username: "username2"]],
db: [hosts: [{"127.0.0.1", "8000"}, {"127.0.0.2", "8001"}]],
max_demand: 40,
nodelist: [:'a@bar', :'b@bar'],
nodelist: [:a@bar, :b@bar],
some_val: :foo
]]
assert expected == Conform.Utils.sort_kwlist(sysconfig)
Expand Down
2 changes: 1 addition & 1 deletion test/configs/readme_example.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config

config :my_app,
nodelist: [:'a@foo', :'b@foo']
nodelist: [:a@foo, :b@foo]
14 changes: 6 additions & 8 deletions test/conform_utils_code_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule ConformCodeTest do
test "can stringify function and case blocks" do
source = """
[transforms: [
"single_clause": fn val ->
single_clause: fn val ->
case val do
foo when foo in [:foo] ->
bar = String.to_atom("bar")
Expand All @@ -16,7 +16,7 @@ defmodule ConformCodeTest do
:baz -> :qux
end
end,
"multi_clause": fn
multi_clause: fn
:foo -> bar
val ->
case val do
Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule ConformCodeTest do
end
]
]
""" |> String.strip(?\n)
""" |> String.trim()

{:ok, quoted} = Code.string_to_quoted(source)
assert stringified == Conform.Utils.Code.stringify(quoted)
Expand All @@ -80,7 +80,7 @@ defmodule ConformCodeTest do
* active-debug: it's going to be active, with verbose debugging information
Just testing "nested quotes"
\"\"\"
""" |> String.strip(?\n)
""" |> String.trim()

{:ok, singleline_quoted} = singleline |> Macro.to_string |> Code.string_to_quoted
{:ok, multiline_quoted} = multiline |> Macro.to_string |> Code.string_to_quoted
Expand Down Expand Up @@ -131,7 +131,7 @@ defmodule ConformCodeTest do
]
]
]
""" |> String.strip(?\n)
""" |> String.trim()

{:ok, quoted} = data |> Code.string_to_quoted
{schema, _} = Code.eval_quoted(quoted, file: "nofile", line: 0)
Expand All @@ -148,7 +148,6 @@ defmodule ConformCodeTest do
case val do
:active ->
data = %{log: :warn}
more_data = %{data | :log => :warn}
{:on, [data: data]}
:'active-debug' -> {:on, [debug: true]}
:passive -> {:off, []}
Expand Down Expand Up @@ -176,7 +175,6 @@ defmodule ConformCodeTest do
case val do
:active ->
data = %{log: :warn}
more_data = %{data | log: :warn}
{:on, [data: data]}
:"active-debug" ->
{:on, [debug: true]}
Expand All @@ -199,7 +197,7 @@ defmodule ConformCodeTest do
end
]
]
""" |> String.strip(?\n)
""" |> String.trim()

{:ok, quoted} = data |> Code.string_to_quoted
assert expected == (quoted |> Conform.Utils.Code.stringify)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test_app/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ proxy = [{:default_route, {{127,0,0,1}, 1813, "secret"}},

config :test,
env: :wat,
"debug_level": {:on, [:passive]}
debug_level: {:on, [:passive]}

config :test, :servers,
proxy: [{ {:eradius_proxy, 'proxy', proxy}, [{'127.0.0.1', "secret"}] }]
Expand Down
2 changes: 1 addition & 1 deletion test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule IntegrationTest do
transforms: [],
validators: []
]
""" |> String.strip(?\n) == result
""" |> String.trim() == result
end

end
4 changes: 2 additions & 2 deletions test/schemas/complex_schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
default: []
],
# just a val
"some_val": [
some_val: [
doc: "Just some atom.",
to: "my_app.some_val",
datatype: :atom,
default: :foo
],

"some_val2": [
some_val2: [
doc: "Just some float.",
to: "my_app.some_val2",
datatype: :float,
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/env_var.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extends: [],
import: [],
mappings: [
"envvarconfig": [
envvarconfig: [
to: "envvarconfig",
datatype: :integer,
env_var: "NOT_SET"
Expand Down
4 changes: 2 additions & 2 deletions test/schemas/evl_daemon.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
],
transforms: [
"evl_daemon.zones": fn (conf) ->
[{key, zones}] = Conform.Conf.get(conf, "evl_daemon.zones")
[{_key, zones}] = Conform.Conf.get(conf, "evl_daemon.zones")

Enum.reduce(zones, Map.new, fn [zone, description], zone_map ->
Map.put(
Expand All @@ -138,7 +138,7 @@
end)
end,
"evl_daemon.partitions": fn (conf) ->
[{key, partitions}] = Conform.Conf.get(conf, "evl_daemon.partitions")
[{_key, partitions}] = Conform.Conf.get(conf, "evl_daemon.partitions")

Enum.reduce(partitions, Map.new, fn [partition, description], partition_map ->
Map.put(
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/merge_master.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end
console_handler = case Conform.Conf.get(conf, "lager.handlers.lager_console_backend.level") do
[] -> []
[{path, level}] -> [lager_console_backend: level]
[{_path, level}] -> [lager_console_backend: level]
end
Conform.Conf.remove(conf, "lager.handlers")
console_handler ++ file_handlers
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/readme_example.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
doc: "A simple list",
to: "my_app.nodelist",
datatype: [list: :atom],
default: [:'a@foo', :'b@foo']
default: [:a@foo, :b@foo]
],
"my_app.db.hosts": [
doc: "Remote database hosts",
Expand Down
1 change: 0 additions & 1 deletion test/schemas/test.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
case val do
:active ->
data = %{log: :warn}
more_data = %{data | :log => :warn}
{:on, [data: data]}
:'active-debug' -> {:on, [debug: true]}
:passive -> {:off, []}
Expand Down
2 changes: 1 addition & 1 deletion test/schemas/utf8.schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extends: [],
import: [],
mappings: [
"utf8": [
utf8: [
commented: false,
datatype: :binary,
default: "Fixé",
Expand Down