Skip to content

Commit

Permalink
Pass --no-compile to tasks in tests and disable code path pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed May 20, 2024
1 parent f3900ab commit c4fb1cc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 83 deletions.
2 changes: 1 addition & 1 deletion installer/test/mix_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule MixHelper do

try do
capture_io(:stderr, fn ->
Mix.Project.in_project(app, path, [], fun)
Mix.Project.in_project(app, path, [prune_code_paths: false], fun)
end)
after
Mix.Project.push(name, file)
Expand Down
5 changes: 4 additions & 1 deletion lib/mix/tasks/phx.digest.clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ defmodule Mix.Tasks.Phx.Digest.Clean do
@doc false
def run(all_args) do
# Ensure all compressors are compiled.
Mix.Task.run("compile", all_args)
if "--no-compile" not in all_args do
Mix.Task.run("compile")
end

{:ok, _} = Application.ensure_all_started(:phoenix)

{opts, _, _} = OptionParser.parse(all_args, switches: @switches, aliases: [o: :output])
Expand Down
5 changes: 4 additions & 1 deletion lib/mix/tasks/phx.digest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ defmodule Mix.Tasks.Phx.Digest do
@doc false
def run(all_args) do
# Ensure all compressors are compiled.
Mix.Task.run("compile", all_args)
if "--no-compile" not in all_args do
Mix.Task.run("compile")
end

Mix.Task.reenable("phx.digest")

{:ok, _} = Application.ensure_all_started(:phoenix)
Expand Down
8 changes: 3 additions & 5 deletions lib/mix/tasks/phx.gen.auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
table: :string,
merge_with_existing_context: :boolean,
prefix: :string,
live: :boolean
live: :boolean,
compile: :boolean
]

@doc false
Expand All @@ -130,18 +131,15 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
hashing_library = build_hashing_library!(opts)

context_args = OptionParser.to_argv(opts, switches: @switches) ++ parsed

{context, schema} = Gen.Context.build(context_args, __MODULE__)

context = put_live_option(context)

Gen.Context.prompt_for_code_injection(context)

if Keyword.get(test_opts, :validate_dependencies?, true) do
if "--no-compile" not in args do
# Needed so we can get the ecto adapter and ensure other
# libraries are loaded.
Mix.Task.run("compile")

validate_required_dependencies!()
end

Expand Down
3 changes: 2 additions & 1 deletion lib/mix/tasks/phx.gen.context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ defmodule Mix.Tasks.Phx.Gen.Context do
context_app: :string,
merge_with_existing_context: :boolean,
prefix: :string,
live: :boolean
live: :boolean,
compile: :boolean
]

@default_opts [schema: true, context: true]
Expand Down
5 changes: 4 additions & 1 deletion lib/mix/tasks/phx.routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ defmodule Mix.Tasks.Phx.Routes do

@doc false
def run(args, base \\ Mix.Phoenix.base()) do
Mix.Task.run("compile", args)
if "--no-compile" not in args do
Mix.Task.run("compile")
end

Mix.Task.reenable("phx.routes")

{opts, args, _} =
Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/phx.digest.clean_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Mix.Tasks.Phx.Digest.CleanTest do
input_path = "priv/static"
:ok = File.mkdir_p!(output_path)

Mix.Tasks.Phx.Digest.Clean.run([input_path, "-o", output_path])
Mix.Tasks.Phx.Digest.Clean.run([input_path, "-o", output_path, "--no-compile"])

msg = "Clean complete for \"#{output_path}\""
assert_received {:mix_shell, :info, [^msg]}
Expand Down
120 changes: 48 additions & 72 deletions test/mix/tasks/phx.gen.auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -226,9 +225,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, true}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -359,9 +357,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
test "works with apps generated with --live", config do
in_tmp_phx_project(config.test, ~w(--live), fn ->
Gen.Auth.run(
~w(Accounts User users --live),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --live --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_file("lib/my_app_web/components/layouts/root.html.heex", fn file ->
Expand Down Expand Up @@ -428,9 +425,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
test "works with apps generated with --no-live", config do
in_tmp_phx_project(config.test, ~w(--no-live), fn ->
Gen.Auth.run(
~w(Accounts User users --no-live),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-live --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_file("lib/my_app_web/components/layouts/root.html.heex", fn file ->
Expand Down Expand Up @@ -494,9 +490,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --web warehouse),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --web warehouse --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -723,9 +718,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -777,9 +771,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.MyXQL,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.MyXQL
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -831,9 +824,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.SQLite3,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.SQLite3
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -885,9 +877,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.TDS,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.TDS
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -941,9 +932,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
with_generator_env(:my_app, [timestamp_type: :utc_datetime], fn ->

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert [migration] = Path.wildcard("priv/repo/migrations/*_create_users_auth_tables.exs")
Expand Down Expand Up @@ -971,9 +961,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --binary-id),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --binary-id --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1004,9 +993,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --hashing-lib bcrypt),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --hashing-lib bcrypt --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand All @@ -1030,9 +1018,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --hashing-lib pbkdf2),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --hashing-lib pbkdf2 --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand All @@ -1056,9 +1043,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --hashing-lib argon2),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --hashing-lib argon2 --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand All @@ -1085,9 +1071,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users --table my_users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --table my_users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1117,9 +1102,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1176,9 +1160,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1244,9 +1227,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
with_generator_env(:my_app_web, [context_app: false], fn ->
assert_raise Mix.Error, ~r/no context_app configured/, fn ->
Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)
end
end)
Expand All @@ -1263,9 +1245,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1296,9 +1277,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1332,9 +1312,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1364,9 +1343,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1441,9 +1419,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts User users),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts User users --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down Expand Up @@ -1509,9 +1486,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
send self(), {:mix_shell_input, :yes?, false}

Gen.Auth.run(
~w(Accounts Admin admins),
ecto_adapter: Ecto.Adapters.Postgres,
validate_dependencies?: false
~w(Accounts Admin admins --no-compile),
ecto_adapter: Ecto.Adapters.Postgres
)

assert_received {:mix_shell, :yes?, [@liveview_option_message]}
Expand Down

0 comments on commit c4fb1cc

Please sign in to comment.