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 7bbe099
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 294 deletions.
3 changes: 2 additions & 1 deletion .check.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ex_doc_config =
{:ex_doc, ex_doc_config},
{:formatter, env: %{"MIX_ENV" => "test"}},
{:mix_audit, env: %{"MIX_ENV" => "test"}},
{:sobelow, "mix sobelow --exit --skip"}
{:sobelow, "mix sobelow --exit --skip"},
{:gettext, false}
]
]
6 changes: 4 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ jobs:
include:
- elixir: '1.16.1'
otp: '26.2.2'
- elixir: '1.14.2'
otp: '25.1.2'
- elixir: '1.14.5'
otp: '24.3.4.16'
- elixir: '1.12.3'
otp: '22.3.4.26'

runs-on: ubuntu-20.04

Expand Down
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 mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ExCheck.MixProject do
[
app: :ex_check,
version: @version,
elixir: "~> 1.14",
elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
deps: deps(),
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
10 changes: 2 additions & 8 deletions 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 All @@ -12,13 +12,7 @@ defmodule ExCheck.ProjectCases.BaseTest do
assert output =~ "dialyzer skipped due to missing package dialyxir"
assert output =~ "ex_doc skipped due to missing package ex_doc"
refute output =~ "npm_test"

if Version.match?(System.version(), ">= 1.10.0") do
assert output =~ "unused_deps success"
else
assert output =~ "unused_deps skipped due to Elixir version ="
end

assert output =~ "unused_deps success"
assert output =~ "Randomized with seed"
end
end
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
32 changes: 10 additions & 22 deletions test/ex_check/project_cases/config_and_scripts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,29 @@ defmodule ExCheck.ProjectCases.ConfigAndScriptsTest do
File.write!(shell_script_path, @shell_script)
File.chmod!(shell_script_path, 0o755)

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, "")

assert plain_output =~ "compiler success"
refute plain_output =~ "formatter success"
assert plain_output =~ "ex_unit success"

if Version.match?(System.version(), ">= 1.10.0") do
assert plain_output =~ "unused_deps fix success"
end

assert plain_output =~ "unused_deps fix success"
refute plain_output =~ "credo skipped due to missing package credo"
refute plain_output =~ "gettext skipped due to missing package credo"
assert plain_output =~ "my_mix_task success"
assert plain_output =~ "my_elixir_script success"
assert plain_output =~ "my_shell_script success"

assert output =~ "sometag"
assert output =~ IO.ANSI.yellow() <> IO.ANSI.faint() <> "my mix task a prod"

if supports_erl_config do
assert output =~ IO.ANSI.blue() <> IO.ANSI.faint() <> "my elixir script a"
else
assert output =~ "my elixir script a"
end

assert output =~ IO.ANSI.blue() <> IO.ANSI.faint() <> "my elixir script a"
assert output =~ "my shell script a b xyz"
assert plain_output =~ ~r/running my_shell_script.*running my_mix_task.*running ex_unit/s
end
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
28 changes: 7 additions & 21 deletions test/ex_check/project_cases/external_tools_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,21 @@ defmodule ExCheck.ProjectCases.ExternalToolsTest do
use ExCheck.ProjectCase, async: true

test "external tools (except dialyzer)", %{project_dir: project_dir} do
tools =
if Version.match?(System.version(), "< 1.10.0") do
[:ex_check, :credo, :doctor, :sobelow, :mix_audit]
else
[:ex_check, :credo, :doctor, :ex_doc, :gettext, :sobelow, :mix_audit]
end

tools = [:ex_check, :credo, :doctor, :ex_doc, :gettext, :sobelow, :mix_audit]
set_mix_deps(project_dir, tools)

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

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

assert output =~ "compiler success"
assert output =~ "formatter success"
assert output =~ "ex_unit success"
assert output =~ "credo success"
assert output =~ "gettext success"

if Version.match?(System.version(), ">= 1.8.0") do
assert output =~ "doctor success"
else
assert output =~ "doctor skipped"
end

if Version.match?(System.version(), ">= 1.10.0") do
assert output =~ "ex_doc success"
else
assert output =~ "ex_doc skipped due to missing package ex_doc"
end

assert output =~ "doctor success"
assert output =~ "ex_doc success"
assert output =~ "sobelow success"
assert output =~ "dialyzer skipped due to missing package dialyxir"
assert output =~ "mix_audit 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
37 changes: 16 additions & 21 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 @@ -38,16 +38,9 @@ defmodule ExCheck.ProjectCases.ManifestTest do
|> String.split("\n")
|> Enum.sort()

expected_manifest =
if Version.match?(System.version(), ">= 1.10.0") do
expected_manifest
else
(expected_manifest -- ["PASS unused_deps"]) ++ ["SKIP unused_deps"]
end

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 +52,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 +65,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 +79,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 +92,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 +119,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 +137,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
Loading

0 comments on commit 7bbe099

Please sign in to comment.