From a5ef1947391d84d2604261755433533c67ab49e7 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 21 Jan 2023 13:15:40 +0100 Subject: [PATCH] Use ExUnit's tmp_dir when possible (#350) --- test/gettext/extractor_test.exs | 18 +-- test/gettext/merger_test.exs | 8 +- test/mix/tasks/gettext.extract_test.exs | 81 +++++------ test/mix/tasks/gettext.merge_test.exs | 185 ++++++++++++------------ 4 files changed, 145 insertions(+), 147 deletions(-) diff --git a/test/gettext/extractor_test.exs b/test/gettext/extractor_test.exs index 68583af2..60df837e 100644 --- a/test/gettext/extractor_test.exs +++ b/test/gettext/extractor_test.exs @@ -5,14 +5,13 @@ defmodule Gettext.ExtractorTest do alias Expo.Messages alias Gettext.Extractor - @pot_path "../../tmp/" |> Path.expand(__DIR__) |> Path.relative_to_cwd() - describe "merge_pot_files/2" do - test "merges two POT files" do + @tag :tmp_dir + test "merges two POT files", %{tmp_dir: tmp_dir} do paths = %{ - tomerge: Path.join(@pot_path, "tomerge.pot"), - ignored: Path.join(@pot_path, "ignored.pot"), - new: Path.join(@pot_path, "new.pot") + tomerge: Path.join(tmp_dir, "tomerge.pot"), + ignored: Path.join(tmp_dir, "ignored.pot"), + new: Path.join(tmp_dir, "new.pot") } extracted_po_structs = [ @@ -55,8 +54,9 @@ defmodule Gettext.ExtractorTest do """ end - test "reports the filename if syntax error" do - path = Path.join(@pot_path, "syntax_error.pot") + @tag :tmp_dir + test "reports the filename if syntax error", %{tmp_dir: tmp_dir} do + path = Path.join(tmp_dir, "syntax_error.pot") write_file(path, """ msgid "foo" @@ -65,7 +65,7 @@ defmodule Gettext.ExtractorTest do msgstr "" """) - message = "tmp/syntax_error.pot:3: syntax error before: msgid" + message = ~r/syntax_error\.pot:3: syntax error before: msgid/ assert_raise Expo.PO.SyntaxError, message, fn -> Extractor.merge_pot_files([{path, %Messages{messages: []}}], [path], []) diff --git a/test/gettext/merger_test.exs b/test/gettext/merger_test.exs index 54947f24..c67ab73d 100644 --- a/test/gettext/merger_test.exs +++ b/test/gettext/merger_test.exs @@ -7,7 +7,6 @@ defmodule Gettext.MergerTest do @opts fuzzy: true, fuzzy_threshold: 0.8 @autogenerated_flags [["elixir-format"]] - @pot_path "../../tmp/" |> Path.expand(__DIR__) |> Path.relative_to_cwd() describe "merge/2" do test "headers from the old file are kept" do @@ -535,9 +534,10 @@ defmodule Gettext.MergerTest do end end - test "new_po_file/2" do - pot_path = Path.join(@pot_path, "new_po_file.pot") - new_po_path = Path.join(@pot_path, "it/LC_MESSAGES/new_po_file.po") + @tag :tmp_dir + test "new_po_file/2", %{tmp_dir: tmp_dir} do + pot_path = Path.join(tmp_dir, "new_po_file.pot") + new_po_path = Path.join(tmp_dir, "it/LC_MESSAGES/new_po_file.po") write_file(pot_path, """ ## Stripme! diff --git a/test/mix/tasks/gettext.extract_test.exs b/test/mix/tasks/gettext.extract_test.exs index 5c6c3fef..a4eb5b8a 100644 --- a/test/mix/tasks/gettext.extract_test.exs +++ b/test/mix/tasks/gettext.extract_test.exs @@ -3,7 +3,7 @@ defmodule Mix.Tasks.Gettext.ExtractTest do import ExUnit.CaptureIO - @priv_path "../../../tmp/gettext.extract" |> Path.expand(__DIR__) |> Path.relative_to_cwd() + @moduletag :tmp_dir setup_all do # To suppress the `redefining module MyApp` warnings for the test modules @@ -11,16 +11,10 @@ defmodule Mix.Tasks.Gettext.ExtractTest do :ok end - setup do - File.rm_rf!(tmp_path("/")) + test "extracting and extracting with --merge", %{test: test, tmp_dir: tmp_dir} = context do + create_test_mix_file(context) - :ok - end - - test "extracting and extracting with --merge", %{test: test} do - create_test_mix_file(test) - - write_file("lib/my_app.ex", """ + write_file(context, "lib/my_app.ex", """ defmodule MyApp.Gettext do use Gettext, otp_app: #{inspect(test)} end @@ -33,12 +27,12 @@ defmodule Mix.Tasks.Gettext.ExtractTest do output = capture_io(fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> run([]) end) + Mix.Project.in_project(test, tmp_dir, fn _module -> run([]) end) end) assert output =~ "Extracted priv/gettext/default.pot" - assert read_file("priv/gettext/default.pot") =~ """ + assert read_file(context, "priv/gettext/default.pot") =~ """ #: lib/my_app.ex:7 #, elixir-autogen, elixir-format msgid "hello" @@ -47,20 +41,20 @@ defmodule Mix.Tasks.Gettext.ExtractTest do # Test --merge too. - write_file("lib/other.ex", """ + write_file(context, "lib/other.ex", """ defmodule MyApp.Other do require MyApp.Gettext def foo(), do: MyApp.Gettext.dgettext("my_domain", "other") end """) - write_file("priv/gettext/it/LC_MESSAGES/my_domain.po", "") + write_file(context, "priv/gettext/it/LC_MESSAGES/my_domain.po", "") capture_io(fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> run(["--merge"]) end) + Mix.Project.in_project(test, tmp_dir, fn _module -> run(["--merge"]) end) end) - assert read_file("priv/gettext/it/LC_MESSAGES/my_domain.po") == """ + assert read_file(context, "priv/gettext/it/LC_MESSAGES/my_domain.po") == """ #: lib/other.ex:3 #, elixir-autogen, elixir-format msgid "other" @@ -68,10 +62,11 @@ defmodule Mix.Tasks.Gettext.ExtractTest do """ end - test "--check-up-to-date should fail if no POT files have been created", %{test: test} do - create_test_mix_file(test) + test "--check-up-to-date should fail if no POT files have been created", + %{test: test, tmp_dir: tmp_dir} = context do + create_test_mix_file(context) - write_file("lib/my_app.ex", """ + write_file(context, "lib/my_app.ex", """ defmodule MyApp.Gettext do use Gettext, otp_app: #{inspect(test)} end @@ -82,7 +77,7 @@ defmodule Mix.Tasks.Gettext.ExtractTest do end """) - write_file("lib/other.ex", """ + write_file(context, "lib/other.ex", """ defmodule MyApp.Other do require MyApp.Gettext def foo(), do: MyApp.Gettext.dgettext("my_domain", "other") @@ -99,17 +94,18 @@ defmodule Mix.Tasks.Gettext.ExtractTest do capture_io(fn -> assert_raise Mix.Error, expected_message, fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> + Mix.Project.in_project(test, tmp_dir, fn _module -> run(["--check-up-to-date"]) end) end end) end - test "--check-up-to-date should pass if nothing changed", %{test: test} do - create_test_mix_file(test, write_reference_comments: false) + test "--check-up-to-date should pass if nothing changed", + %{test: test, tmp_dir: tmp_dir} = context do + create_test_mix_file(context, write_reference_comments: false) - write_file("lib/my_app.ex", """ + write_file(context, "lib/my_app.ex", """ defmodule MyApp.Gettext do use Gettext, otp_app: #{inspect(test)} end @@ -121,20 +117,21 @@ defmodule Mix.Tasks.Gettext.ExtractTest do """) capture_io(fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> + Mix.Project.in_project(test, tmp_dir, fn _module -> run([]) end) - Mix.Project.in_project(test, tmp_path("/"), fn _module -> + Mix.Project.in_project(test, tmp_dir, fn _module -> run(["--check-up-to-date"]) end) end) end - test "--check-up-to-date should fail if POT files are outdated", %{test: test} do - create_test_mix_file(test) + test "--check-up-to-date should fail if POT files are outdated", + %{test: test, tmp_dir: tmp_dir} = context do + create_test_mix_file(context) - write_file("lib/my_app.ex", """ + write_file(context, "lib/my_app.ex", """ defmodule MyApp.Gettext do use Gettext, otp_app: #{inspect(test)} end @@ -145,7 +142,7 @@ defmodule Mix.Tasks.Gettext.ExtractTest do end """) - write_file("lib/other.ex", """ + write_file(context, "lib/other.ex", """ defmodule MyApp.Other do require MyApp.Gettext def foo(), do: MyApp.Gettext.dgettext("my_domain", "other") @@ -153,10 +150,10 @@ defmodule Mix.Tasks.Gettext.ExtractTest do """) capture_io(fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> run([]) end) + Mix.Project.in_project(test, tmp_dir, fn _module -> run([]) end) end) - write_file("lib/my_app.ex", """ + write_file(context, "lib/my_app.ex", """ defmodule MyApp.Gettext do use Gettext, otp_app: #{inspect(test)} end @@ -176,20 +173,20 @@ defmodule Mix.Tasks.Gettext.ExtractTest do capture_io(fn -> assert_raise Mix.Error, expected_message, fn -> - Mix.Project.in_project(test, tmp_path("/"), fn _module -> + Mix.Project.in_project(test, tmp_dir, fn _module -> run(["--check-up-to-date"]) end) end end) end - defp create_test_mix_file(test, gettext_config \\ []) do - write_file("mix.exs", """ + defp create_test_mix_file(context, gettext_config \\ []) do + write_file(context, "mix.exs", """ defmodule MyApp.MixProject do use Mix.Project def project() do - [app: #{inspect(test)}, version: "0.1.0", gettext: #{inspect(gettext_config)}] + [app: #{inspect(context.test)}, version: "0.1.0", gettext: #{inspect(gettext_config)}] end def application() do @@ -199,18 +196,14 @@ defmodule Mix.Tasks.Gettext.ExtractTest do """) end - defp write_file(path, contents) do - path = tmp_path(path) + defp write_file(context, path, contents) do + path = Path.join(context.tmp_dir, path) File.mkdir_p!(Path.dirname(path)) File.write!(path, contents) end - defp read_file(path) do - path |> tmp_path() |> File.read!() - end - - defp tmp_path(path) do - Path.join(@priv_path, path) + defp read_file(context, path) do + context.tmp_dir |> Path.join(path) |> File.read!() end defp run(args) do diff --git a/test/mix/tasks/gettext.merge_test.exs b/test/mix/tasks/gettext.merge_test.exs index 4ab10c92..3ab17a55 100644 --- a/test/mix/tasks/gettext.merge_test.exs +++ b/test/mix/tasks/gettext.merge_test.exs @@ -3,13 +3,6 @@ defmodule Mix.Tasks.Gettext.MergeTest do import ExUnit.CaptureIO - @priv_path "../../../tmp/gettext.merge" |> Path.expand(__DIR__) |> Path.relative_to_cwd() - - setup do - File.rm_rf!(@priv_path) - :ok - end - test "raises an error when if one of the files doesn't exist" do assert_raise Mix.Error, "No such file: foo.po", fn -> run(~w(foo.po bar.pot)) @@ -34,47 +27,50 @@ defmodule Mix.Tasks.Gettext.MergeTest do end end - test "passing a :fuzzy_threshold outside of 0..1 raises an error" do - File.mkdir_p!(@priv_path) + @tag :tmp_dir + test "passing a :fuzzy_threshold outside of 0..1 raises an error", %{tmp_dir: tmp_dir} do + File.mkdir_p(tmp_dir) assert_raise Mix.Error, "The :fuzzy_threshold option must be a float >= 0.0 and <= 1.0", fn -> - run([@priv_path, "--fuzzy-threshold", "5.0"]) + run([tmp_dir, "--fuzzy-threshold", "5.0"]) end end - test "merging an existing PO file with a new POT file" do + @tag :tmp_dir + test "merging an existing PO file with a new POT file", %{tmp_dir: tmp_dir} do pot_contents = """ msgid "hello" msgstr "" """ - write_file("foo.pot", pot_contents) + write_file(Path.join(tmp_dir, "foo.pot"), pot_contents) - write_file("it/LC_MESSAGES/foo.po", "") + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), "") output = capture_io(fn -> - run([tmp_path("it/LC_MESSAGES/foo.po"), tmp_path("foo.pot")]) + run([Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), Path.join(tmp_dir, "foo.pot")]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/foo.po" + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/foo\.po} assert output =~ "(1 new message, 0 removed, 0 unchanged, 0 reworded (fuzzy), 0 marked as obsolete)" # The POT file is left unchanged - assert read_file("foo.pot") == pot_contents + assert File.read!(Path.join(tmp_dir, "foo.pot")) == pot_contents - assert read_file("it/LC_MESSAGES/foo.po") == """ + assert File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po")) == """ msgid "hello" msgstr "" """ end - test "marks messages as obsolete" do - write_file("foo.pot", "") + @tag :tmp_dir + test "marks messages as obsolete", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "foo.pot"), "") - write_file("it/LC_MESSAGES/foo.po", """ + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), """ msgid "foo" msgstr "" """) @@ -82,41 +78,48 @@ defmodule Mix.Tasks.Gettext.MergeTest do output = capture_io(fn -> run([ - tmp_path("it/LC_MESSAGES/foo.po"), - tmp_path("foo.pot"), + Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), + Path.join(tmp_dir, "foo.pot"), "--on-obsolete", "mark_as_obsolete" ]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/foo.po" + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/foo.po} assert output =~ "(0 new messages, 0 removed, 0 unchanged, 0 reworded (fuzzy), 1 marked as obsolete)" end - test "removes obsolete messages" do - write_file("foo.pot", "") + @tag :tmp_dir + test "removes obsolete messages", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "foo.pot"), "") - write_file("it/LC_MESSAGES/foo.po", """ + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), """ msgid "foo" msgstr "" """) output = capture_io(fn -> - run([tmp_path("it/LC_MESSAGES/foo.po"), tmp_path("foo.pot"), "--on-obsolete", "delete"]) + run([ + Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), + Path.join(tmp_dir, "foo.pot"), + "--on-obsolete", + "delete" + ]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/foo.po" + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/foo.po} assert output =~ "(0 new messages, 1 removed, 0 unchanged, 0 reworded (fuzzy), 0 marked as obsolete)" end - test "validates on-obsolete" do - write_file("foo.pot", "") - write_file("it/LC_MESSAGES/foo.po", "") + @tag :tmp_dir + test "validates on-obsolete", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "foo.pot"), "") + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), "") expected_message = """ An invalid value was provided for the option `on_obsolete`. @@ -125,37 +128,44 @@ defmodule Mix.Tasks.Gettext.MergeTest do """ assert_raise Mix.Error, expected_message, fn -> - run([tmp_path("it/LC_MESSAGES/foo.po"), tmp_path("foo.pot"), "--on-obsolete", "invalid"]) + run([ + Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), + Path.join(tmp_dir, "foo.pot"), + "--on-obsolete", + "invalid" + ]) end end - test "passing a dir and a --locale opt will update/create PO files in the locale dir" do - write_file("default.pot", """ + @tag :tmp_dir + test "passing a dir and a --locale opt will update/create PO files in the locale dir", + %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "default.pot"), """ msgid "def" msgstr "" """) - write_file("new.pot", """ + write_file(Path.join(tmp_dir, "new.pot"), """ msgid "new" msgstr "" """) - write_file("it/LC_MESSAGES/default.po", "") + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/default.po"), "") output = capture_io(fn -> - run([@priv_path, "--locale", "it"]) + run([tmp_dir, "--locale", "it"]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/new.po" - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/default.po" + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/new.po} + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/default.po} - assert read_file("it/LC_MESSAGES/default.po") == """ + assert File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/default.po")) == """ msgid "def" msgstr "" """ - new_po = read_file("it/LC_MESSAGES/new.po") + new_po = File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/new.po")) assert new_po =~ ~S""" msgid "" @@ -170,25 +180,27 @@ defmodule Mix.Tasks.Gettext.MergeTest do assert String.starts_with?(new_po, "## \"msgid\"s in this file come from POT") end - test "enabling --store-previous-message-on-fuzzy-match stores previous message" do - write_file("default.pot", """ + @tag :tmp_dir + test "enabling --store-previous-message-on-fuzzy-match stores previous message", + %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "default.pot"), """ msgid "Hello Worlds" msgstr "" """) - write_file("it/LC_MESSAGES/default.po", """ + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/default.po"), """ msgid "Hello World" msgstr "" """) output = capture_io(fn -> - run([@priv_path, "--locale", "it", "--store-previous-message-on-fuzzy-match"]) + run([tmp_dir, "--locale", "it", "--store-previous-message-on-fuzzy-match"]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/default.po" + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/default.po} - assert read_file("it/LC_MESSAGES/default.po") == """ + assert File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/default.po")) == """ #, fuzzy #| msgid "Hello World" msgid "Hello Worlds" @@ -196,21 +208,22 @@ defmodule Mix.Tasks.Gettext.MergeTest do """ end - test "passing a dir and a --locale opt will update/create PO files in the locale dir with custom plural forms" do - write_file("new.pot", """ + @tag :tmp_dir + test "passing a dir and a --locale opt will update/create PO files in the locale dir with custom plural forms", + %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "new.pot"), """ msgid "new" msgstr "" """) output = capture_io(fn -> - run([@priv_path, "--locale", "it", "--plural-forms-header", "nplurals=3"]) + run([tmp_dir, "--locale", "it", "--plural-forms-header", "nplurals=3"]) end) - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/new.po" - new_po = read_file("it/LC_MESSAGES/new.po") + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/new.po} - assert new_po =~ ~S""" + assert File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/new.po")) =~ ~S""" msgid "" msgstr "" "Language: it\n" @@ -221,23 +234,24 @@ defmodule Mix.Tasks.Gettext.MergeTest do """ end - test "passing a dir and a --locale opt will update/create PO files in the locale dir with app env plural forms" do + @tag :tmp_dir + test "passing a dir and a --locale opt will update/create PO files in the locale dir with app env plural forms", + %{tmp_dir: tmp_dir} do Application.put_env(:gettext, :plural_forms, GettextTest.CustomPlural) - write_file("new.pot", """ + write_file(Path.join(tmp_dir, "new.pot"), """ msgid "new" msgstr "" """) output = capture_io(fn -> - run([@priv_path, "--locale", "elv"]) + run([tmp_dir, "--locale", "elv"]) end) - assert output =~ "Wrote tmp/gettext.merge/elv/LC_MESSAGES/new.po" - new_po = read_file("elv/LC_MESSAGES/new.po") + assert output =~ ~r{Wrote .*/elv/LC_MESSAGES/new.po} - assert new_po =~ ~S""" + assert File.read!(Path.join(tmp_dir, "elv/LC_MESSAGES/new.po")) =~ ~S""" msgid "" msgstr "" "Language: elv\n" @@ -250,80 +264,71 @@ defmodule Mix.Tasks.Gettext.MergeTest do Application.put_env(:gettext, :plural_forms, Gettext.Plural) end - test "passing just a dir merges with PO files in every locale" do - write_file("fr/LC_MESSAGES/foo.po", "") - write_file("it/LC_MESSAGES/foo.po", "") + @tag :tmp_dir + test "passing just a dir merges with PO files in every locale", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "fr/LC_MESSAGES/foo.po"), "") + write_file(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po"), "") contents = """ msgid "foo" msgstr "" """ - write_file("foo.pot", contents) + write_file(Path.join(tmp_dir, "foo.pot"), contents) - output = - capture_io(fn -> - run([@priv_path]) - end) + output = capture_io(fn -> run([tmp_dir]) end) - assert output =~ "Wrote tmp/gettext.merge/fr/LC_MESSAGES/foo.po" - assert output =~ "Wrote tmp/gettext.merge/it/LC_MESSAGES/foo.po" + assert output =~ ~r{Wrote .*/fr/LC_MESSAGES/foo.po} + assert output =~ ~r{Wrote .*/it/LC_MESSAGES/foo.po} - assert read_file("fr/LC_MESSAGES/foo.po") == contents - assert read_file("it/LC_MESSAGES/foo.po") == contents + assert File.read!(Path.join(tmp_dir, "fr/LC_MESSAGES/foo.po")) == contents + assert File.read!(Path.join(tmp_dir, "it/LC_MESSAGES/foo.po")) == contents end - test "non existing locale/LC_MESSAGES directories are created" do - write_file("foo.pot", """ + @tag :tmp_dir + test "non-existing locale/LC_MESSAGES directories are created", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "foo.pot"), """ msgid "foo" msgstr "" """) - created_dir = Path.join([@priv_path, "en", "LC_MESSAGES"]) + created_dir = Path.join([tmp_dir, "en", "LC_MESSAGES"]) refute File.dir?(created_dir) output = capture_io(fn -> - run([@priv_path, "--locale", "en"]) + run([tmp_dir, "--locale", "en"]) end) assert File.dir?(created_dir) assert output =~ "Created directory #{created_dir}" end - test "informative comments at the top of the file" do - write_file("inf.pot", """ + @tag :tmp_dir + test "informative comments at the top of the file", %{tmp_dir: tmp_dir} do + write_file(Path.join(tmp_dir, "inf.pot"), """ msgid "foo" msgstr "" """) capture_io(fn -> - run([@priv_path, "--locale", "en"]) - contents = read_file("en/LC_MESSAGES/inf.po") + run([tmp_dir, "--locale", "en"]) + contents = File.read!(Path.join(tmp_dir, "en/LC_MESSAGES/inf.po")) assert contents =~ "## \"msgid\"s in this file" # Running the task again without having change the PO file shouldn't # remove the informative comment. - run([@priv_path, "--locale", "en"]) - assert contents == read_file("en/LC_MESSAGES/inf.po") + run([tmp_dir, "--locale", "en"]) + assert contents == File.read!(Path.join(tmp_dir, "en/LC_MESSAGES/inf.po")) end) end defp write_file(path, contents) do - path = tmp_path(path) File.mkdir_p!(Path.dirname(path)) File.write!(path, contents) end - defp read_file(path) do - path |> tmp_path() |> File.read!() - end - - defp tmp_path(path) do - Path.join(@priv_path, path) - end - defp run(args) do Mix.Tasks.Gettext.Merge.run(args) end