-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Refactor escript tests to use less modules #13732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,46 +13,10 @@ defmodule Mix.Tasks.EscriptTest do | |
end | ||
end | ||
|
||
defmodule EscriptWithDebugInfo do | ||
def project do | ||
[ | ||
app: :escript_test_with_debug_info, | ||
version: "0.0.1", | ||
escript: [main_module: EscriptTest, strip_beams: false] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptWithPath do | ||
def project do | ||
[ | ||
app: :escript_test_with_path, | ||
version: "0.0.1", | ||
escript: [ | ||
app: nil, | ||
embed_elixir: true, | ||
main_module: EscriptTest, | ||
path: Path.join("ebin", "escript_test_with_path") | ||
] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptWithDeps do | ||
def project do | ||
[ | ||
app: :escript_test_with_deps, | ||
version: "0.0.1", | ||
escript: [main_module: EscriptTest], | ||
deps: [{:ok, path: fixture_path("deps_status/deps/ok")}] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptErlangWithDeps do | ||
def project do | ||
[ | ||
app: :escript_test_erlang_with_deps, | ||
app: :escript_test, | ||
version: "0.0.1", | ||
language: :erlang, | ||
escript: [main_module: :escript_test], | ||
|
@@ -65,57 +29,18 @@ defmodule Mix.Tasks.EscriptTest do | |
end | ||
end | ||
|
||
defmodule EscriptErlangMainModule do | ||
def project do | ||
[ | ||
app: :escript_test_erlang_main_module, | ||
version: "0.0.1", | ||
escript: [main_module: :escript_test] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptWithUnknownMainModule do | ||
def project do | ||
[ | ||
app: :escript_test_with_unknown_main_module, | ||
version: "0.0.1", | ||
escript: [main_module: BogusEscriptTest] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptConsolidated do | ||
def project do | ||
[ | ||
app: :escript_test_consolidated, | ||
build_embedded: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this to the default test, since we expect consolidation to happen by default. Also, I don't think |
||
version: "0.0.1", | ||
escript: [main_module: EscriptTest] | ||
] | ||
end | ||
end | ||
|
||
defmodule EscriptWithPrivs do | ||
def project do | ||
[ | ||
app: :escript_test_with_priv, | ||
version: "0.0.1", | ||
escript: [main_module: EscriptTest, include_priv_for: [:escript_test_with_priv, :ok]], | ||
deps: [{:ok, path: fixture_path("deps_status/deps/ok")}] | ||
] | ||
end | ||
end | ||
|
||
test "generate escript" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
assert_received {:mix_shell, :info, ["Generated escript escript_test with MIX_ENV=dev"]} | ||
assert System.cmd("escript", ["escript_test"]) == {"TEST\n", 0} | ||
assert count_abstract_code("escript_test") == 0 | ||
|
||
# Consolidates protocols | ||
assert System.cmd("escript", ["escript_test", "--protocol", "Enumerable"]) == {"true\n", 0} | ||
|
||
# Each app has a distinct, valid path | ||
assert System.cmd("escript", ["escript_test", "--app-paths"]) == {"{true, true, true}\n", 0} | ||
|
||
|
@@ -127,7 +52,7 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with --no-compile option" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
Mix.Tasks.Compile.run([]) | ||
purge([EscriptTest]) | ||
|
@@ -139,7 +64,7 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with compile config" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
File.mkdir_p!("config") | ||
|
||
|
@@ -156,7 +81,7 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with runtime config" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
File.mkdir_p!("config") | ||
|
||
|
@@ -183,15 +108,15 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with debug information" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithDebugInfo) | ||
push_project_with_config(Escript, escript: [main_module: EscriptTest, strip_beams: false]) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
msg = "Generated escript escript_test_with_debug_info with MIX_ENV=dev" | ||
msg = "Generated escript escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^msg]} | ||
|
||
assert System.cmd("escript", ["escript_test_with_debug_info"]) == {"TEST\n", 0} | ||
assert count_abstract_code("escript_test_with_debug_info") > 0 | ||
assert System.cmd("escript", ["escript_test"]) == {"TEST\n", 0} | ||
assert count_abstract_code("escript_test") > 0 | ||
end) | ||
end | ||
|
||
|
@@ -226,46 +151,55 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with path" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithPath) | ||
push_project_with_config(Escript, | ||
escript: [ | ||
app: nil, | ||
embed_elixir: true, | ||
main_module: EscriptTest, | ||
path: Path.join("ebin", "escript_test") | ||
] | ||
) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript ebin/escript_test_with_path with MIX_ENV=dev" | ||
message = "Generated escript ebin/escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["ebin/escript_test_with_path"]) == {"TEST\n", 0} | ||
assert System.cmd("escript", ["ebin/escript_test"]) == {"TEST\n", 0} | ||
end) | ||
end | ||
|
||
test "generate escript with deps" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithDeps) | ||
push_project_with_config(Escript, | ||
escript: [main_module: EscriptTest], | ||
deps: [{:ok, path: fixture_path("deps_status/deps/ok")}] | ||
) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_with_deps with MIX_ENV=dev" | ||
message = "Generated escript escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["escript_test_with_deps"]) == {"TEST\n", 0} | ||
assert System.cmd("escript", ["escript_test"]) == {"TEST\n", 0} | ||
|
||
# Does not include priv for deps by default | ||
assert System.cmd("escript", ["escript_test_with_deps", "--list-priv", "ok"]) == | ||
{":error\n", 0} | ||
assert System.cmd("escript", ["escript_test", "--list-priv", "ok"]) == {":error\n", 0} | ||
end) | ||
after | ||
purge([Ok.MixProject]) | ||
end | ||
|
||
test "generate escript with Erlang and deps" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptErlangWithDeps) | ||
push_project_with_config(EscriptErlangWithDeps) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_erlang_with_deps with MIX_ENV=dev" | ||
message = "Generated escript escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["escript_test_erlang_with_deps", "arg1", "arg2"]) == | ||
assert System.cmd("escript", ["escript_test", "arg1", "arg2"]) == | ||
{~s(["arg1","arg2"]), 0} | ||
end) | ||
after | ||
|
@@ -274,50 +208,36 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "generate escript with Erlang main module" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptErlangMainModule) | ||
push_project_with_config(Escript, escript: [main_module: :escript_test]) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_erlang_main_module with MIX_ENV=dev" | ||
message = "Generated escript escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["escript_test_erlang_main_module", "arg1", "arg2"]) == | ||
assert System.cmd("escript", ["escript_test", "arg1", "arg2"]) == | ||
{~s([<<"arg1">>,<<"arg2">>]), 0} | ||
end) | ||
after | ||
purge([Ok.MixProject]) | ||
end | ||
|
||
test "generate escript with consolidated protocols" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptConsolidated) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_consolidated with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", ["escript_test_consolidated", "--protocol", "Enumerable"]) == | ||
{"true\n", 0} | ||
end) | ||
end | ||
|
||
test "generate escript with priv" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithPrivs) | ||
push_project_with_config(Escript, | ||
escript: [main_module: EscriptTest, include_priv_for: [:escript_test, :ok]], | ||
deps: [{:ok, path: fixture_path("deps_status/deps/ok")}] | ||
) | ||
|
||
Mix.Tasks.Escript.Build.run([]) | ||
|
||
message = "Generated escript escript_test_with_priv with MIX_ENV=dev" | ||
message = "Generated escript escript_test with MIX_ENV=dev" | ||
assert_received {:mix_shell, :info, [^message]} | ||
|
||
assert System.cmd("escript", [ | ||
"escript_test_with_priv", | ||
"--list-priv", | ||
"escript_test_with_priv" | ||
]) == {~s/{:ok, [~c"hello"]}\n/, 0} | ||
assert System.cmd("escript", ["escript_test", "--list-priv", "escript_test"]) == | ||
{~s/{:ok, [~c"hello"]}\n/, 0} | ||
|
||
assert System.cmd("escript", ["escript_test_with_priv", "--list-priv", "ok"]) == | ||
assert System.cmd("escript", ["escript_test", "--list-priv", "ok"]) == | ||
{~s/{:ok, [~c"sample"]}\n/, 0} | ||
end) | ||
end | ||
|
@@ -326,7 +246,7 @@ defmodule Mix.Tasks.EscriptTest do | |
File.rm_rf!(tmp_path(".mix/escripts")) | ||
|
||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
# check that no escripts are installed | ||
Mix.Tasks.Escript.run([]) | ||
|
@@ -362,7 +282,7 @@ defmodule Mix.Tasks.EscriptTest do | |
File.rm_rf!(tmp_path(".mix/escripts")) | ||
|
||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(Escript) | ||
push_project_with_config(Escript) | ||
|
||
Mix.Tasks.Escript.Install.run(["--force"]) | ||
|
||
|
@@ -392,7 +312,7 @@ defmodule Mix.Tasks.EscriptTest do | |
|
||
test "escript invalid main module" do | ||
in_fixture("escript_test", fn -> | ||
Mix.Project.push(EscriptWithUnknownMainModule) | ||
push_project_with_config(Escript, escript: [main_module: BogusEscriptTest]) | ||
|
||
message = | ||
"Could not generate escript, module Elixir.BogusEscriptTest defined as :main_module could not be loaded" | ||
|
@@ -446,4 +366,9 @@ defmodule Mix.Tasks.EscriptTest do | |
after | ||
purge([GitRepo, GitRepo.MixProject]) | ||
end | ||
|
||
defp push_project_with_config(module, config \\ []) do | ||
Mix.ProjectStack.post_config(config) | ||
Mix.Project.push(module) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this one, since it also defines
application
.