diff --git a/.travis.yml b/.travis.yml index 4f3b259..ca4a932 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/conform/releases/plugin.ex b/lib/conform/releases/plugin.ex index 445e376..1210d6e 100644 --- a/lib/conform/releases/plugin.ex +++ b/lib/conform/releases/plugin.ex @@ -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 diff --git a/lib/conform/schema.ex b/lib/conform/schema.ex index bdc8431..d0daca7 100644 --- a/lib/conform/schema.ex +++ b/lib/conform/schema.ex @@ -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) @@ -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)) @@ -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 diff --git a/lib/conform/translate.ex b/lib/conform/translate.ex index 4156349..5cc3077 100644 --- a/lib/conform/translate.ex +++ b/lib/conform/translate.ex @@ -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) diff --git a/lib/mix/tasks/conform.archive.ex b/lib/mix/tasks/conform.archive.ex index e151874..ed1ed64 100644 --- a/lib/mix/tasks/conform.archive.ex +++ b/lib/mix/tasks/conform.archive.ex @@ -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), ".") @@ -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 = diff --git a/priv/bin/conform b/priv/bin/conform index 74c6366..cd58af5 100755 Binary files a/priv/bin/conform and b/priv/bin/conform differ diff --git a/test/conf_translate_test.exs b/test/conf_translate_test.exs index 6c2ccd4..20f2beb 100644 --- a/test/conf_translate_test.exs +++ b/test/conf_translate_test.exs @@ -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"]) @@ -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 @@ -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 diff --git a/test/config_test.exs b/test/config_test.exs index d1f16d9..5588cf8 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -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) diff --git a/test/configs/readme_example.exs b/test/configs/readme_example.exs index 37234d2..78db8e5 100644 --- a/test/configs/readme_example.exs +++ b/test/configs/readme_example.exs @@ -1,4 +1,4 @@ use Mix.Config config :my_app, - nodelist: [:'a@foo', :'b@foo'] + nodelist: [:a@foo, :b@foo] diff --git a/test/conform_utils_code_test.exs b/test/conform_utils_code_test.exs index a26fecd..a5b5528 100644 --- a/test/conform_utils_code_test.exs +++ b/test/conform_utils_code_test.exs @@ -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") @@ -16,7 +16,7 @@ defmodule ConformCodeTest do :baz -> :qux end end, - "multi_clause": fn + multi_clause: fn :foo -> bar val -> case val do @@ -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) @@ -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 @@ -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) @@ -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, []} @@ -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]} @@ -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) diff --git a/test/fixtures/test_app/config.exs b/test/fixtures/test_app/config.exs index ec5c81a..61fb981 100644 --- a/test/fixtures/test_app/config.exs +++ b/test/fixtures/test_app/config.exs @@ -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"}] }] diff --git a/test/integration_test.exs b/test/integration_test.exs index 8c8148a..ea7a4ee 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -131,7 +131,7 @@ defmodule IntegrationTest do transforms: [], validators: [] ] - """ |> String.strip(?\n) == result + """ |> String.trim() == result end end diff --git a/test/schemas/complex_schema.exs b/test/schemas/complex_schema.exs index 439a07b..de74a9c 100644 --- a/test/schemas/complex_schema.exs +++ b/test/schemas/complex_schema.exs @@ -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, diff --git a/test/schemas/env_var.schema.exs b/test/schemas/env_var.schema.exs index b73026d..29c3157 100644 --- a/test/schemas/env_var.schema.exs +++ b/test/schemas/env_var.schema.exs @@ -2,7 +2,7 @@ extends: [], import: [], mappings: [ - "envvarconfig": [ + envvarconfig: [ to: "envvarconfig", datatype: :integer, env_var: "NOT_SET" diff --git a/test/schemas/evl_daemon.schema.exs b/test/schemas/evl_daemon.schema.exs index 3c377f5..2e80374 100644 --- a/test/schemas/evl_daemon.schema.exs +++ b/test/schemas/evl_daemon.schema.exs @@ -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( @@ -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( diff --git a/test/schemas/merge_master.schema.exs b/test/schemas/merge_master.schema.exs index 69a660e..156bb3f 100644 --- a/test/schemas/merge_master.schema.exs +++ b/test/schemas/merge_master.schema.exs @@ -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 diff --git a/test/schemas/readme_example.schema.exs b/test/schemas/readme_example.schema.exs index 6ca063d..6d0af9d 100644 --- a/test/schemas/readme_example.schema.exs +++ b/test/schemas/readme_example.schema.exs @@ -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", diff --git a/test/schemas/test.schema.exs b/test/schemas/test.schema.exs index a66a11d..55e6b95 100644 --- a/test/schemas/test.schema.exs +++ b/test/schemas/test.schema.exs @@ -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, []} diff --git a/test/schemas/utf8.schema.exs b/test/schemas/utf8.schema.exs index 6227f92..b6f410f 100644 --- a/test/schemas/utf8.schema.exs +++ b/test/schemas/utf8.schema.exs @@ -2,7 +2,7 @@ extends: [], import: [], mappings: [ - "utf8": [ + utf8: [ commented: false, datatype: :binary, default: "Fixé",