Skip to content

Commit

Permalink
Fix skipped test
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Aug 20, 2024
1 parent 61e8452 commit 5835a6c
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions test/gettext/new_backend_setup_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# https://github.com/elixir-gettext/gettext/issues/330
defmodule Gettext.NewBackendSetupTest do
# https://github.com/elixir-gettext/gettext/issues/330
use ExUnit.Case, async: true

import ExUnit.CaptureIO
import GettextTest.MixProjectHelpers
# Has to be async: false since it changes Elixir compiler options.
use ExUnit.Case, async: false

@moduletag :tmp_dir

Expand Down Expand Up @@ -34,29 +32,37 @@ defmodule Gettext.NewBackendSetupTest do
end

describe "compile-time dependencies" do
@tag :skip
test "are not created for modules that use the backend",
%{test: test, tmp_dir: tmp_dir} = context do
create_test_mix_file(context)

write_file(context, "lib/my_app.ex", """
defmodule MyApp.Gettext do
use Gettext.Backend, otp_app: #{inspect(test)}
end
defmodule MyApp do
use Gettext, backend: MyApp.Gettext
end
""")

output =
in_project(test, tmp_dir, fn _module ->
capture_io(fn -> Mix.Task.run("compile") end)
capture_io(fn -> Mix.Task.run("xref", ["trace", "lib/my_app.ex"]) end)
end)

assert output =~ ~r"lib/my_app\.ex:\d+: alias MyApp\.Gettext \(runtime\)\n"
refute output =~ ~r"lib/my_app\.ex:\d+: alias MyApp\.Gettext \(compile\)\n"
test "are not created for modules that use the backend", %{test: test} do

Check failure on line 35 in test/gettext/new_backend_setup_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.13 | Erlang/OTP 24.1)

test compile-time dependencies are not created for modules that use the backend (Gettext.NewBackendSetupTest)
top_level_module = :"Elixir.Gettext_#{test}"
backend_module = Module.concat(top_level_module, Gettext)

Code.eval_quoted(
quote do
defmodule unquote(backend_module) do
use Gettext.Backend, otp_app: unquote(test)
end
end
)

old_compiler_opts = Code.compiler_options(tracers: [__MODULE__])
on_exit(fn -> Code.compiler_options(old_compiler_opts) end)

Code.compile_quoted(
quote do
defmodule unquote(top_level_module) do
use Gettext, backend: unquote(backend_module)
end
end
)

assert_received {:trace, {:require, _meta, Gettext.Macros, _opts}}
refute_received {:trace, {:require, _meta, ^backend_module, _opts}}
refute_received {:trace, {:import, _meta, ^backend_module, _opts}}
end
end

def trace(event, _env) do
send(self(), {:trace, event})
:ok
end
end

0 comments on commit 5835a6c

Please sign in to comment.