Skip to content

Commit

Permalink
Upgrade to Elixir 1.17, fix step warning (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromss authored Sep 9, 2024
1 parent 5c04914 commit 9d4ae3f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.6.3
erlang 20.3
erlang 27.0.1
elixir 1.17.2-otp-27
16 changes: 2 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
language: elixir
sudo: false
elixir:
- 1.6.3
- 1.7.4
- 1.8.0
- 1.17.2
otp_release:
- 19.0
- 20.1
- 21.2
matrix:
exclude:
- elixir: 1.6.3
otp_release: 21.2
- elixir: 1.8.0
otp_release: 18.3
- elixir: 1.8.0
otp_release: 19.0
- 27.0.1
before_script:
- mix local.hex --force
- mix deps.get --only test
Expand Down
1 change: 0 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
5 changes: 4 additions & 1 deletion lib/mecks_unit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ defmodule MecksUnit do
|> Enum.map(fn
{:def, _, [{func, _meta, args} | _tail]} ->
{module, func, args |> List.wrap() |> length()}
_ -> nil ## for mofule attributes

## for mofule attributes
_ ->
nil
end)
|> Enum.filter(&(&1 != nil))
end
Expand Down
70 changes: 44 additions & 26 deletions lib/mecks_unit/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,65 @@ defmodule MecksUnit.Case do
quote do
postfix = if unquote(preserve), do: "__INDEX__", else: @mock_index

name = Module.concat([
Enum.join([__MODULE__, postfix]),
unquote_splicing(List.wrap(name))
])

attrs = if unquote(attributes), do:
Enum.map(unquote(attributes), fn attr ->
val = Module.get_attribute(__MODULE__, attr, :default)
if val == :default do
nil
else
{:@, [line: 0], [{attr, [line: 0], [ Macro.escape(val) ]}]}
end
end)
|> Enum.filter(&(&1 != nil)),
else: []
name =
Module.concat([
Enum.join([__MODULE__, postfix]),
unquote_splicing(List.wrap(name))
])

attrs =
if unquote(attributes),
do:
Enum.map(unquote(attributes), fn attr ->
val = Module.get_attribute(__MODULE__, attr, :default)

if val == :default do
nil
else
{:@, [line: 0], [{attr, [line: 0], [Macro.escape(val)]}]}
end
end)
|> Enum.filter(&(&1 != nil)),
else: []

block = unquote(Macro.escape(block))

cond do
unquote(as) != nil -> @flagged_mocks {unquote(as), name, attrs ++ block}
unquote(preserve) -> @preserved_mocks {name, attrs ++ block}
true -> @mocks {name, attrs ++ block}
unquote(preserve) -> @preserved_mocks {name, attrs ++ block}
true -> @mocks {name, attrs ++ block}
end
end
end

defmacro mocked_test(message, options \\ [], pattern \\ nil, block) do
{options, pattern} = cond do
Keyword.keyword?(options) -> {options, pattern}
{options, pattern} =
cond do
Keyword.keyword?(options) -> {options, pattern}
true -> {[], options}
end
args = if pattern != nil, do: [message, pattern], else: [message]

args = if pattern != nil, do: [message, pattern], else: [message]

quote do
used_flags = if unquote(options) != nil, do: Keyword.get(unquote(options), :use), else: nil
used_mocks = if used_flags != nil, do: Enum.filter(Enum.map(@flagged_mocks, fn
{k, n, b} -> if k in used_flags, do: {n, b}, else: nil
end), &(&1 != nil)), else: []

MecksUnit.define_mocks(Enum.reverse(@preserved_mocks) ++ @mocks ++ used_mocks, __MODULE__, @mock_index)
used_mocks =
if used_flags != nil,
do:
Enum.filter(
Enum.map(@flagged_mocks, fn
{k, n, b} -> if k in used_flags, do: {n, b}, else: nil
end),
&(&1 != nil)
),
else: []

MecksUnit.define_mocks(
Enum.reverse(@preserved_mocks) ++ @mocks ++ used_mocks,
__MODULE__,
@mock_index
)

test unquote_splicing(args) do
mock_env = Enum.join([__MODULE__, @mock_index])
Expand Down Expand Up @@ -90,7 +108,7 @@ defmodule MecksUnit.Case do
|> Enum.reduce([""], fn {p, {m, f, a}, r}, calls ->
p = inspect(p)
m = String.replace("#{m}", "Elixir.", "")
a = String.slice(inspect(a), 1..-2)
a = String.slice(inspect(a), 1..-2//-1)
r = inspect(r)
["#{p} #{m}.#{f}(#{a}) #=> #{r}"]
end)
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ defmodule MecksUnit.MixProject do

defp deps do
[
{:meck, "~> 0.8.8"},
{:ex_doc, "~> 0.18.0", only: :dev, runtime: false}
{:meck, "~> 0.8"},
{:ex_doc, "~> 0.18", only: :dev, runtime: false}
]
end

Expand Down
11 changes: 8 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
%{
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
"earmark": {:hex, :earmark, "1.4.47", "7e7596b84fe4ebeb8751e14cbaeaf4d7a0237708f2ce43630cfd9065551f94ca", [:mix], [], "hexpm", "3e96bebea2c2d95f3b346a7ff22285bc68a99fbabdad9b655aa9c6be06c698f8"},
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
"ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"},
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
}
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Code.put_compiler_option(:warnings_as_errors, true)
ExUnit.start()
MecksUnit.mock()

0 comments on commit 9d4ae3f

Please sign in to comment.