Skip to content

Commit

Permalink
Fix umbrella app order for Elixir 1.16 + refine test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsluszniak committed Mar 1, 2024
1 parent de95cdc commit a9ab030
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 241 deletions.
4 changes: 3 additions & 1 deletion lib/ex_check/check/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ defmodule ExCheck.Check.Compiler do
else: actual_apps_paths

tool_instances =
Enum.map(apps_paths, fn {app_name, app_dir} ->
apps_paths
|> Enum.sort_by(&elem(&1, 0))
|> Enum.map(fn {app_name, app_dir} ->
final_tool_opts = Keyword.update(tool_opts, :cd, app_dir, &Path.join(app_dir, &1))
{{tool_name, app_name}, final_tool_opts}
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_check/manifest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule ExCheck.Manifest do
defp serialize_tool_name({tool, app}), do: "#{app}/#{tool}"
defp serialize_tool_name(tool), do: tool

@escape Enum.map(' [~#%&*{}\\:<>?/+|"]', &<<&1::utf8>>)
@escape Enum.map(~c" [~#%&*{}\\:<>?/+|\"]", &<<&1::utf8>>)

defp get_path(opts) do
Keyword.get_lazy(opts, :manifest, fn ->
Expand Down
2 changes: 1 addition & 1 deletion test/ex_check/project_cases/application_mod_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule ExCheck.ProjectCases.ApplicationModTest do
application_test_path = Path.join([project_dir, "test", "application_test.exs"])
File.write!(application_test_path, @application_test)

assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
2 changes: 1 addition & 1 deletion test/ex_check/project_cases/base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ExCheck.ProjectCases.BaseTest do
use ExCheck.ProjectCase, async: true

test "base", %{project_dir: project_dir} do
assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
5 changes: 3 additions & 2 deletions test/ex_check/project_cases/compiler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ defmodule ExCheck.ProjectCases.CompilerTest do
end
""")

assert {output, 1} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(1)

assert output =~ "compiler error code 1"
assert output =~ "variable \"a\" is unused"

assert {output, 0} = System.cmd("mix", ~w[check --except compiler --no-retry], cd: project_dir)
output =
System.cmd("mix", ~w[check --except compiler --no-retry], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
15 changes: 8 additions & 7 deletions test/ex_check/project_cases/config_and_scripts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ defmodule ExCheck.ProjectCases.ConfigAndScriptsTest do

supports_erl_config = Version.match?(System.version(), ">= 1.9.0")

assert {output, 0} =
System.cmd(
"elixir",
["-e", "Application.put_env(:elixir, :ansi_enabled, true)", "-S", "mix", "check"],
cd: project_dir,
stderr_to_stdout: true
)
output =
System.cmd(
"elixir",
["-e", "Application.put_env(:elixir, :ansi_enabled, true)", "-S", "mix", "check"],
cd: project_dir,
stderr_to_stdout: true
)
|> cmd_exit(0)

plain_output = String.replace(output, @ansi_code_regex, "")

Expand Down
4 changes: 2 additions & 2 deletions test/ex_check/project_cases/deps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule ExCheck.ProjectCases.DepsTest do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @config)

assert {output, 1} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(1)

assert output =~ "a success"
assert output =~ "b success"
Expand All @@ -63,7 +63,7 @@ defmodule ExCheck.ProjectCases.DepsTest do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @config)

assert {output, 1} = System.cmd("mix", ~w[check --no-parallel], cd: project_dir)
output = System.cmd("mix", ~w[check --no-parallel], cd: project_dir) |> cmd_exit(1)

assert output =~ "a success"
assert output =~ "b success"
Expand Down
2 changes: 1 addition & 1 deletion test/ex_check/project_cases/detect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule ExCheck.ProjectCases.DetectTest do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @config)

assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(0)

assert output =~ "credo skipped due to missing package credo"
assert output =~ "bad_dir skipped due to missing directory bad_directory"
Expand Down
3 changes: 2 additions & 1 deletion test/ex_check/project_cases/external_tools_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ defmodule ExCheck.ProjectCases.ExternalToolsTest do

set_mix_deps(project_dir, tools)

assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir, env: %{"MIX_ENV" => "dev"})
output =
System.cmd("mix", ~w[check], cd: project_dir, env: %{"MIX_ENV" => "dev"}) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
2 changes: 1 addition & 1 deletion test/ex_check/project_cases/formatter_issue_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ExCheck.ProjectCases.FormatterIssueTest do

File.write!(invalid_file_path, "IO.inspect( 1 )")

assert {output, 1} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(1)

assert output =~ "compiler success"
assert output =~ "formatter error code 1"
Expand Down
6 changes: 3 additions & 3 deletions test/ex_check/project_cases/gen_config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ defmodule ExCheck.ProjectCases.GenConfigTest do
test "gen config", %{project_dir: project_dir} do
File.rm!(Path.join(project_dir, ".check.exs"))

assert {output, 0} = System.cmd("mix", ~w[check.gen.config], cd: project_dir)
output = System.cmd("mix", ~w[check.gen.config], cd: project_dir) |> cmd_exit(0)

assert output =~ "creating .check.exs"

assert {output, 0} = System.cmd("mix", ~w[check.gen.config], cd: project_dir)
output = System.cmd("mix", ~w[check.gen.config], cd: project_dir) |> cmd_exit(0)

assert output =~ ".check.exs already exists, skipped"

assert {output, 0} = System.cmd("mix", ~w[check --no-fix], cd: project_dir)
output = System.cmd("mix", ~w[check --no-fix], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
30 changes: 16 additions & 14 deletions test/ex_check/project_cases/manifest_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ExCheck.ProjectCases.ManifestTest do

File.write!(invalid_file_path, "IO.inspect( 1 )")

assert {output, 1} = System.cmd("mix", ~w[check --manifest manifest.txt], cd: project_dir)
output = System.cmd("mix", ~w[check --manifest manifest.txt], cd: project_dir) |> cmd_exit(1)

assert output =~ "compiler success"
assert output =~ "formatter error code 1"
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule ExCheck.ProjectCases.ManifestTest do

assert manifest |> String.split("\n") |> Enum.sort() == expected_manifest

assert {output, 1} = System.cmd("mix", ~w[check --manifest manifest.txt], cd: project_dir)
output = System.cmd("mix", ~w[check --manifest manifest.txt], cd: project_dir) |> cmd_exit(1)

assert output =~ "retrying automatically"
assert output =~ "compiler success"
Expand All @@ -59,8 +59,8 @@ defmodule ExCheck.ProjectCases.ManifestTest do
refute output =~ "ex_doc skipped due to missing package ex_doc"
refute output =~ "mix_audit skipped due to missing package mix_audit"

assert {output, 1} =
System.cmd("mix", ~w[check --manifest manifest.txt --retry], cd: project_dir)
output =
System.cmd("mix", ~w[check --manifest manifest.txt --retry], cd: project_dir) |> cmd_exit(1)

refute output =~ "retrying automatically"
assert output =~ "compiler success"
Expand All @@ -72,8 +72,9 @@ defmodule ExCheck.ProjectCases.ManifestTest do
refute output =~ "ex_doc skipped due to missing package ex_doc"
refute output =~ "mix_audit skipped due to missing package mix_audit"

assert {output, 1} =
System.cmd("mix", ~w[check --manifest manifest.txt --no-retry], cd: project_dir)
output =
System.cmd("mix", ~w[check --manifest manifest.txt --no-retry], cd: project_dir)
|> cmd_exit(1)

refute output =~ "retrying automatically"
assert output =~ "compiler success"
Expand All @@ -85,8 +86,9 @@ defmodule ExCheck.ProjectCases.ManifestTest do
assert output =~ "ex_doc skipped due to missing package ex_doc"
assert output =~ "mix_audit skipped due to missing package mix_audit"

assert {output, 0} =
System.cmd("mix", ~w[check --manifest manifest.txt --retry --fix], cd: project_dir)
output =
System.cmd("mix", ~w[check --manifest manifest.txt --retry --fix], cd: project_dir)
|> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter fix success"
Expand All @@ -97,8 +99,8 @@ defmodule ExCheck.ProjectCases.ManifestTest do
refute output =~ "ex_doc skipped due to missing package ex_doc"
refute output =~ "mix_audit skipped due to missing package mix_audit"

assert {output, 0} =
System.cmd("mix", ~w[check --manifest manifest.txt --retry], cd: project_dir)
output =
System.cmd("mix", ~w[check --manifest manifest.txt --retry], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
refute output =~ "formatter success"
Expand All @@ -124,14 +126,14 @@ defmodule ExCheck.ProjectCases.ManifestTest do
end
""")

assert {output, 1} =
System.cmd("mix", ~w[check --only ex_unit --only formatter], cd: project_dir)
output =
System.cmd("mix", ~w[check --only ex_unit --only formatter], cd: project_dir) |> cmd_exit(1)

assert output =~ "formatter success"
assert output =~ "ex_unit error code"
assert output =~ "2 tests, 1 failure"

assert {output, 1} = System.cmd("mix", ~w[check --retry], cd: project_dir)
output = System.cmd("mix", ~w[check --retry], cd: project_dir) |> cmd_exit(1)

refute output =~ "formatter"
assert output =~ "ex_unit error code"
Expand All @@ -142,7 +144,7 @@ defmodule ExCheck.ProjectCases.ManifestTest do
File.read!(failing_test_path) |> String.replace(":universe", ":world")
)

assert {output, 0} = System.cmd("mix", ~w[check --retry], cd: project_dir)
output = System.cmd("mix", ~w[check --retry], cd: project_dir) |> cmd_exit(0)

refute output =~ "formatter"
assert output =~ "ex_unit retry success"
Expand Down
2 changes: 1 addition & 1 deletion test/ex_check/project_cases/missing_test_helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule ExCheck.ProjectCases.MissingTestHelperTest do
test_dir_path = Path.join(project_dir, "test")
File.rm_rf!(test_dir_path)

assert {output, 0} = System.cmd("mix", ~w[check], cd: project_dir)
output = System.cmd("mix", ~w[check], cd: project_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
4 changes: 2 additions & 2 deletions test/ex_check/umbrella_project_cases/asset_testing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ defmodule ExCheck.UmbrellaProjectCases.AssetTestingTest do
File.mkdir_p!(Path.dirname(package_json_path))
File.write!(package_json_path, @package_json)

assert {_, 0} = System.cmd("mix", ~w[compile], cd: project_root_dir)
assert {output, 1} = System.cmd("mix", ~w[check], cd: project_root_dir)
System.cmd("mix", ~w[compile], cd: project_root_dir) |> cmd_exit(0)
output = System.cmd("mix", ~w[check], cd: project_root_dir) |> cmd_exit(1)

assert output =~ "npm_test in child_a error code 1"
refute output =~ "npm_test in child_b"
Expand Down
4 changes: 2 additions & 2 deletions test/ex_check/umbrella_project_cases/base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ defmodule ExCheck.UmbrellaProjectCases.BaseTest do
use ExCheck.UmbrellaProjectCase, async: true

test "base", %{project_dirs: [project_root_dir | _]} do
assert {_, 0} = System.cmd("mix", ~w[compile], cd: project_root_dir)
assert {output, 0} = System.cmd("mix", ~w[check], cd: project_root_dir)
System.cmd("mix", ~w[compile], cd: project_root_dir) |> cmd_exit(0)
output = System.cmd("mix", ~w[check], cd: project_root_dir) |> cmd_exit(0)

assert output =~ "compiler success"
assert output =~ "formatter success"
Expand Down
4 changes: 2 additions & 2 deletions test/ex_check/umbrella_project_cases/non_recursive_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ defmodule ExCheck.UmbrellaProjectCases.NonRecursiveTest do
config_path = Path.join(project_root_dir, ".check.exs")
File.write!(config_path, @config)

assert {_, 0} = System.cmd("mix", ~w[compile], cd: project_root_dir)
assert {output, 0} = System.cmd("mix", ~w[check], cd: project_root_dir)
System.cmd("mix", ~w[compile], cd: project_root_dir) |> cmd_exit(0)
output = System.cmd("mix", ~w[check], cd: project_root_dir) |> cmd_exit(0)

assert output =~ "ex_unit success"
refute output =~ "ex_unit in child_a success"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ defmodule ExCheck.UmbrellaProjectCases.OnlySpecificAppsTest do
config_path = Path.join(project_root_dir, ".check.exs")
File.write!(config_path, @config)

assert {_, 0} = System.cmd("mix", ~w[compile], cd: project_root_dir)
assert {output, 0} = System.cmd("mix", ~w[check], cd: project_root_dir)
System.cmd("mix", ~w[compile], cd: project_root_dir) |> cmd_exit(0)
output = System.cmd("mix", ~w[check], cd: project_root_dir) |> cmd_exit(0)

refute output =~ "ex_unit success"
assert output =~ "ex_unit in child_a success"
refute output =~ "ex_unit in child_b success"

assert {output, 0} = System.cmd("mix", ~w[check], cd: child_a_dir)
output = System.cmd("mix", ~w[check], cd: child_a_dir) |> cmd_exit(0)

assert output =~ "ex_unit success"

assert {output, 0} = System.cmd("mix", ~w[check], cd: child_b_dir)
output = System.cmd("mix", ~w[check], cd: child_b_dir) |> cmd_exit(0)

refute output =~ "ex_unit"
end
Expand Down
49 changes: 28 additions & 21 deletions test/ex_check/umbrella_project_cases/sequential_test.exs
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
defmodule ExCheck.UmbrellaProjectCases.SequentialTest do
use ExCheck.UmbrellaProjectCase, async: true

@a_script """
Process.sleep(1_000)
File.write!(Path.join("..", "a_out"), "a_out")
"""

@b_script """
IO.puts(File.read!(Path.join("..", "a_out")))
"""

@config """
[
tools: [
{:seq, "elixir script.exs", umbrella: [parallel: false]},
test "sequential", %{project_dirs: [project_root_dir, child_a_dir, child_b_dir]} do
script_path = Path.join(project_root_dir, "a_out")

a_script = """
IO.inspect({:a1, DateTime.utc_now()})
Process.sleep(1_000)
File.write!("#{script_path}", "a_out")
IO.inspect({:a2, DateTime.utc_now()})
"""

b_script = """
IO.inspect({:b1, DateTime.utc_now()})
Process.sleep(1_000)
IO.puts(File.read!("#{script_path}"))
IO.inspect({:b2, DateTime.utc_now()})
"""

config = """
[
tools: [
{:seq, "elixir script.exs", umbrella: [parallel: false]},
]
]
]
"""
"""

test "sequential", %{project_dirs: [project_root_dir, child_a_dir, child_b_dir]} do
config_path = Path.join(project_root_dir, ".check.exs")
File.write!(config_path, @config)
File.write!(config_path, config)

child_a_script_path = Path.join(child_a_dir, "script.exs")
File.write!(child_a_script_path, @a_script)
File.write!(child_a_script_path, a_script)

child_b_script_path = Path.join(child_b_dir, "script.exs")
File.write!(child_b_script_path, @b_script)
File.write!(child_b_script_path, b_script)

assert {_, 0} = System.cmd("mix", ~w[compile], cd: project_root_dir)
assert {output, 0} = System.cmd("mix", ~w[check], cd: project_root_dir)
System.cmd("mix", ~w[compile], cd: project_root_dir) |> cmd_exit(0)
output = System.cmd("mix", ~w[check], cd: project_root_dir) |> cmd_exit(0)

assert output =~ "seq in child_a success"
assert output =~ "seq in child_b success"
Expand Down
Loading

0 comments on commit a9ab030

Please sign in to comment.