diff --git a/.check.exs b/.check.exs index 9c2738e..19b50a2 100644 --- a/.check.exs +++ b/.check.exs @@ -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} ] ] diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index fe49352..3554a50 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 diff --git a/lib/ex_check/check/compiler.ex b/lib/ex_check/check/compiler.ex index e806228..14ebedb 100644 --- a/lib/ex_check/check/compiler.ex +++ b/lib/ex_check/check/compiler.ex @@ -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) diff --git a/lib/ex_check/manifest.ex b/lib/ex_check/manifest.ex index 9b2728a..c68917b 100644 --- a/lib/ex_check/manifest.ex +++ b/lib/ex_check/manifest.ex @@ -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 -> diff --git a/mix.exs b/mix.exs index a0f44f3..5bf8f67 100644 --- a/mix.exs +++ b/mix.exs @@ -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(), diff --git a/test/ex_check/project_cases/application_mod_test.exs b/test/ex_check/project_cases/application_mod_test.exs index ff12334..88edaa5 100644 --- a/test/ex_check/project_cases/application_mod_test.exs +++ b/test/ex_check/project_cases/application_mod_test.exs @@ -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" diff --git a/test/ex_check/project_cases/base_test.exs b/test/ex_check/project_cases/base_test.exs index d6d176e..6b02611 100644 --- a/test/ex_check/project_cases/base_test.exs +++ b/test/ex_check/project_cases/base_test.exs @@ -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" @@ -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 diff --git a/test/ex_check/project_cases/compiler_test.exs b/test/ex_check/project_cases/compiler_test.exs index fc5f18b..ee95efd 100644 --- a/test/ex_check/project_cases/compiler_test.exs +++ b/test/ex_check/project_cases/compiler_test.exs @@ -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" diff --git a/test/ex_check/project_cases/config_and_scripts_test.exs b/test/ex_check/project_cases/config_and_scripts_test.exs index 786bde7..8afdf76 100644 --- a/test/ex_check/project_cases/config_and_scripts_test.exs +++ b/test/ex_check/project_cases/config_and_scripts_test.exs @@ -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 diff --git a/test/ex_check/project_cases/deps_test.exs b/test/ex_check/project_cases/deps_test.exs index 991cbae..95d455f 100644 --- a/test/ex_check/project_cases/deps_test.exs +++ b/test/ex_check/project_cases/deps_test.exs @@ -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" @@ -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" diff --git a/test/ex_check/project_cases/detect_test.exs b/test/ex_check/project_cases/detect_test.exs index b588321..5f3e668 100644 --- a/test/ex_check/project_cases/detect_test.exs +++ b/test/ex_check/project_cases/detect_test.exs @@ -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" diff --git a/test/ex_check/project_cases/external_tools_test.exs b/test/ex_check/project_cases/external_tools_test.exs index f934b8c..e3e54bb 100644 --- a/test/ex_check/project_cases/external_tools_test.exs +++ b/test/ex_check/project_cases/external_tools_test.exs @@ -2,35 +2,19 @@ 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"}) + 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" diff --git a/test/ex_check/project_cases/formatter_issue_test.exs b/test/ex_check/project_cases/formatter_issue_test.exs index 4743b9e..d741fbf 100644 --- a/test/ex_check/project_cases/formatter_issue_test.exs +++ b/test/ex_check/project_cases/formatter_issue_test.exs @@ -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" diff --git a/test/ex_check/project_cases/gen_config_test.exs b/test/ex_check/project_cases/gen_config_test.exs index 3d0d1b0..2e4f63d 100644 --- a/test/ex_check/project_cases/gen_config_test.exs +++ b/test/ex_check/project_cases/gen_config_test.exs @@ -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" diff --git a/test/ex_check/project_cases/manifest_test.exs b/test/ex_check/project_cases/manifest_test.exs index 473ad18..47e9754 100644 --- a/test/ex_check/project_cases/manifest_test.exs +++ b/test/ex_check/project_cases/manifest_test.exs @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/test/ex_check/project_cases/missing_test_helper_test.exs b/test/ex_check/project_cases/missing_test_helper_test.exs index 9d10b26..dbcd8f5 100644 --- a/test/ex_check/project_cases/missing_test_helper_test.exs +++ b/test/ex_check/project_cases/missing_test_helper_test.exs @@ -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" diff --git a/test/ex_check/umbrella_project_cases/asset_testing_test.exs b/test/ex_check/umbrella_project_cases/asset_testing_test.exs index 160ae20..5caa7fe 100644 --- a/test/ex_check/umbrella_project_cases/asset_testing_test.exs +++ b/test/ex_check/umbrella_project_cases/asset_testing_test.exs @@ -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" diff --git a/test/ex_check/umbrella_project_cases/base_test.exs b/test/ex_check/umbrella_project_cases/base_test.exs index b318e1b..d5396d9 100644 --- a/test/ex_check/umbrella_project_cases/base_test.exs +++ b/test/ex_check/umbrella_project_cases/base_test.exs @@ -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" diff --git a/test/ex_check/umbrella_project_cases/non_recursive_test.exs b/test/ex_check/umbrella_project_cases/non_recursive_test.exs index 0150b87..c0c0ed0 100644 --- a/test/ex_check/umbrella_project_cases/non_recursive_test.exs +++ b/test/ex_check/umbrella_project_cases/non_recursive_test.exs @@ -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" diff --git a/test/ex_check/umbrella_project_cases/only_specific_apps_test.exs b/test/ex_check/umbrella_project_cases/only_specific_apps_test.exs index bc8867c..04d6048 100644 --- a/test/ex_check/umbrella_project_cases/only_specific_apps_test.exs +++ b/test/ex_check/umbrella_project_cases/only_specific_apps_test.exs @@ -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 diff --git a/test/ex_check/umbrella_project_cases/sequential_test.exs b/test/ex_check/umbrella_project_cases/sequential_test.exs index 797620e..4867d39 100644 --- a/test/ex_check/umbrella_project_cases/sequential_test.exs +++ b/test/ex_check/umbrella_project_cases/sequential_test.exs @@ -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" diff --git a/test/support/ex_check/case_helpers.ex b/test/support/ex_check/case_helpers.ex new file mode 100644 index 0000000..652d90f --- /dev/null +++ b/test/support/ex_check/case_helpers.ex @@ -0,0 +1,101 @@ +defmodule ExCheck.CaseHelpers do + @moduledoc false + + use ExUnit.CaseTemplate + + @default_config """ + [ + fix: false + ] + """ + + def cmd_exit({output, code}, expected_code) do + assert code == expected_code, + "unexpected exit code #{code} (expected #{expected_code}):\n\n#{output}" + + output + end + + def create_tmp_directory do + timestamp = DateTime.utc_now() |> DateTime.to_unix(:microsecond) + unique_id = :crypto.strong_rand_bytes(12) |> Base.url_encode64() + + tmp_dir = + System.tmp_dir!() + |> Path.join("ex_check_test") + |> Path.join("#{timestamp}-#{unique_id}") + + File.mkdir_p!(tmp_dir) + + tmp_dir + end + + def remove_tmp_directory(tmp_dir) do + File.rm_rf!(tmp_dir) + end + + def set_mix_deps(project_dirs, deps) when is_list(project_dirs) do + Enum.map(project_dirs, &set_mix_deps(&1, deps)) + end + + def set_mix_deps(project_dir, deps) do + config_path = "#{project_dir}/mix.exs" + deps_from = ~r/ *defp deps.*end\n/Us + + deps_list = + Enum.map(deps, fn + :ex_check -> + "{:ex_check, path: \"#{File.cwd!()}\", only: [:dev, :test], runtime: false}" + + dep -> + "{:#{dep}, \">= 0.0.0\", only: :dev, runtime: false}" + end) + + deps_to = """ + defp deps do + [ + #{Enum.join(deps_list, ",\n ")} + ] + end + """ + + new_config = + config_path + |> File.read!() + |> String.replace(deps_from, deps_to) + + unless String.contains?(new_config, "ex_check"), do: raise("unable to add ex_check dep") + + File.write!(config_path, new_config) + {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) + {_, 0} = System.cmd("mix", ~w[deps.get], cd: project_dir) + end + + def set_mix_app_mod(project_dir, mod) do + config_path = "#{project_dir}/mix.exs" + app_from = ~r/ *def application.*end\n/Us + + app_to = """ + def application do + [ + mod: {#{mod}, []} + ] + end + """ + + new_config = + config_path + |> File.read!() + |> String.replace(app_from, app_to) + + unless String.contains?(new_config, mod), do: raise("unable to set #{mod} app mod") + + File.write!(config_path, new_config) + {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) + end + + def write_default_config(project_dir) do + config_path = Path.join(project_dir, ".check.exs") + File.write!(config_path, @default_config) + end +end diff --git a/test/support/ex_check/project_case.ex b/test/support/ex_check/project_case.ex index b46e081..2c189a3 100644 --- a/test/support/ex_check/project_case.ex +++ b/test/support/ex_check/project_case.ex @@ -3,14 +3,9 @@ defmodule ExCheck.ProjectCase do use ExUnit.CaseTemplate - @default_config """ - [ - fix: false - ] - """ - using do quote do + import ExCheck.CaseHelpers import ExCheck.ProjectCase @moduletag timeout: 5 * 60 * 1_000 @@ -28,88 +23,9 @@ defmodule ExCheck.ProjectCase do end end - def create_tmp_directory do - timestamp = DateTime.utc_now() |> DateTime.to_unix(:microsecond) - unique_id = :crypto.strong_rand_bytes(12) |> Base.url_encode64() - - tmp_dir = - System.tmp_dir!() - |> Path.join("ex_check_test") - |> Path.join("#{timestamp}-#{unique_id}") - - File.mkdir_p!(tmp_dir) - - tmp_dir - end - - def remove_tmp_directory(tmp_dir) do - File.rm_rf!(tmp_dir) - end - def create_mix_project(root_dir) do System.cmd("mix", ~w(new test_project), cd: root_dir) Path.join(root_dir, "test_project") end - - def set_mix_deps(project_dir, deps) do - config_path = "#{project_dir}/mix.exs" - deps_from = ~r/ *defp deps.*end\n/Us - - deps_list = - Enum.map(deps, fn - :ex_check -> - "{:ex_check, path: \"#{File.cwd!()}\", only: [:dev, :test], runtime: false}" - - dep -> - "{:#{dep}, \">= 0.0.0\", only: :dev, runtime: false}" - end) - - deps_to = """ - defp deps do - [ - #{Enum.join(deps_list, ",\n ")} - ] - end - """ - - new_config = - config_path - |> File.read!() - |> String.replace(deps_from, deps_to) - - unless String.contains?(new_config, "ex_check"), do: raise("unable to add ex_check dep") - - File.write!(config_path, new_config) - {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) - {_, 0} = System.cmd("mix", ~w[deps.get], cd: project_dir) - end - - def set_mix_app_mod(project_dir, mod) do - config_path = "#{project_dir}/mix.exs" - app_from = ~r/ *def application.*end\n/Us - - app_to = """ - def application do - [ - mod: {#{mod}, []} - ] - end - """ - - new_config = - config_path - |> File.read!() - |> String.replace(app_from, app_to) - - unless String.contains?(new_config, mod), do: raise("unable to set #{mod} app mod") - - File.write!(config_path, new_config) - {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) - end - - def write_default_config(project_dir) do - config_path = Path.join(project_dir, ".check.exs") - File.write!(config_path, @default_config) - end end diff --git a/test/support/ex_check/umbrella_project_case.ex b/test/support/ex_check/umbrella_project_case.ex index 18afd03..f662ceb 100644 --- a/test/support/ex_check/umbrella_project_case.ex +++ b/test/support/ex_check/umbrella_project_case.ex @@ -3,14 +3,9 @@ defmodule ExCheck.UmbrellaProjectCase do use ExUnit.CaseTemplate - @default_config """ - [ - fix: false - ] - """ - using do quote do + import ExCheck.CaseHelpers import ExCheck.UmbrellaProjectCase @moduletag timeout: 5 * 60 * 1_000 @@ -32,24 +27,6 @@ defmodule ExCheck.UmbrellaProjectCase do end end - def create_tmp_directory do - timestamp = DateTime.utc_now() |> DateTime.to_unix(:microsecond) - unique_id = :crypto.strong_rand_bytes(12) |> Base.url_encode64() - - tmp_dir = - System.tmp_dir!() - |> Path.join("ex_check_test") - |> Path.join("#{timestamp}-#{unique_id}") - - File.mkdir_p!(tmp_dir) - - tmp_dir - end - - def remove_tmp_directory(tmp_dir) do - File.rm_rf!(tmp_dir) - end - def create_mix_project(root_dir, opts \\ []) do name = Keyword.get(opts, :name, "test_project") umbrella = Keyword.get(opts, :umbrella, false) @@ -59,69 +36,4 @@ defmodule ExCheck.UmbrellaProjectCase do Path.join(root_dir, name) end - - def set_mix_deps(project_dirs, deps) when is_list(project_dirs) do - Enum.map(project_dirs, &set_mix_deps(&1, deps)) - end - - def set_mix_deps(project_dir, deps) do - config_path = "#{project_dir}/mix.exs" - deps_from = ~r/ *defp deps.*end\n/Us - - deps_list = - Enum.map(deps, fn - :ex_check -> - "{:ex_check, path: \"#{File.cwd!()}\", only: [:dev, :test], runtime: false}" - - dep -> - "{:#{dep}, \">= 0.0.0\", only: :dev, runtime: false}" - end) - - deps_to = """ - defp deps do - [ - #{Enum.join(deps_list, ",\n ")} - ] - end - """ - - new_config = - config_path - |> File.read!() - |> String.replace(deps_from, deps_to) - - unless String.contains?(new_config, "ex_check"), do: raise("unable to add ex_check dep") - - File.write!(config_path, new_config) - {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) - {_, 0} = System.cmd("mix", ~w[deps.get], cd: project_dir) - end - - def set_mix_app_mod(project_dir, mod) do - config_path = "#{project_dir}/mix.exs" - app_from = ~r/ *def application.*end\n/Us - - app_to = """ - def application do - [ - mod: {#{mod}, []} - ] - end - """ - - new_config = - config_path - |> File.read!() - |> String.replace(app_from, app_to) - - unless String.contains?(new_config, mod), do: raise("unable to set #{mod} app mod") - - File.write!(config_path, new_config) - {_, 0} = System.cmd("mix", ~w[format], cd: project_dir) - end - - def write_default_config(project_dir) do - config_path = Path.join(project_dir, ".check.exs") - File.write!(config_path, @default_config) - end end